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

How to do the log mechanism whenever wdt or hard fault happens in NRF52832?

Hi

My application with SDK11 S132 softdevice is having some unknown issues that will make wdt or hard fault handler happen. And I am trying to use the following code to access the flash memory in wdt

sd_flash_page_erase( page_num ); nrf_delay_ms(50); sd_flash_write( calib_addr, program_word, 25 ); nrf_delay_ms(50);

but it jumps to hard fault handler. How can I implement the mechanism even in hard fault, wdt, bus fault handler to store some important indicators in the flash so that I can still get the information in the next boot up?

  • You can't use the softdevice sd_ functions. You're already in a handler, the chip can't make a SVC call. At this point you should only use direct calls into the NVIC to clear a page and write the data you want.

  • Hi RK, Do you have any example for it? I am quite rookie to arm based architecture or any example provided in SDK11?

  • I tried to access the NVMC register with the following codes in WDT_handler, but it failed. The same code works fine in main thread. Did I miss anything?

    static void flash_page_erase(uint32_t * page_address){
    // Turn on flash erase enable and wait until the NVMC is ready:
    NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Een << NVMC_CONFIG_WEN_Pos);
    
    while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
    {
        // Do nothing.
    }
    
    // Erase page:
    NRF_NVMC->ERASEPAGE = (uint32_t)page_address;
    
    while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
    {
        // Do nothing.
    }
    
    // Turn off flash erase enable and wait until the NVMC is ready:
    NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos);
    
    while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
    {
        // Do nothing.
    }
    

    }

    static void flash_word_write(uint32_t * address, uint32_t value)
    {
    // Turn on flash write enable and wait until the NVMC is ready:
    NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos);
    
    while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
    {
        // Do nothing.
    }
    
    *address = value;
    
    while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
    {
        // Do nothing.
    }
    
    // Turn off flash write enable and wait until the NVMC is ready:
    NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos);
    
    while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
    {
        // Do nothing.
    }
    

    }

  • How does it fail? Hard faults? Have you debugged and set breakpoints in your functions to pinpoint where things fail?

  • It failed at NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Een << NVMC_CONFIG_WEN_Pos); at the beginning of flash_page_erase. I also put the breakpoint in the hard fault handler but system did not get there. It seems like that I cannot access NVMC register in the WDT_handler. Any idea? Thanks!!!

Related