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

Save in flash a NO_INIT variable

Hi everyone!

After defining a variable as no_init , my intention is to update its value along the program to debug what was its last state before a random reset.

I am able to write this variable in flash but it never remains its last value after reset.

I am using softdevice so I think that although it is defined as no_init, it is reset by softdevice during ble_stack_init.

I have tested doing Hardware Pin Reset as well as NVIC_System_reset().

is there  any way to save its value before it is reset again?

Parents
  • Hi,

    Flash writes are time consuming operations that need to go through the SoftDevice API if the SoftDevice is enabled. Also note that flash is written by flipping bits from 1 to 0, and the only way to flip bits back from 0 to 1 again is to do a flash page erase (that is, flip all bits in the 4096 byte flash page back to 1.)

    There is no writing to flash as part of ble_stack_init(), so either the flash write operation did not finish before the reset, there is a flash erase performed elsewhere in the code, or the method used for flash writing is wrong.

    • How are you writing to flash?
    • How do you confirm the value is correctly written to flash before reset?
    • How are you checking the value after reset?

    Regards,
    Terje

Reply
  • Hi,

    Flash writes are time consuming operations that need to go through the SoftDevice API if the SoftDevice is enabled. Also note that flash is written by flipping bits from 1 to 0, and the only way to flip bits back from 0 to 1 again is to do a flash page erase (that is, flip all bits in the 4096 byte flash page back to 1.)

    There is no writing to flash as part of ble_stack_init(), so either the flash write operation did not finish before the reset, there is a flash erase performed elsewhere in the code, or the method used for flash writing is wrong.

    • How are you writing to flash?
    • How do you confirm the value is correctly written to flash before reset?
    • How are you checking the value after reset?

    Regards,
    Terje

Children
No Data
Related