Flash operations do not work in the hard fault handler (HardFault_c_handler function).

Hi,

I want to log the error type and program counter when a hard fault occurred. I implemented some algorithm for that, I am using fds library for saving this information to flash. I do not get an error when saving hard fault information on the flash. 

How can i save hard fault information to the flash?

Parents
  • Hello,

    I guess there are different ways, but considering you are in the hardfault handler and you can't really depend on any software modules to work, and the interrupts are disabled (or lower priority), so you would need to use flash api that are bare metal and don't rely on interrupts or other software modules. In that case I suggest to use the api in \modules\nrfx\hal\nrf_nvmc.c directly, for instance call nrf_nvmc_page_erase() to erase the flash page you want to store the information, and then follow by one or several calls to nrf_nvmc_write_words(), before you do a system reset to start the chip again. It may be that you need to rename the api in \modules\nrfx\hal\nrf_nvmc.c, because you may using a similar api in your project already that rely on other software modules.

    Kenneth

Reply
  • Hello,

    I guess there are different ways, but considering you are in the hardfault handler and you can't really depend on any software modules to work, and the interrupts are disabled (or lower priority), so you would need to use flash api that are bare metal and don't rely on interrupts or other software modules. In that case I suggest to use the api in \modules\nrfx\hal\nrf_nvmc.c directly, for instance call nrf_nvmc_page_erase() to erase the flash page you want to store the information, and then follow by one or several calls to nrf_nvmc_write_words(), before you do a system reset to start the chip again. It may be that you need to rename the api in \modules\nrfx\hal\nrf_nvmc.c, because you may using a similar api in your project already that rely on other software modules.

    Kenneth

Children
Related