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 Reply
  • Perhaps you're misunderstanding the problem: the code throws an ASSERT error when no error is warranted.

    The ASSERT statement is assuming the expected result from sd_power_system_off() is NRF_SUCCESS, but that syscall NEVER returns NRF_SUCCESS. However, sd_power_system_off() DOES return NRF_ERROR_SOC_POWER_OFF_SHOULD_NOT_RETURN if and only if the debug module is connected.

    With the current bug, it's impossible to debug waking from system off because the erroneous ASSERT prevents the chip from entering the 'simulated' power system off that consists of an infinite loop around __WFE.

Children
Related