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

Why does nRF52 hrs sdk11 example sd_power_off return 6?

Hello all: I am running a nRF52832QF AAB0 pca10040 board with SDK11 in Segger embedded studio. I followed the 'getting started' tutorial.

After pressing button 1, I noticed an error handler was being triggered. It was the sd_power_system_off call in sleep_mode_enter. This error is also thrown when the device attempts to sleep after advertising times out.

The SD 132 v2.0.0 is initialized prior to this error being thrown. The error is 0x2006, not supported. Surely system off is supported on the nrf52...

Additionally I am using RTT logging if that may make a difference. I'm eager to get up and running with S132 3.0 and SDK12.

  • Proposed solution after some searching: devzone.nordicsemi.com/.../

    Will investigate and report back.


    EDIT

    You can not call sd_power_system_off when a debugger is attached.

    (you can, it just won't work)

    I have confirmed the application runs as expected when the debugger is not attached. The error code makes sense, this is a good example of a 'gotcha'. The nice thing about mistakes is you never have to make the same one again for the rest of your life. Now I know.

  • I've seen errors like this when you try and call an sd_ function without having initialized the softdevice.

  • This is defined in nrf_error_soc.h

    NRF_ERROR_SOC_POWER_OFF_SHOULD_NOT_RETURN         (NRF_ERROR_SOC_BASE_NUM + 6)
    

    The reason is explained by Emulated system off mode.

    If the device is in debug interface mode, System OFF will be emulated to secure that all required resources needed for debugging are available during System OFF. See Debug and trace on page 99 for more information. Required resources needed for debugging include the following key components: 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.

    In normal system off mode, the CPU goes to deep sleep and on wakeup a reset is generated and the CPU execution starts from address 0x0. In emulated system OFF, the CPU keeps on going, but the wakeup resource will generate a reset. sd_power_system_off() function expects that it should not return which is correct in non debug mode.

    I would suggest to to ignore the error in debug mode

    #ifdef DEBUG_NRF
     (void) sd_power_system_off();
     while(1);
    #else
      APP_ERROR_CHECK(sd_power_system_off());
    #endif  // DEBUG_NRF
    

    you have to manually add this (DEBUG_NRF) flag in your project.

  • That looks interesting. So theoretically a wakeup source (let's pick an IO pin, maybe a button press) will in fact generate a reset when in emulated system OFF. Is that correct? Perhaps I will add that while loop.

    Thanks for the snippet!

  • forgot to add while loop in debug mode. fixed it now . Yes both in normal system off and emulated system off, wakeup source will generate a reset.

Related