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

NRF_LOG not working on Segger Embedded Studio

Greetings,

I'm having some trouble displaying logs to the SES Debug Terminal... Basically, I can see the logs with RTTviewer but not in SES Debug Terminal. However printf works just fine on the SES Debug Terminal

My setup:

OS: Windows 10

Board: NRF52-DK

SDK: 15.3.0

Example: peripheral\bsp

IDE: Segger Embedded Studio 4.16

After reading lots of posts and documentation that's what I've done so far:

1) tried many other examples and got the same problem

2) NO, I'm not using RTTviewer and SES Debug Terminal at the same time

3) On SDK_Config.h made sure that settings are:

NRF_LOG_BACKEND_RTT_ENABLE 1
NRF_LOG_BACKEND_RTT_ENABLE 0
NRF_LOG_ENABLE 1
NRF_LOG_DEFFERED 1
NRF_LOG_DEFAULT_LEVEL 3 //AKA Info

4) Tried to build clean, build Debug, build Release

5)  On main:

Initializing NRF_LOG:

APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
NRF_LOG_DEFAULT_BACKENDS_INIT();

On main loop:

NRF_LOG_INFO("BSP example started.");
NRF_LOG_FLUSH();

6) If instead of NRF_LOG_INFO I use printf the SES Debug Terminal prints my message just fine

7) If I open the SES J-Link Control Panel Window while debugging, I can see the message on the RTT tab, but still not in Debug Terminal:

8) Verified Project Debug Settings:

9) Tried changing NRF_LOG_FLUSH() to NRF_LOG_PROCESS() . No difference...

10) I also notice that something is been send to the Debug Terminal because the cursor moves to a new line every time a new NRF_LOG should be displayed.

Any ideas of what I am doing wrong?

  • Following some beginner trial and error, I discovered that the solution (i.e. setting NRF_FPRINTF_FLAG_AUTOMATIC_CR_ON_LF_ENABLED to 0) does in fact work, but I needed to always manually connect the j-link target before going into a debug session... I think that was suggested by someone else on this post too.

    EDIT. As a novice, I also noticed that there is some "buffering" or equivalent going on as the output is not always immediate. As in, if stepping into or out of code manually in debugging mode it does not always produce an immediate output response (both on UART and Debug). So, it looks as if something is not working but when in run mode you do see the output.

  • Hi !

    Usually my Debugger works but when I execute a function which returns a error message, i cannot see messages from NRF_LOG anymore. 

    uint32_t ble_cos_char_add(uint16_t                        service_handle,
                               ble_uuid_t                      uuid,
                               ble_cos_init_params             char_params,
                               ble_gatts_char_handles_t      * p_handles)
    {
        // uuid type starts at 0x02, this is the index of the first base UUID we add. 0x03 will be the index of the second base UUID we add and etc
        // About exponent : actual value = Characteristic Value * 10^Exponent
        // About CPF description : WIKA number
        // About Namespace : SIG number or not
        if((uuid.type <= BLE_UUID_TYPE_UNKNOWN) || (uuid.type > (1 + NRF_SDH_BLE_VS_UUID_COUNT))
        || (char_params.read_access > SEC_SIGNED_MITM) || (char_params.read_access < SEC_NO_ACCESS) 
        || (char_params.write_access > SEC_SIGNED_MITM) || (char_params.write_access < SEC_NO_ACCESS) 
        || (char_params.cpf.format > BLE_GATT_CPF_FORMAT_STRUCT) || (char_params.cpf.format < BLE_GATT_CPF_FORMAT_BOOLEAN)
        || (char_params.cpf.name_space < BLE_GATT_CPF_NAMESPACE_DESCRIPTION_UNKNOWN) || (char_params.cpf.name_space > BLE_GATT_CPF_NAMESPACE_BTSIG) 
        /*|| (char_params.cpf.desc != WIKA_NUMBER)*/
        /*|| (char_params.cpf.unit < BLE_GATT_UNIT_UNITLESS)|| (char_params.cpf.unit > BLE_GATT_UNIT_CONCENTRATION_PARTS_PER_BILLION)*/)
        {
            NRF_LOG_INFO("Info: Unable to add characteristic to COS Service, invalid parameter");
            NRF_LOG_ERROR("Error: Unable to add characteristic to COS Service, invalid parameter");
            NRF_LOG_DEBUG("Debug: Unable to add characteristic to COS Service, invalid parameter");
    
            return NRF_ERROR_INVALID_PARAM;
        }
    
        if((char_params.len == 0) || (p_handles == NULL))
        {
            NRF_LOG_INFO("Info: Unable to add characteristic to COS Service, NULL parameter");
            NRF_LOG_ERROR("Error: Unable to add characteristic to COS Service, NULL parameter");
            NRF_LOG_DEBUG("Debug: Unable to add characteristic to COS Service, NULL parameter");
            return NRF_ERROR_NULL;
        }
    
        ble_add_char_params_t add_char_params;
    
        //APP_ERROR_CHECK_BOOL(char_params.p_value != NULL);
        //APP_ERROR_CHECK_BOOL(char_params.len > 0);
    
        memset(&add_char_params, 0, sizeof(add_char_params));
    
        add_char_params.uuid_type       = uuid.type;
        add_char_params.uuid            = uuid.uuid;
        add_char_params.max_len         = char_params.len;
        add_char_params.init_len        = char_params.len;
    
        if(char_params.p_value != NULL) add_char_params.p_init_value = char_params.p_value;
        else add_char_params.p_init_value = NULL;
    
        add_char_params.char_props.read = (char_params.read_access == 0) ? 0 : 1;
        add_char_params.read_access     = char_params.read_access;
        add_char_params.char_props.write = (char_params.write_access == 0) ? 0 : 1;
        add_char_params.write_access     = char_params.write_access;
        //add_char_params.p_presentation_format = &char_params.cpf;
    
        return characteristic_add(service_handle, &add_char_params, p_handles);
    }

    For example I have this function, and for now due to my parameters it returns NRF_ERROR_INVALID_PARAM. Thuis error code is given to the APP_ERROR_CHECK() MACRO. So when I have a function like that, I would like to see fastly where is the mistake, that's why I have put some nrf_log. 

    Do you have any ideas why it doesn't work ?

  • nRF5 SDK v17.0.2 is still getting this wrong in examples:

    https://devzone.nordicsemi.com/f/nordic-q-a/67308/nrf5-sdk-v17-0-2-rtt-output-does-not-work-with-specified-ses-version

    The fix remains to disable NRF_FPRINTF_FLAG_AUTOMATIC_CR_ON_LF_ENABLED:

    that option is under 'nRF_Libraries'

  • Thank you @Mauricio Farina, @SEGGER - Johannes and @ for bringing this issue up and solving it.

    I hereby confirm that:

    nordic RTT logging in Segger studio does not work

    while in RTT Viewer it works and this is the case the last v17.0.2 SDK.

    The fix is, as already written, set NRF_FPRINTF_FLAG_AUTOMATIC_CR_ON_LF_ENABLED 0 in sdk_config.h

    I am repeating this as this has to be somehow brought up as the first search result in Google, and please Nordic, resolve it. I (and probably many others) have just lost several hours thinking it was my problem somewhere as it appeared while migrating from nrf5_SDK_for_Mesh_v4.0.0 to the last nRF5_SDK_17.0.2.

Related