Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nrf_pwr_mgmt bug

I think I've found a bug in the power management that occurs only when a softdevice and the debug interface are active. In SDK v17.0.2, nrf_pwr_mgmt.c lines 417-429:

            ret_code_t ret_code = sd_power_system_off();    // Expected ret_code is NRF_ERROR_SOC_POWER_OFF_SHOULD_NOT_RETURN
            ASSERT((ret_code == NRF_SUCCESS) || (ret_code == NRF_ERROR_SOFTDEVICE_NOT_ENABLED));
            UNUSED_VARIABLE(ret_code);
#ifdef DEBUG
            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();
            }
#endif

The ASSERT statement fails to catch the case where sd_power_system_off returns NRF_ERROR_SOC_POWER_OFF_SHOULD_NOT_RETURN with a debugger connected.

Parents
  • Hi Benjamin

    Do you add SOFTDEVICE_PRESENT into the preprocessor Definitions as the figure? 

    The code should work when the SOFTDEVICE_PRESENT is added into the preprocessor Definitions. 

    #ifdef SOFTDEVICE_PRESENT
            if (nrf_sdh_is_enabled())
            {
                ret_code_t ret_code = sd_power_system_off();
                ASSERT((ret_code == NRF_SUCCESS) || (ret_code == NRF_ERROR_SOFTDEVICE_NOT_ENABLED));
                UNUSED_VARIABLE(ret_code);
    #ifdef DEBUG
                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();
    
                }
    #endif
            }
    #endif // SOFTDEVICE_PRESENT

    -Amanda H.

  • Yes, without SOFTDEVICE_PRESENT set none of this code would be executed.

    The primary issue is that, per nrf_soc.h, the syscall sd_power_system_off() returns NRF_ERROR_SOC_POWER_OFF_SHOULD_NOT_RETURN, but only when there's a debugger attached (because of https://infocenter.nordicsemi.com/topic/ps_nrf52840/power.html?cp=4_0_0_4_2_2_0#unique_142049681). sd_power_system_off() will never return NRF_SUCCESS.

    Swapping NRF_SUCCESS for NRF_ERROR_SOC_POWER_OFF_SHOULD_NOT_RETURN eliminates the erroneous assert error.

Reply Children
Related