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

error returned with sd_power_system_off()

Hi,

I've been working on the hrs example for nRF52840 DK and I wanted to add buttons to the project. For the first button (I took from app_blinky), it is working perfectly fine. I thought it worked perfectly fine for the second as well until I noticed that unlike the case with only one button, the advertising wasn't starting again after APP_ADV_DURATION.

The sd_power_system_off() starts returning the error code 8198. I read somewhere that it was normal as this function isn't suppose to work in debug mode. It will enter its emulated state, which was working fine with one button. I wonder why adding as second button changed its behaviour:

static void buttons_init(void)
{
    ret_code_t err_code;

    //The array must be static because a pointer to it will be saved in the button handler module.
    static app_button_cfg_t buttons[] =
    {
        {START_BUTTON, false, BUTTON_PULL, button_event_handler},
        {STOP_BUTTON, false, BUTTON_PULL, button_event_handler},
    };

    err_code = app_button_init(buttons, ARRAY_SIZE(buttons),
                               BUTTON_DETECTION_DELAY);
    APP_ERROR_CHECK(err_code);
}

Did I need to change something in sdk_config.h in order to add one more button ? I didn't see anything important while looking into the file. Why is sd_power_system_off() returning something now while it wasn't previously ?

static void sleep_mode_enter(void)
{
    ret_code_t err_code;

    err_code = bsp_indication_set(BSP_INDICATE_IDLE);
    APP_ERROR_CHECK(err_code);

    // Prepare wakeup buttons.
    err_code = bsp_btn_ble_sleep_mode_prepare();
    APP_ERROR_CHECK(err_code);

    // Go to system-off mode (this function will not return; wakeup will cause a reset).
    err_code = sd_power_system_off();
    APP_ERROR_CHECK(err_code);
}

Best regards,

FM

  • Hello FM,

    I thought it worked perfectly fine for the second as well until I noticed that unlike the case with only one button, the advertising wasn't starting again after APP_ADV_DURATION.

    Could you elaborate on this, what do you mean that the advertisement does not start again after the advertising duration is over?

    The sd_power_system_off() starts returning the error code 8198. I read somewhere that it was normal as this function isn't suppose to work in debug mode.

    This is correct - when the debugger is attached it will not go into SYSTEM_OFF, since the debugger then would not be able to do anything for the duration of the sleep.
    Therefore, the SYSTEM_OFF sleep is emulated as a while(1) loop idling the CPU with interrupts disabled.

    Did I need to change something in sdk_config.h in order to add one more button ? I didn't see anything important while looking into the file. Why is sd_power_system_off() returning something now while it wasn't previously ?

    It sounds strange to me that additional buttons would cause sd_power_system_off() to behave differently. This function should however always return an error when the debugger is attached, but when the debugger is not in use it should not return anything.
    Could you try to run your application without the debugger attached, to see if it then behaves as expected?

    Best regards,
    Karl

  • Hi Karl,

    Could you elaborate on this, what do you mean that the advertisement does not start again after the advertising duration is over?

    What I meant was that the error prevented the advertising to start again.

    Could you try to run your application without the debugger attached, to see if it then behaves as expected?

    Indeed when running the code without debugger it does seem to work perfectly fine. Although I don't quite understand why adding a button started to make it return an error in debugger this time.

    The function sd_power_system_off() was already there and the code used to run through it without returning anything (as it is supposed to work) even in debugger mode. Adding that button changed the behaviour for some reason.

    Thanks for the help !

    Best regards,

    FM

  • Hello again FM, 

    FM37 said:
    What I meant was that the error prevented the advertising to start again.

    Aha, now I understand - thank you for clarifying. 

    FM37 said:

    Indeed when running the code without debugger it does seem to work perfectly fine. Although I don't quite understand why adding a button started to make it return an error in debugger this time.

    The function sd_power_system_off() was already there and the code used to run through it without returning anything (as it is supposed to work) even in debugger mode. Adding that button changed the behaviour for some reason.

    It is expected that sd_power_system_off will return an error code when running with a debugger, since the function normally (without a debugger) will never return. The returned error code will cause the APP_ERROR_CHECK to fail, which will reset the device (if not specific error handling is implemented). Normally, when in SYSTEM OFF mode, the only thing that can wake the device again is an external interrupt on a predesignated pin.
    I am happy to hear that it works as expected without the debugger connected!

    I would say that it sounds stranger that the sd_power_system_off did not return the error code when running with the debugger and a single button - this is unexpected.

    FM37 said:
    Thanks for the help !

    No problem at all, I am happy to help!

    Please do not hesitate to open another ticket if you should encounter any issues or questions in the future! :)

    Best regards,
    Karl

Related