From 83b5c969d2d24f02513495965930ee464b955f10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20J=C3=B8lsgard?= Date: Thu, 6 Jul 2023 13:02:13 +0200 Subject: [PATCH 1/3] snippets: nrf91-modem-trace-uart: add UART1 specific Kconfigs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Enable ASYNC UART for the UART1 instance. Signed-off-by: Eivind Jølsgard --- snippets/nrf91-modem-trace-uart/overlay-modem-trace-uart.conf | 2 ++ 1 file changed, 2 insertions(+) diff --git a/snippets/nrf91-modem-trace-uart/overlay-modem-trace-uart.conf b/snippets/nrf91-modem-trace-uart/overlay-modem-trace-uart.conf index c3ad518a50d5..e583bac718b5 100644 --- a/snippets/nrf91-modem-trace-uart/overlay-modem-trace-uart.conf +++ b/snippets/nrf91-modem-trace-uart/overlay-modem-trace-uart.conf @@ -13,3 +13,5 @@ CONFIG_NRF_MODEM_LIB_TRACE_BACKEND_UART_ZEPHYR=y # UART configuration CONFIG_SERIAL=y CONFIG_UART_ASYNC_API=y +CONFIG_UART_1_ASYNC=y +CONFIG_UART_1_INTERRUPT_DRIVEN=n From f13a8454f7b918ae9796187c68b0d7550f5f5c79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20J=C3=B8lsgard?= Date: Thu, 6 Jul 2023 13:05:31 +0200 Subject: [PATCH 2/3] lib: nrf_modem: trace: allow trace backend to return EAGAIN on retry MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allow the trace backend to return -EAGAIN if the operation should be retried. This is advantageous compared to the backend waiting forever as we need to shut down the tracing if the modem is shut down. Signed-off-by: Eivind Jølsgard --- .../releases/release-notes-changelog.rst | 7 +++++-- include/modem/trace_backend.h | 2 ++ lib/nrf_modem_lib/nrf_modem_lib_trace.c | 15 +++++++++++++++ lib/nrf_modem_lib/trace_backends/uart/uart.c | 5 +++++ 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst b/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst index e2a25ffd0c17..b6f2cdbb02aa 100644 --- a/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst +++ b/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst @@ -404,8 +404,11 @@ Modem libraries * :ref:`nrf_modem_lib_readme`: - * Fixed a rare bug that caused a deadlock between two threads when one thread sent data while the other received a lot of data quickly. - * Updated the :c:func:`nrf_modem_lib_shutdown` function to allow the modem to be in flight mode (``CFUN=4``) when shutting down the modem. + Updated: + + * The :c:func:`nrf_modem_lib_shutdown` function to allow the modem to be in flight mode (``CFUN=4``) when shutting down the modem. + * The trace backends can now return ``-EAGAIN`` if the write operation can be retried. + * Fixed a rare bug that caused a deadlock between two threads when one thread sent data while the other received a lot of data quickly. * :ref:`lib_location` library: diff --git a/include/modem/trace_backend.h b/include/modem/trace_backend.h index 418ba32c1232..38eb0d6592aa 100644 --- a/include/modem/trace_backend.h +++ b/include/modem/trace_backend.h @@ -58,6 +58,8 @@ struct nrf_modem_lib_trace_backend { * -ENOSPC if no space is available and the backend has to be cleared before * tracing can continue. For some trace backends, space is also cleared * when performing the read operation. + * -EAGAIN if no data were written due to e.g. flow control and the operation + * should be retried. */ int (*write)(const void *data, size_t len); diff --git a/lib/nrf_modem_lib/nrf_modem_lib_trace.c b/lib/nrf_modem_lib/nrf_modem_lib_trace.c index 6973597dd412..77a0b31b4fa5 100644 --- a/lib/nrf_modem_lib/nrf_modem_lib_trace.c +++ b/lib/nrf_modem_lib/nrf_modem_lib_trace.c @@ -204,6 +204,21 @@ static int trace_fragment_write(struct nrf_modem_trace_data *frag) __ASSERT(ret != 0, "Trace backend wrote 0 bytes"); + /* We handle this here and not in the trace_thread_handler as we might not write the + * entire trace fragment in the same write operation. If we get EAGAIN on the + * second, third, ..., we would repeat sending the first section of the trace + * fragment. + */ + if (ret == -EAGAIN) { + /* We don't allow retrying if the modem is shut down as that can block + * a new modem init. + */ + if (!nrf_modem_is_initialized()) { + return -ESHUTDOWN; + } + continue; + } + if (ret < 0) { LOG_ERR("trace_backend.write failed with err: %d", ret); return ret; diff --git a/lib/nrf_modem_lib/trace_backends/uart/uart.c b/lib/nrf_modem_lib/trace_backends/uart/uart.c index 7f7889defcb2..c87ebf78dfe0 100644 --- a/lib/nrf_modem_lib/trace_backends/uart/uart.c +++ b/lib/nrf_modem_lib/trace_backends/uart/uart.c @@ -158,6 +158,11 @@ int trace_backend_write(const void *data, size_t len) ret = len - remaining_bytes; out: k_sem_give(&tx_sem); + + if (ret == 0) { + return -EAGAIN; + } + return ret; } From ee2c781cd9f8d4560c9ffa9658d3f3b3e655e76a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20J=C3=B8lsgard?= Date: Thu, 6 Jul 2023 13:22:06 +0200 Subject: [PATCH 3/3] lib: nrf_modem: trace: cancel work items on deinit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cancel work items on deinit. Signed-off-by: Eivind Jølsgard --- .../releases/release-notes-changelog.rst | 7 ++++--- lib/nrf_modem_lib/nrf_modem_lib_trace.c | 13 +++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst b/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst index b6f2cdbb02aa..0d0df7524911 100644 --- a/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst +++ b/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst @@ -404,7 +404,9 @@ Modem libraries * :ref:`nrf_modem_lib_readme`: - Updated: + * Added CEREG event tracking to ``lte_connectivity``. + + * Updated: * The :c:func:`nrf_modem_lib_shutdown` function to allow the modem to be in flight mode (``CFUN=4``) when shutting down the modem. * The trace backends can now return ``-EAGAIN`` if the write operation can be retried. @@ -418,10 +420,9 @@ Modem libraries * Updated the library to allow a ``PDP_type``-only configuration in the :c:func:`pdn_ctx_configure` function. -* :ref:`nrf_modem_lib_readme`: +* :ref:`modem_key_mgmt`: * Updated the :c:func:`modem_key_mgmt_cmp` function to return ``1`` if the buffer length does not match the certificate length. - * Added CEREG event tracking to ``lte_connectivity``. Libraries for networking ------------------------ diff --git a/lib/nrf_modem_lib/nrf_modem_lib_trace.c b/lib/nrf_modem_lib/nrf_modem_lib_trace.c index 77a0b31b4fa5..ed5a1f81ba5c 100644 --- a/lib/nrf_modem_lib/nrf_modem_lib_trace.c +++ b/lib/nrf_modem_lib/nrf_modem_lib_trace.c @@ -362,6 +362,19 @@ static int trace_deinit(void) return err; } + +#if CONFIG_NRF_MODEM_LIB_TRACE_BACKEND_BITRATE + k_work_cancel(&backend_bps_avg_update_work); +#endif + +#if CONFIG_NRF_MODEM_LIB_TRACE_BACKEND_BITRATE_LOG + k_work_cancel(&backend_bps_log_work); +#endif + +#if CONFIG_NRF_MODEM_LIB_TRACE_BITRATE_LOG + k_work_cancel(&bps_log_work); +#endif + k_sem_give(&trace_done_sem); return 0;