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

How to detect cause of Reset

Hello,

 

I am using nRF52832, SDK_15.3.0, S132 SoftDevice and Segger for flashing the image. I am using ‘ble_app_blinky’.

 

1) As per below link, do I need to skip GPIO initialization when chip wakeup from System OFF or even peripheral, ble and other initializations (Ex: rtc, timers etc…) can be skipped.

https://devzone.nordicsemi.com/f/nordic-q-a/38550/gpio-value-after-wake-up-from-gpio

 

2) Is there any API to know the status of reset (System OFF, Watchdog etc…) or directly read NRF_POWER->RESETREAS register.

 

3) As per below link, I am trying to print RESETREAS register. But code gets hanged. Do I need to call NRF_POWER->RESETREAS before enabling of SoftDevice.

https://devzone.nordicsemi.com/f/nordic-q-a/38405/detect-wake-up-reason-from-deep-sleep/148200#148200

 

 

    #if 1
    uint32_t u32Reset_reason = NRF_POWER->RESETREAS;
    NRF_LOG_INFO("Reset Status %x", u32Reset_reason);
    NRF_POWER->RESETREAS = NRF_POWER->RESETREAS; // Clear reset reason by writting 1.
    #endif

I called above code after all Peripheral and SoftDevice initilization. But I am getting below debug prints.

<info> app: Reset Status 0

<error> app: SOFTDEVICE: INVALID MEMORY ACCESS

Thanks & Regards

Vishnu Beema

Parents
  • Hi,

    I'd recommend that you read the register before doing anything else.

    You can always store the value to then use once you've initialised the rest of your system.

    With the code that you're using above, have you initialised the NRF logging functionality first?

  • Hi,

    As shown below, I initialized NRF logging functionality.

    First reset cause is working fine. But if I enable code at last I am getting error messages and code hangs.

    Also can you please let me know your inputs on above query 1.

    int main(void)
    {
        // Initialize.
        log_init();
    
        #if 0
        uint32_t u32Reset_reason = NRF_POWER->RESETREAS;
        NRF_LOG_INFO("Reset Status1 %x", u32Reset_reason);
        NRF_POWER->RESETREAS = NRF_POWER->RESETREAS; // Clear reset reason by writting 1.
        #endif
    
        leds_init();
        timers_init();
        buttons_init();
        power_management_init();
        ble_stack_init();
        gap_params_init();
        gatt_init();
        services_init();
        advertising_init();
        conn_params_init();
        
        #if 1
        uint32_t u32Reset_reason = NRF_POWER->RESETREAS;
        NRF_LOG_INFO("Reset Status2 %x", u32Reset_reason);
        NRF_POWER->RESETREAS = NRF_POWER->RESETREAS; // Clear reset reason by writting 1.
        #endif
    
        // Start execution.
        NRF_LOG_INFO("Blinky example started.");
        advertising_start();
    
        // Enter main loop.
        for (;;)
        {
            idle_state_handle();
        }
    }

    Thanks & Regards

    Vishnu Beema

Reply
  • Hi,

    As shown below, I initialized NRF logging functionality.

    First reset cause is working fine. But if I enable code at last I am getting error messages and code hangs.

    Also can you please let me know your inputs on above query 1.

    int main(void)
    {
        // Initialize.
        log_init();
    
        #if 0
        uint32_t u32Reset_reason = NRF_POWER->RESETREAS;
        NRF_LOG_INFO("Reset Status1 %x", u32Reset_reason);
        NRF_POWER->RESETREAS = NRF_POWER->RESETREAS; // Clear reset reason by writting 1.
        #endif
    
        leds_init();
        timers_init();
        buttons_init();
        power_management_init();
        ble_stack_init();
        gap_params_init();
        gatt_init();
        services_init();
        advertising_init();
        conn_params_init();
        
        #if 1
        uint32_t u32Reset_reason = NRF_POWER->RESETREAS;
        NRF_LOG_INFO("Reset Status2 %x", u32Reset_reason);
        NRF_POWER->RESETREAS = NRF_POWER->RESETREAS; // Clear reset reason by writting 1.
        #endif
    
        // Start execution.
        NRF_LOG_INFO("Blinky example started.");
        advertising_start();
    
        // Enter main loop.
        for (;;)
        {
            idle_state_handle();
        }
    }

    Thanks & Regards

    Vishnu Beema

Children
  • Perhaps it's because you're running the reset detection after initialising the SoftDevice.

    I'm running the following as my first lines in main, before any hardware or SoftDevice initialisation without problems:

        ret_code_t err_code = NRF_LOG_INIT(NULL);
        APP_ERROR_CHECK(err_code);
    
        NRF_LOG_DEFAULT_BACKENDS_INIT();
        NRF_LOG_INFO("INIT START");
    
        int32_t reset_reason = NRF_POWER->RESETREAS;
        NRF_LOG_INFO("Reset reason = 0x%08x.\n", reset_reason);
        NRF_POWER->RESETREAS = NRF_POWER->RESETREAS;
    

  • Thank you for confirmation.

    Also can you please let me know your inputs on above query 1 regarding skipping of initialization.

  • You'll certainly need to reinitialise the SoftDevice and your BLE.

    Personally I prefer to run through as much initialisation as possible, but depending on your application there may be things that you skip e.g. GPIO lines that you set to specific states before power off, that you wish to retain their state without interruption on power-up.

    Anything reliant on RAM will need to be initialised on restart from System OFF as its not retained unless you've set it to remain powered through use of RAM[n].POWER registers on shutdown.

  • Hi,

    You can store the err_code on the flash (particular region) inside the app_error_handler.

    https://github.com/jimmywong2003/nrf5-debug-save-error-code-flash-app

    void app_error_save_and_stop(uint32_t id, uint32_t pc, uint32_t info)
    {
    ...
            case NRF_FAULT_ID_SDK_ERROR:
                    m_error_data.p_error_info = (error_info_t *)info;
                    m_error_data.err_code     = m_error_data.p_error_info->err_code;
                    m_error_data.line_num     = m_error_data.p_error_info->line_num;
                    m_error_data.p_file_name  = m_error_data.p_error_info->p_file_name;
                    path_addr=(uint32_t *)m_error_data.p_error_info->p_file_name;
    
    
                    // Erase page:
                    flash_page_erase(flash_addr);
                    flash_word_write(flash_addr, m_error_data.err_code);
                    flash_addr++;
                    flash_word_write(flash_addr, m_error_data.line_num);
                    flash_addr++;
                    for(store_length=0; store_length<1000;)
                    {

    When you print out the reset reason (NRF_POWER->RESETREAS) after just system power up,

    if the reset reason is 0, most likely it is caused by the POR (Power on reset ) or BOR (Burst on reset).

    If it is non-zero value, you can refer to the table as below (inside the Product specification).

Related