This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

app_trace_init not returning useful value if debugging disabled

Hi everyone,

I am using the nRF51 SDK 10.0. The documentation for the Debug Logger API suggests sample code like:

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

However, if you do this without the macro ENABLE_DEBUG_LOG_SUPPORT set, GCC 4.9 will correctly say

error: expected primary-expression before ';' token

I therefore suggest the following change to app_trace.h:

#else // ENABLE_DEBUG_LOG_SUPPORT

-#define app_trace_init(...)
+#define app_trace_init(...) NRF_ERROR_NOT_SUPPORTED
#define app_trace_log(...)
#define app_trace_dump(...)

EDIT: I just realized that there is an even bigger confusion with app_trace_init. It does not return a value at all! So it should actually be fixed so that it returns a value and then in the way above if debugging is disabled.

  • Hi, the documentation doesn't seem to correspond to actual implementation in the SDK. In the SDK (ble_app_hrs) app_trace is defined as app_trace_init(...) when ENABLE_DEBUG_LOG_SUPPORT is not defined, hence doing nothing. Also, it doesn't return any error code in case of assert. Will report this internally.

    Normally app_trace_init() shouldn't fail unless it has been modified in some way which is why it's a void function. However, if it does fail I think it's better to catch the error by passing it to the APP_ERROR_CHECK() macro :

    void app_trace_init(void)
    {
        uint32_t err_code = NRF_SUCCESS;
        const app_uart_comm_params_t comm_params =  
        {
            RX_PIN_NUMBER, 
            TX_PIN_NUMBER, 
            RTS_PIN_NUMBER, 
            CTS_PIN_NUMBER, 
            APP_UART_FLOW_CONTROL_DISABLED, 
            false, 
            UART_BAUDRATE_BAUDRATE_Baud38400
        }; 
            
        APP_UART_FIFO_INIT(&comm_params, 
                           UART_RX_BUF_SIZE, 
                           UART_TX_BUF_SIZE, 
                           uart_error_handle, 
                           APP_IRQ_PRIORITY_LOW,
                           err_code);
       //UNUSED_VARIABLE(err_code);
       APP_ERROR_CHECK(err_code);
    }
    

    Then in case of assert, the app_error.c->app_error_handler() will be called with the error code passed as an argument. The list of error codes are found in nrf_error.h, and can be used to determine the reason for the assert.

Related