Best approach to save data to flash while using Softdevice

Hello,

I am using  nrf52840, SDK 17.0.2, softdevice s140 and also implemented OTA DFU in my application.

I want to save some data lets say admin code in flash. Once I burn the firmware to device it should be like below

 uint8_t ADMIN_CODE[6]  = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};

During my application is running I want to change it to lets say ADMIN_CODE[6]  = {0x12, 0x56,0xFF,0xAA,0xFA,0xCD}. Then this becomes my admin code and when I power off and back on my ADMIN_CODE[6] should not go back to {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF} but instead should remain same ie: {0x12, 0x56,0xFF,0xAA,0xFA,0xCD} And when I do reset then it should go back to  {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}.

I saw some questions like this already on forum, some suggested to use flash write using NVMC or UICR and some suggests to use pstorage or FDS. I am confused what is the best approach in my scenario. Also if you can guide to some example code of right approach, that would be great!

Parents
  • Thank you Jimmywong and Hungbui,

    I am now able to save data to flash using fds and it is doing same as intended when I power off and then on. However, when I do reset, data(admin code) is not reset to default value.

    I guess I need to find the reset handler function and there I can make current value of admin code invalid and update it to its default value.

    The only problem is I cannot find reset handler. Can you please point me to some resource, where it actually explain that what happens when we press reset button on dev kit and if there is some handler function where my program goes once I press reset button.

    Thanks again

Reply
  • Thank you Jimmywong and Hungbui,

    I am now able to save data to flash using fds and it is doing same as intended when I power off and then on. However, when I do reset, data(admin code) is not reset to default value.

    I guess I need to find the reset handler function and there I can make current value of admin code invalid and update it to its default value.

    The only problem is I cannot find reset handler. Can you please point me to some resource, where it actually explain that what happens when we press reset button on dev kit and if there is some handler function where my program goes once I press reset button.

    Thanks again

Children
Related