<?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>Smallest Flash-write operation possible and what is to consider when using BLE and Flash at the same time?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/30800/smallest-flash-write-operation-possible-and-what-is-to-consider-when-using-ble-and-flash-at-the-same-time</link><description>I&amp;#39;m developing for the NRF52 DK (nRF52832) using VisualGDB (which uses SDK v11.0.0). 
 When completed my program is supposed to read data from sensor (via I2C), store it in the internal flash and if enough data is accumulated send it to a phone via BLE</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 29 Mar 2018 12:34:37 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/30800/smallest-flash-write-operation-possible-and-what-is-to-consider-when-using-ble-and-flash-at-the-same-time" /><item><title>RE: Smallest Flash-write operation possible and what is to consider when using BLE and Flash at the same time?</title><link>https://devzone.nordicsemi.com/thread/126400?ContentTypeID=1</link><pubDate>Thu, 29 Mar 2018 12:34:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:73016c1c-7968-4f39-9add-1d78049dccd5</guid><dc:creator>AlexanderGrath</dc:creator><description>&lt;p&gt;The sd_flash_write function does not keep the data pointer alive, the variable needs to be static. Now it does work fine.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Smallest Flash-write operation possible and what is to consider when using BLE and Flash at the same time?</title><link>https://devzone.nordicsemi.com/thread/126389?ContentTypeID=1</link><pubDate>Thu, 29 Mar 2018 10:14:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:61a884b4-8dd8-4565-8142-0331e1db30dc</guid><dc:creator>AlexanderGrath</dc:creator><description>&lt;p&gt;Edit: Figured it out read reply below if anybody has the same problem.&lt;/p&gt;
&lt;p&gt;After further testing it seems that the sd_flash.. calls do not work while the SoftDevice is running.&lt;br /&gt;I&amp;#39;m using them in my program and as soon as I start using BLE it completely stops working.&amp;nbsp;&lt;br /&gt;There is an event Queue running, everything else works fine (I2C communication etc). If I disable the BLE initialization the write functions work fine, if it is enabled again it stops working.&amp;nbsp;&lt;br /&gt;The program does not crash, the write functions simply write wrong values like if it is supposed to write 0xFFFF47C it reads 0x2000FF80. The write functions are getting called with eventQueue-&amp;gt;call(&amp;lt;function&amp;gt;); Am I supposed to do it differently?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Smallest Flash-write operation possible and what is to consider when using BLE and Flash at the same time?</title><link>https://devzone.nordicsemi.com/thread/122629?ContentTypeID=1</link><pubDate>Fri, 02 Mar 2018 14:37:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a9817d9b-6cb3-4adf-b4fb-1f54db014e01</guid><dc:creator>AlexanderGrath</dc:creator><description>&lt;p&gt;Thank you very much for your reply,&lt;/p&gt;
&lt;p&gt;the limitation of 181 writing operations is really valuable information. I switched over to using a buffer for my data. It&amp;#39;s not a lot of information, without doing that I would have run out of writing operations before filling a block.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In terms of BLE &amp;amp; Flash I switched over to using the &amp;quot;sd_flash...&amp;quot; functions.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Smallest Flash-write operation possible and what is to consider when using BLE and Flash at the same time?</title><link>https://devzone.nordicsemi.com/thread/122140?ContentTypeID=1</link><pubDate>Tue, 27 Feb 2018 13:41:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:705a8286-7156-413a-961d-2e761f556733</guid><dc:creator>Rune Holmgren</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;First I want to give you my&amp;nbsp;general advice&amp;nbsp;which is what I would do if I understand your system correctly: Use a small buffer to receive 4 bytes of data before writing to flash 32 bit at a time.&lt;/p&gt;
[quote user=""]Is it possible to write less than 4 Bytes to the flash at one time?[/quote]
&lt;p&gt;Yes, you can write 1 byte at a time by setting all bits you do not want to affect to &amp;#39;1&amp;#39;. Write operations are only flipping &amp;#39;1&amp;#39; bits to &amp;#39;0&amp;#39; when you perform a write operation.&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " height="38" src="https://devzone.nordicsemi.com/resized-image/__size/1040x51/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-b5b765fbec824e17be4086e979d83ae5/Capture.PNG" width="841" /&gt;&lt;/p&gt;
&lt;p&gt;But there are limitations to this. You may only write 181 times to each block. A block is 1/8th of a flash page (512 byte or 128 words).&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-b5b765fbec824e17be4086e979d83ae5/pastedimage1519736397934v2.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-b5b765fbec824e17be4086e979d83ae5/pastedimage1519736323201v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;This essentially means that you can write 1 byte at a time, but then you can only write to the first 181 bytes of the 512 bytes in the flash page. Based on the fact that you are worried about flash lifetime this sounds like a bad solution for you.&lt;/p&gt;
[quote user=""]One thing that does worry me about this is &lt;em&gt;wear&lt;/em&gt;. According to the&amp;nbsp;&lt;a href="http://infocenter.nordicsemi.com/pdf/nRF52832_PS_v1.1.pdf" rel="noopener noreferrer" target="_blank"&gt;Absolute Maximum Ratings&lt;/a&gt;&amp;nbsp;10000 write /erase cycles are possible; would writing the same data over and over again wear down the flash?[/quote]
&lt;p&gt;The first thing I want to say about this topic is that 10000 cycles is an absolute maximum rating which is really just a worst case for chips operating in extreme environments.&amp;nbsp;This number applies to chips operating with a heavy load in extreme environments with parameters like temperature swinging between&amp;nbsp; -40°C and 85°C. A chip&amp;nbsp;operating at room temperature most of the time with a normal workload will typically hold at least 50000 cycles. (This is not an official guaranteed&amp;nbsp;rating from Nordic Semiconductor, but rather a number observed by testing.)&lt;/p&gt;
&lt;p&gt;The rating is for full cycles of writing to and then erasing the flash. You are capped by the 181 write limit, so as long as you keep within this limitation you should be doing fine. I can&amp;#39;t find any data available on the impact of writing compared to the impact of erasing.&lt;/p&gt;
[quote user=""]What is to be considered when using BLE and Flash-operations?[/quote]
&lt;p&gt;It&amp;#39;s not a problem performing flash operations while the SoftDevice is enabled, but you have to send the flash operations to the SoftDevice and not directly to the hardware. The SoftDevice has a series of API calls &amp;quot;sd_flash... &amp;quot; which allow you to use the flash. When you use these API calls the SoftDevice will queue the operation, find a timeslot in between the&amp;nbsp;scheduled radio operations and send you an event when it&amp;#39;s done.&lt;/p&gt;
[quote user=""]Function used to read from flash:[/quote]
&lt;p&gt;This code is fine I, but you don&amp;#39;t really need it. You can read data directly from flash without this function.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Rune Holmgren&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>