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

sd_power_system_off in error handler (circumvent the hardfault)

I would like to call sd_power_system_off in my error handler. The product is at a stage where occasional errors still occur as the devices are deployed "in the field" for test purposes.

I would like to log these errors to flash memory and afterwards go to system power off so that the battery doesn't drain unneccessarily while the device is doing nothing. Then I can later reset the device using the reset pin and read the logged error information from flash.

However, depending on where the fault handler is called from, calling sd_power_system_off causes a hardfault (resulting in ~5 mA of constant current consumption) because it is called from the wrong level of interrupt handler. How can I handle these cases and bring the system to a low power state?

Parents
  • I found the answer to the question. Using nrf_power_system_off instead of sd_power_system_off works just fine.

    What I'm doing is:

    void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info)
    {
    #ifdef DEBUG
        error_info_t * err_info = (error_info_t *)info;
    
        ret_code_t err_code = store_err_info(err_info);
    
        if (err_code == NRF_SUCCESS)
        {
            // let's give it some more time to complete the flash write
            nrf_delay_ms(1000);
    
            for (int i = 0; i < NUMBER_OF_PINS; ++i)
            {
                if (i != 21) // exclude the reset pin
                    nrf_gpio_input_disconnect(i);
            }
    
            __sd_nvic_irq_disable();
    
            while (true)
            {
                nrf_power_system_off();
            }
        }
        else
        {
            ...
    

    does this make any sense? What I'm observing is that on pushing the button I still sometimes get LEDs flashing on the device (normal behavior in response to the button push), so it appears that the device is still woken by the button push (cannot verify in the debugger as there it seems to not wake).

  • Seems like this is ok. Note that you have three wakeup sources while in system off, see this. To disable the wakeup on GPIO turn off sense and enable pullup/down, or disconnect the pin(s).

Reply Children
No Data
Related