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

Segger and J-link debugging with RTT is not working properly

Starting with the BLE Uart Service example code, I wanted to send longer length packets, so the necessitated modifying settings like NRF_SDH_BLE_GATT_MAX_MTU_SIZE, NRF_SDH_BLE_GAP_DATA_LENGTH, NRF_SDH_BLE_GAP_DATA_LENGTH, etc, which then modifies the memory requirements of the BLE stack. The need to modify the ram settings is is fine, and is the expected behaviour.

So, running the code in the segger debugger, with it configured with logging enabled at NRF_SDH_BLE_LOG_LEVEL 4, for RTT debug output to the debug window I would have expected it to provide helpful debug output  (as per the tutorial video at https://www.youtube.com/watch?v=uP8RYgYGRvI ) to tell me what the new RAM settings shoud be.

However when the code executes the following line of code, the NRF_LOG_WARNING code goes mad.

Just the very bottom line of the segger Debug Terminal window flickers furiously with the words "Insufficient RAM allocated for the Soft Device". There is no scrolling of the window, and no other messages. If I pause it, the debug terminal is blank as it is constantly being cleared by something.

By attaching the external J-Link viewer, I can see the following stream of output:

etc.

i.e. it is just repeatedly printing the same warning message, without moving on to subsequent lines of code, and therefore it never gets to print out the helpful messages that tell me what I should set the ram start and ram size values to.

There are work-arounds I can use to find those ram values, but the main issue here is that debug logging isn't working properly.

Parents Reply Children
  • Hi,

    NRF_LOG_DEFERRED was already set to 0 (in sdh_config.h)

    Sorry, I can't post commercial project code to a public forum.

    However, as shown in the below screen-grab, the place where it goes crazy is line 558 of nrf_log_frontend.c, where it calls NRF_LOG_FLUSH(), and this causes the same debug statement to be printed an infinite number of times to the debug window.


  • Ok, I have found the cause of the problem!

    The function log_init() was getting called twice during startup.

    i.e. this function...

    // Function for initializing the log.
    static void log_init(void)
    {
        ret_code_t err_code = NRF_LOG_INIT(NULL);
        APP_ERROR_CHECK(err_code);
    
        NRF_LOG_DEFAULT_BACKENDS_INIT();
    }
    

    For some reason, when this initialisation function get called more than once, it causes the observed erroneous behaviour that any subsequently generated debug message will be repeatedly printed forever, effectivey hanging the program.

    Whilst it was my fault for accidentally calling log_init() in two different places, I'm still going to classify this as a bug in the Nordic libraries, as the log initialisation code should internally check whether it has already been initialised, and not just silently break and do weird things.

  • Whilst it was my fault for accidentally calling log_init() in two different places, I'm still going to classify this as a bug in the Nordic libraries, as the log initialisation code should internally check whether it has already been initialised, and not just silently break and do weird things.

    I agree. I will internally create a bug-report on this for the nrf_log developers. Thank you for reporting this.

Related