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

sd_power_system_off resets?

I'm using nrf_pwr_mgmt_shutdown to shut down the system to wake on interrupt. 17.0.2 SDK and 7.2.0 softdevice. When I step through the code with a debugger, it gets to sd_power_system_off and then when I attempt to step over it reboots. The bootloader starts and launches the app. Is this because a debugger is connected? When the softdevice is not enabled, and nrf_power_system_off is called instead, it does shut down correctly.

Parents
  • Hi,

    Yes, when the debugger is connected, the chip will enter Emulated System OFF mode. The code will return from the function, and the debugger can continue executing code. Normally the return-code from the softdevice functions are passed to APP_ERROR_CHECK, which will put your application in the error handler in case of non-zero return code. sd_power_system_off() will return NRF_ERROR_SOC_POWER_OFF_SHOULD_NOT_RETURN if you are in debug mode and Emulated system OFF is entered.

    If you want to continue debugging in emulated system off mode, remove the APP_ERROR_CHECK(), and replace it with a while(1)-loop, to prevent application from executing unexpected code.

    Best regards,
    Jørgen

  • This would be fine, but it isn't what happens. The sd_power_system_off is not returning, it is rebooting immediately.

    Here is the (slightly modified) code from nrf_pwr_mgmt.c

    ret_code_t ret_code = sd_power_system_off();
    //            ASSERT((ret_code == NRF_SUCCESS) || (ret_code == NRF_ERROR_SOFTDEVICE_NOT_ENABLED) || (ret_code == NRF_ERROR_SOC_POWER_OFF_SHOULD_NOT_RETURN));
                UNUSED_VARIABLE(ret_code);
    #ifdef DEBUG
    #pragma GCC diagnostic push
    #pragma GCC diagnostic ignored "-Wmissing-noreturn"
                while (true)
                {
                    /* Since the CPU is kept on in an emulated System OFF mode, it is recommended
                     * to add an infinite loop directly after entering System OFF, to prevent
                     * the CPU from executing code that normally should not be executed. */
                    __WFE();
    
                }

    I can place a breakpoint on sd_power_system_off and it will be hit, but stepping over it results immediately in a reboot. I want that function to either power off or return (which will be handled by the loop), not reboot.

Reply
  • This would be fine, but it isn't what happens. The sd_power_system_off is not returning, it is rebooting immediately.

    Here is the (slightly modified) code from nrf_pwr_mgmt.c

    ret_code_t ret_code = sd_power_system_off();
    //            ASSERT((ret_code == NRF_SUCCESS) || (ret_code == NRF_ERROR_SOFTDEVICE_NOT_ENABLED) || (ret_code == NRF_ERROR_SOC_POWER_OFF_SHOULD_NOT_RETURN));
                UNUSED_VARIABLE(ret_code);
    #ifdef DEBUG
    #pragma GCC diagnostic push
    #pragma GCC diagnostic ignored "-Wmissing-noreturn"
                while (true)
                {
                    /* Since the CPU is kept on in an emulated System OFF mode, it is recommended
                     * to add an infinite loop directly after entering System OFF, to prevent
                     * the CPU from executing code that normally should not be executed. */
                    __WFE();
    
                }

    I can place a breakpoint on sd_power_system_off and it will be hit, but stepping over it results immediately in a reboot. I want that function to either power off or return (which will be handled by the loop), not reboot.

Children
No Data
Related