nRF51 SDK - S210 SoftDevice
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Debug Logger

The logger module provides simple log messages over UART for debugging purposes. In case debug messages are to be enabled, ENABLE_DEBUG_LOG_SUPPORT should be defined in the project. Logging can be easily disabled by removing the define ENABLE_DEBUG_LOG_SUPPORT from the project.

Initialization

The module must be initialized before logging can be be done using the module API app_trace_init. Initialization routine takes care of initializing and configuring UART. UART configuration used by logger module in SDK uses a baud rate of 38400 bps, with no flow control or parity.

uint32_t retval;
// Initialize module
retval = app_trace_init();
if(retval == NRF_SUCCESS)
{
// Module successfully initialized.
}
else
{
// Module initialization failed. Take corrective action.
}

Debug Logging

The application should use app_trace_log API to print trace messages over UART. Please note that the string being printed should end with \r\n for neat formatting on the terminal.

.
.
.
uint32_t retval;
retval = some_api();
if(retval != NRF_SUCCESS)
{
app_trace_log("Some API failed, reason %X\r\n", retval);
}
.
.
.

Usage by SDK modules and recommendations

The logger module is used by the Connection Manager and application in SDK examples. It should be noted that these modules do not use the logger module directly through out the code. But a macro is used to enable logging. For example, connection manager defines a macro called the CONN_MNGR_LOG which is defined to app_trace_log. The advantage of this is to be able enable or disable selectively log messages from a certain module in case too many modules are logging messages and debugging gets convoluted.

Further, practice of including a module signature is added in order to map each message with a particular module. For example, all messages from connection manager start with "[CM]:" followed by the message.

Note
For Keil, enabling use of microlib is needed to enable logging as currently, app_trace_log is mapped to printf.