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

How to know it started first time after flash firmware.

I'm actually writing some data to the flash. I'm using pstorage api interface.

But whenever I flash the new firmware, I get some garbage data. in my main function I would like to know that, after flashing a new firmware, it started for the first time, so I clear the garbage data, and want to make sure it is not result of a reset or a manual reset etc.

Thanks

  • @mobi: Could you elaborate a little bit more ? My understanding is when you flash the firmware you write some flags (garbage data) to a location on flash.
    On the first time when the firmware starts, it will read that address and if the flags are set, it will clear the flags. So that next time when the device reset or restart it will be able to detect by reading the flags' address again ? If it's correct, I don't see a problem with this approach.

  • Hi Hung, I have implemented similar to what you suggested already, that is, I write some header in flash. On Start of the firmware, I read header, if the header is not correct, that mean entire flash data is not valid and I need to erase that. But I have to waste a page data (140 bytes). Rest of the pages are used for other data and information storage. So, if there is an alternate to wasting page data, that will be great.

  • BTW, can you point me where to get some more knowledge about flags? what you have suggested? So, on flashing the firmware if I can set some flag. And when the application runs I can check that flag. Can I also reset that flag from that application again ? Thanks

  • Hi mobi,

    I called it flags, but it could be anything that you set in flash.

    I am not fully understand what you meant by "waste data". If you want to erase/modify something on flash, you would need to erase the whole page (1024 byte). To write data to an address in flash when programming, you should use attribute and set the address and the value you want to write to flash. You can refer on how we do it in file bootloader_settings_arm.c in the dfu bootloader example in the nRF51 SDK.

    For example here we write BOOTLOADER_REGION_START value to NRF_UICR_BOOT_START_ADDRESS address:

    uint32_t m_uicr_bootloader_start_address __attribute__((at(NRF_UICR_BOOT_START_ADDRESS))) = BOOTLOADER_REGION_START;
    
Related