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

Segger Embedded Studio loops in softdevice

Hi,

My project cannot be debugged using Segger Embedded Studio. The debugger doesn't halt at the application main and instead keeps running. Hitting a pause shows the debugger at 'SEV' instruction at address 0x0001304A (which seems to be from softdevice). I am using the softdevice s132v5.1 and the application uses freertos similar to the HRS example in SDK.

Any inputs on the reason for debugger behaving so?

Thanks.

  • Hi,

    The __SEV and __WFE instructions in the softdevice are used to make the chip enter system ON idle mode (sleep), which typically is >99% of the time. In other words, there is a high probability that the PC will be at 0x0001304A when you halt the CPU. 

    SES projects delivered in our SDKs are configured to break at main, and I verified this with the hrs freertos example in SDK 14.2.0. Have you tried this example?

    Debugger settings to break at main:

  • Hi,

    Thanks for your response. OK. That makes sense about SEV, WFE instruction. Yes my debugger settings are fine and I am able to debug the example and my code during initial stages of the project. As more modules were added the debugger does not halt at main (instead is just in running state). The BLE DFU bootloader enters DFU mode when segger debug->go option is selected. I can't figure out why debugging invalidates the app.

  • Hi, 

    The bootloader runs a CRC check on the application on startup to check if it is valid, and enters DFU mode if the check fails. This check will fail if you make code changes in the app, then upload the new app through SES. Do you see the same if you erase the bootloader? 

  • Yes! Thanks that does help although it causes other issues like DFU BLE service cannot be initialised because the bootloader address is not found in NRF_UICR->NRFFW[1] register. Is there a way to generate a hex file which skips the CRC check? i.e. bootloader settings file with 0 CRC

  • You can skip the crc in nrf_dfu_utils.c -> nrf_dfu_app_is_valid() by doing something like this:

    bool nrf_dfu_app_is_valid(void)
    {
        NRF_LOG_DEBUG("Enter nrf_dfu_app_is_valid");
        if (s_dfu_settings.bank_0.bank_code != NRF_DFU_BANK_VALID_APP)
        {
           // Bank 0 has no valid app. Nothing to boot
           NRF_LOG_DEBUG("Return false in valid app check");
           return false;
        }
    
    #ifndef SKIP_INTEGRITY_CHECK
        // If CRC == 0, the CRC check is skipped.
        if (s_dfu_settings.bank_0.image_crc != 0)
        {
            uint32_t crc = crc32_compute((uint8_t*) CODE_REGION_1_START,
                                         s_dfu_settings.bank_0.image_size,
                                         NULL);
    
            if (crc != s_dfu_settings.bank_0.image_crc)
            {
                // CRC does not match with what is stored.
                NRF_LOG_DEBUG("Return false in CRC");
                return  false;
            }
        }
    #endif //SKIP_INTEGRITY_CHECK
    
        NRF_LOG_DEBUG("Return true. App was valid");
        return true;
    }

     

    Note that compile time flags to skip CRC check were added in SDK 15. You could implement the same in SDK 14  (flags to skip CRC in SDK 15).  

Related