<?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>read write operation from flash memory nrf52840</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/106162/read-write-operation-from-flash-memory-nrf52840</link><description>I want to perform read and write operation from flash memory in nrf52840 through below api&amp;#39;s 
 uint32_t flash_address = 0x0003D1E0; 
 sd_flash_write((uint32_t *)flash_address, data_to_write, 1); write operation 
 memcpy(&amp;amp;data_to_read, (uint32_t *)flash_address</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 29 Nov 2023 12:49:32 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/106162/read-write-operation-from-flash-memory-nrf52840" /><item><title>RE: read write operation from flash memory nrf52840</title><link>https://devzone.nordicsemi.com/thread/458095?ContentTypeID=1</link><pubDate>Wed, 29 Nov 2023 12:49:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e29f656d-d134-4cc0-b66a-142843ef3d92</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user=""]1. Is there any API to do for flash read operation.[/quote]
&lt;p&gt;No, there is no SoftDevice API to read flash. Write and erase operations will halt the CPU when the operation is completed, so the APIs are provided to allow the Softdevice to schedule the operations between other tasks. Read operations can be done at any time without halting the CPU, and therefore does not need a special API.&lt;/p&gt;
[quote user=""]2. when I try to write using the write operation command it fails.[/quote]
&lt;p&gt;Can you elaborate how it fails? Do the API return any errors, are the new value not written correctly, etc?&lt;/p&gt;
[quote user=""]3. which location should i used for storing some data in flash currently using&amp;nbsp;0x0003D1E0 this location.[/quote]
&lt;p&gt;You can use any location that does not overlap with the application code or other static flash content. The address also needs to be erased before it can be written. The answer to this question depends on your application. You can see the size of the application in the build logs or similar. You can also read out the full flash content using nrfjprog or nRF Connect Programmer application to see which address ranges are occupied.&lt;/p&gt;
[quote user=""]&lt;p&gt;4. There are multiple API&amp;#39;s for flash operation which one should i prefer.&lt;/p&gt;
&lt;p&gt;nrf_fstorage_write,&lt;/p&gt;
&lt;p&gt;fds_record_write,&lt;/p&gt;
&lt;p&gt;&lt;span&gt;sd_flash_write&lt;/span&gt;&lt;/p&gt;[/quote]
&lt;p&gt;Again, this depends on your application needs. If a Softdevice is enabled, the SoftDevice API must be used to perform write/erase operations. Further, &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/lib_fstorage.html"&gt;fstorage&lt;/a&gt; is one abstraction layer above this, and provides backends for both SoftDevice (which uses the SoftDevice APIs) and NVMC backend that access the NVMC peripheral directly. &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/lib_fds.html"&gt;FDS&lt;/a&gt; is one abstraction layer above this again, and uses fstorage in the lower layers for flash writes. FDS provides additional functionality, like minimalistic file system, basic wear leveling, etc.&lt;/p&gt;
&lt;p&gt;If you are planning to update the value stored in flash at a regular interval, I would highly recommend using FDS. If using SD API directly, you either need to erase the full flash page between each write operation, or keep track of the current next free address where flash is erased.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Jørgen&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>