<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>How to handle flashwrit in an safe way.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/557/how-to-handle-flashwrit-in-an-safe-way</link><description>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</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 08 Oct 2013 07:07:02 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/557/how-to-handle-flashwrit-in-an-safe-way" /><item><title>RE: How to handle flashwrit in an safe way.</title><link>https://devzone.nordicsemi.com/thread/2877?ContentTypeID=1</link><pubDate>Tue, 08 Oct 2013 07:07:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b05431b6-d810-4356-a879-06dd819942fd</guid><dc:creator>Ole Morten</dc:creator><description>&lt;p&gt;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&amp;#39;re happy to help you, but we can not and will not do the implementation for you.&lt;/p&gt;
&lt;p&gt;I do believe that you&amp;#39;ve gotten the information you need to do this implementation, but if anything in particular is unclear, I can try to elaborate. I&amp;#39;ve tried clearing up a few things below:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;As long as you don&amp;#39;t do a recompile, the size of your application will not change.&lt;/li&gt;
&lt;li&gt;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&amp;#39;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.&lt;/li&gt;
&lt;li&gt;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.&lt;/li&gt;
&lt;/ul&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to handle flashwrit in an safe way.</title><link>https://devzone.nordicsemi.com/thread/2881?ContentTypeID=1</link><pubDate>Mon, 07 Oct 2013 12:30:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5dc69600-aadc-4cc3-9e45-98add8b5b69e</guid><dc:creator>Marc Nicholas</dc:creator><description>&lt;p&gt;Hi Nils,&lt;/p&gt;
&lt;p&gt;I think you&amp;#39;re asking two things:&lt;/p&gt;
&lt;p&gt;(1) How to erase* and write to Flash
(2) How to construct and erase a circular/ring buffer&lt;/p&gt;
&lt;p&gt;*I&amp;#39;m preempting what&amp;#39;s coming next. IIRC, you need to erase the Flash page at least once every two write cycles.&lt;/p&gt;
&lt;p&gt;I would say it&amp;#39;s reasonable to ask for support on the first question, but the second question is a bit of stretch as it&amp;#39;s a generic programming issue. Unfortunately, I can&amp;#39;t share our code to do it as we consider it proprietary, but there&amp;#39;re some examples of how to do this on the Interweb. For example:&lt;/p&gt;
&lt;p&gt;&lt;a target="_blank" href="http://www.embedded.com/electronics-blogs/embedded-round-table/4419407/The-ring-buffer" rel="nofollow"&gt;http://www.embedded.com/electronics-blogs/embedded-round-table/4419407/The-ring-buffer&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Note: the example is a simple ring buffer, but the contents of a ring buffer itself can easily be a struct that contains your datatypes.&lt;/p&gt;
&lt;p&gt;-m&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to handle flashwrit in an safe way.</title><link>https://devzone.nordicsemi.com/thread/2878?ContentTypeID=1</link><pubDate>Mon, 07 Oct 2013 11:34:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:01b11671-5863-4a3e-87e9-d6ae045001c5</guid><dc:creator>Nils Minor</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;in the moment it is not possible for me to write an application which writes data to the Flash in a savety way. The best thing would be an example how to programm Log-File-Data to the memory. Maybe this will not be possible to get this example so i have to write it be my self, but for that i need to understand what i have to to to write in a savety way to the Flash.&lt;/p&gt;
&lt;p&gt;Do i understand this correctly,in the example of SDK tha Data will be written on the Last Page every Time again and again ? And after the Page is full it begins at the start adress again?
But this is not the way i want to use it, i need to write as much as possible into the Flash, not only to one Page.&lt;/p&gt;
&lt;p&gt;Please Nordic give me Some more support, i really try to understand but its hard for me, more examples would be great,&lt;/p&gt;
&lt;p&gt;Thank you and best regards nils&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to handle flashwrit in an safe way.</title><link>https://devzone.nordicsemi.com/thread/2876?ContentTypeID=1</link><pubDate>Mon, 07 Oct 2013 05:52:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d347046b-61a2-4659-86e4-25e02b884645</guid><dc:creator>Nils Minor</dc:creator><description>&lt;p&gt;Hi Ole,&lt;/p&gt;
&lt;p&gt;thanks for your feedback.&lt;/p&gt;
&lt;p&gt;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?&lt;/p&gt;
&lt;p&gt;And then i can right data to it like in the example of your SDk with an increment of the address.&lt;/p&gt;
&lt;p&gt;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?&lt;/p&gt;
&lt;p&gt;best regards Nils&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to handle flashwrit in an safe way.</title><link>https://devzone.nordicsemi.com/thread/2880?ContentTypeID=1</link><pubDate>Fri, 04 Oct 2013 13:42:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:369fd0f9-9052-4b01-a11b-f05da72bdece</guid><dc:creator>Ole Morten</dc:creator><description>&lt;p&gt;Flash is normally divided into parts, called pages. On the nRF51822, a page is a 1024 byte area of the flash, so a 256 kB version of the chip will have NRF_FICR-&amp;gt;CODESIZE = 0x100 = 256.&lt;/p&gt;
&lt;p&gt;The example snippet you show takes this number, subtracts 1, and multiplies it with the page size in bytes. This will give you the start address of the last page, which is then written to.&lt;/p&gt;
&lt;p&gt;There isn&amp;#39;t any magic way to know if a page is used by the application, you simply have to use your application size to calculate which pages are used. In addition, the bond manager and possibly the error handler also writes to flash, so you should avoid those pages as well. If a flash address contains only 0xFFs, this normally indicates that it is not written. You can inspect any address using either J-Link Commander, nrfjprog or Keil&amp;#39;s debugger.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to handle flashwrit in an safe way.</title><link>https://devzone.nordicsemi.com/thread/2875?ContentTypeID=1</link><pubDate>Wed, 02 Oct 2013 12:40:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3d1844d7-a860-45bb-a0e4-7d327fb53ff6</guid><dc:creator>Nils Minor</dc:creator><description>&lt;p&gt;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?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to handle flashwrit in an safe way.</title><link>https://devzone.nordicsemi.com/thread/2879?ContentTypeID=1</link><pubDate>Wed, 02 Oct 2013 12:02:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:52f69bf8-c95a-4aa8-899c-52e0497b4186</guid><dc:creator>Nils Minor</dc:creator><description>&lt;p&gt;Hi Ole,&lt;/p&gt;
&lt;p&gt;ok i understand, but in my case i don&amp;#39;t need the softdevice so i write to the flash when the softdevie is not needed, so how can i stop the softdevice?&lt;/p&gt;
&lt;p&gt;In the exampkle of the sdk there is used this:
pg_size = NRF_FICR-&amp;gt;CODEPAGESIZE;
pg_num = NRF_FICR-&amp;gt;CODESIZE - 1;    // Use last page in flash
// Start address:
addr = (uint32_t *)(pg_size * pg_num);
So is this safe for me, am i writing then in the flash area over my application and the softdevie?&lt;/p&gt;
&lt;p&gt;And in the Code the use &amp;quot;page_size&amp;quot; what is ment by this, i dont&amp;#39;t realy understand what they mean with pages in the flash, is there any Information about that?&lt;/p&gt;
&lt;p&gt;Thanks for your help :)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to handle flashwrit in an safe way.</title><link>https://devzone.nordicsemi.com/thread/2874?ContentTypeID=1</link><pubDate>Wed, 02 Oct 2013 11:51:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eff73cbe-b632-49f1-8b9a-6c53c077ccf1</guid><dc:creator>Ole Morten</dc:creator><description>&lt;p&gt;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&amp;#39;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.&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;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&amp;#39;d recommend you to do a few searches. Let me know if you have specific problems.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to handle flashwrit in an safe way.</title><link>https://devzone.nordicsemi.com/thread/2873?ContentTypeID=1</link><pubDate>Mon, 30 Sep 2013 16:53:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c1bc24e8-e6a1-4503-916e-a89f57bc48d0</guid><dc:creator>Marc Nicholas</dc:creator><description>&lt;p&gt;There are two banks for Flash. One bank (80KB) is set aside for the S110 Softdevice and the other is available for your consumption (app and as data storage).&lt;/p&gt;
&lt;p&gt;Yes, you have to the Flash in a Softdevice &amp;#39;friendly&amp;#39; manner. There&amp;#39;re some vague clues in the HRM app, if I recall correctly.&lt;/p&gt;
&lt;p&gt;-m&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>