The modem trace interface in the Modem library is used to retrieve trace data from the modem core.
Enabling modem traces
To enable traces the application must initialize the Modem library with a non-zero trace region size.
The trace output from the modem can be toggled at runtime using the AT command
%XMODEMTRACE, which can also be used to change the trace output level.
See the AT command documentation %XMODEMTRACE AT command documentation for further information.
Fetching modem traces
Modem traces are retrieved by the application and output to a trace medium, typically UART.
You can call the
nrf_modem_trace_get() function to retrieve traces from the Modem library.
The trace data, containing multiple fragments, must be processed in order, starting from the first array index.
Once the trace data is processed, the application must call the
nrf_modem_trace_processed() function to release the memory allocated in the trace memory area.
If the trace data is processed in fragments, this can be split into multiple calls, for example, one call for each fragment of processed data.
If no trace data is available, the
nrf_modem_trace_get() function blocks until new data becomes available or the modem is shut down or faulted.
This require the traces to be processed in its own thread separate from the rest of the application.
Processing modem traces
The application must call the
nrf_modem_trace_processed() function as it processes the trace data to inform the Modem library that the trace data has been handled and can be released.
It is not necessary that the application has processed a whole trace fragment before calling the
To maximize the availability of the shared memory in the trace region, the application must call the
nrf_modem_trace_processed() function frequently as soon as some bytes are processed.
nrf_modem_trace_processed() function must be called with the total number of bytes in the trace fragments before making a new call to the
An example is shown in the following figure:
Tracing and modem faults
When a fault occurs in the modem and traces are enabled, the modem will send a coredump using the trace interface.
nrf_modem_trace_get() function returns trace fragments until there are no more fragments to process.
In the case where there are no more trace fragments after a modem coredump is complete, the
nrf_modem_trace_get() function returns
-NRF_ENODATA as shown in the following figure: