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

nrf_pwr_mgmt_shutdown() fails while debugging.

Hi

Im using nRF52832-QAAB0. SDK 15.3. Softdevice is running. 

With debugger connected, calling nrf_pwr_mgmt_shutdown(NRF_PWR_MGMT_SHUTDOWN_STAY_IN_SYSOFF) will assert in shutdown_process() when sd_power_system_off() returns. 
According to https://devzone.nordicsemi.com/f/nordic-q-a/15677/why-does-nrf52-hrs-sdk11-example-sd_power_off-return-6 nordic employee recommends adding while(1); after calling sd_power_system_off()

Is there any reason nrf_pwr_mgmt_shutdown() does not handle debugging?
Parents
  • Yeah, it's called "emulated shutdown". If the MCU goes into SystemOFF mode with a debugger attached then the DAP - Debug access port will also shut down and you will exit whatever debugging session you're in. This is not really conducive to debugging so we emulated the shutdown, either by putting the system into SystemON Idle mode , holding the CPU in an infinite loop, or stopping the CPU. 

    Try compiling without the DEBUG flags, in SES you can use the "release" build environment. 

  • Surely this is still incorrect behaviour in nrf_pwr_mgmt_shutdown though – it should have a while(1) after the call to sd_power_system_off as nrf_power_system_off does:

    /* Solution for simulated System OFF in debug mode */
    while (true)
    {
        __WFE();
    }

    Seems like a bug?

  • I won't get fixed in the SoftDevice so the power management library should have handled that, but it does not. You'll want to use an ifdef for debug mode though: 

    /* Solution for simulated System OFF in debug mode */
    
            // Enter System OFF.
    #ifdef SOFTDEVICE_PRESENT
            if (nrf_sdh_is_enabled())
            {
                ret_code_t ret_code = sd_power_system_off();
    #ifdef DEBUG
                while(true)
                {
                    __WFE;
                } 
    #else
                ASSERT((ret_code == NRF_SUCCESS) || (ret_code == NRF_ERROR_SOFTDEVICE_NOT_ENABLED));
    #endif
                UNUSED_VARIABLE(ret_code);
            }
    #endif // SOFTDEVICE_PRESENT
            nrf_power_system_off();

Reply
  • I won't get fixed in the SoftDevice so the power management library should have handled that, but it does not. You'll want to use an ifdef for debug mode though: 

    /* Solution for simulated System OFF in debug mode */
    
            // Enter System OFF.
    #ifdef SOFTDEVICE_PRESENT
            if (nrf_sdh_is_enabled())
            {
                ret_code_t ret_code = sd_power_system_off();
    #ifdef DEBUG
                while(true)
                {
                    __WFE;
                } 
    #else
                ASSERT((ret_code == NRF_SUCCESS) || (ret_code == NRF_ERROR_SOFTDEVICE_NOT_ENABLED));
    #endif
                UNUSED_VARIABLE(ret_code);
            }
    #endif // SOFTDEVICE_PRESENT
            nrf_power_system_off();

Children
Related