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

How to handle flashwrit in an safe way.

Hi,

i need to store data in my Flash, for that i use the flashwrite example. Am i right taht i can use the remain of my application flash? So all flash = 256 kB - App = 20 kB = Flash i can use to write my Data to ?

I read that if i use flashwrite and the Softdevie, that i have to halt the Softdevie becauose of the latncy of flahswriting is that right? How can i handle this in a safe way?

Best reagrds Nils

Parents
  • All of the flash can be used both for code and for data, but you do of course have to make sure that you don't try to write data to the areas occupied by the softdevice or the application. Depending on application size, the upper pages should be free, except for the ones used by the bond manager.

    Flash writing and erasing will halt the CPU, and for that reason, you must make sure to not do it when the softdevice needs the CPU. This means that you must do it between connection events (or advertising events). The softdevice provides a radio notification feature to allow you to know when a radio event is finished. At that time, you can do flash operations for a period equal to the connection interval*(slave latency-1) - some ms. Note that erasing a flash page takes typical 21 ms, so if you have a short connection interval, that might not be possible without slave latency. Also, if you have queued data to be sent, for example by sending a notification, the softdevice might need to wake up even if you do have slave latency.

    You can take a look at the ble_radio_notification module in the SDK for more information on how the radio notification feature can be used. Also, there are some pointers given in different questions here on the developer zone, so I'd recommend you to do a few searches. Let me know if you have specific problems.

Reply
  • All of the flash can be used both for code and for data, but you do of course have to make sure that you don't try to write data to the areas occupied by the softdevice or the application. Depending on application size, the upper pages should be free, except for the ones used by the bond manager.

    Flash writing and erasing will halt the CPU, and for that reason, you must make sure to not do it when the softdevice needs the CPU. This means that you must do it between connection events (or advertising events). The softdevice provides a radio notification feature to allow you to know when a radio event is finished. At that time, you can do flash operations for a period equal to the connection interval*(slave latency-1) - some ms. Note that erasing a flash page takes typical 21 ms, so if you have a short connection interval, that might not be possible without slave latency. Also, if you have queued data to be sent, for example by sending a notification, the softdevice might need to wake up even if you do have slave latency.

    You can take a look at the ble_radio_notification module in the SDK for more information on how the radio notification feature can be used. Also, there are some pointers given in different questions here on the developer zone, so I'd recommend you to do a few searches. Let me know if you have specific problems.

Children
  • I Think my main problem is that i don#t understand what in the sdk example happens. I only need to safe some data in free flash and i need to knwo wher it begins and where it and. Maybe you can explain me how the address in the example is calculated. And is this static, so could i define this addres as beginning address?

  • Hi Ole,

    thanks for your feedback.

    So normaly i can define my first address where i want to write the first Data is that right becouse my Application Code is also static thes address would be the same every time?

    And then i can right data to it like in the example of your SDk with an increment of the address.

    How do i know if the page i am writing to is full and how can i go to the next page or is this automatically done?

    best regards Nils

  • There is no silver bullet when it comes to flash writing, and you will have to keep track of a lot of details yourself. Marc is quite correct below, we're happy to help you, but we can not and will not do the implementation for you.

    I do believe that you've gotten the information you need to do this implementation, but if anything in particular is unclear, I can try to elaborate. I've tried clearing up a few things below:

    • As long as you don't do a recompile, the size of your application will not change.
    • There is no magic way to know if a particular flash address have been written or not, but newly erased flash will always have the value 0xFF. If the value is 0xFF, you can therefore most likely assume that it isn't written, although 0xFF could of course also be the value that was written. This is often overcome by using framing bytes, adding CRC and block sizes or similar.
    • There is no automatic way to know if a page is full, or to progress to the next page. You have to monitor the address you write to yourself, and handle this in your application, either to erase the same page or start writing to the next page.
Related