<?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>Flash initialization in custom section</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/39594/flash-initialization-in-custom-section</link><description>Hi, 
 
 I am developing on a nRF52832 with S132 softdevice using Segger and SDK15.2.0. I am doing some tests with the Flash memory, and my goal is to have some const variables that point to a specific flash section, so they can be changed afterwards using</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 19 Oct 2018 09:10:03 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/39594/flash-initialization-in-custom-section" /><item><title>RE: Flash initialization in custom section</title><link>https://devzone.nordicsemi.com/thread/153596?ContentTypeID=1</link><pubDate>Fri, 19 Oct 2018 09:10:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7af766be-ffee-4770-ad55-6008caaf32a9</guid><dc:creator>halls</dc:creator><description>&lt;p&gt;Hi Andreas,&lt;/p&gt;
&lt;p&gt;This is in fact what I was already using. With this, the best I see I can do is just check if the flash page has been already been used, and if not, write some default data in it. But with this solution I get &amp;quot;double&amp;quot; data in flash, the default one (initializing the variables in the code) and the one that the user updates the specific flash section with.&lt;/p&gt;
&lt;p&gt;So still, not solving my problem of initializing flash from the beginning.&lt;/p&gt;
&lt;p&gt;However, I see I will have to stick to that for the moment...&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks anyway!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash initialization in custom section</title><link>https://devzone.nordicsemi.com/thread/153580?ContentTypeID=1</link><pubDate>Fri, 19 Oct 2018 08:19:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fdb11b10-3a09-491d-9b11-4c608e21062d</guid><dc:creator>AndreasF</dc:creator><description>&lt;p&gt;Hi Imanol.&lt;/p&gt;
&lt;p&gt;You can use the &lt;strong&gt;&lt;a href="http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.s140.api.v6.1.0%2Fgroup___n_r_f___s_o_c___f_u_n_c_t_i_o_n_s.html&amp;amp;anchor=gae5361e65cbb5e7f6e258947a394c9b55"&gt;sd_flash_write()&lt;/a&gt;&lt;/strong&gt; API.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;uint32_t sd_flash_write 	( 	uint32_t *  	p_dst,
		uint32_t const *  	p_src,
		uint32_t  	size 
	) 		

Flash Write.

Commands to write a buffer to flash

If the SoftDevice is enabled: This call initiates the flash access command, and its completion will be communicated to the application with exactly one of the following events:

    NRF_EVT_FLASH_OPERATION_SUCCESS - The command was successfully completed.
    NRF_EVT_FLASH_OPERATION_ERROR - The command could not be started.

If the SoftDevice is not enabled no event will be generated, and this call will return NRF_SUCCESS when the write has been completed

Note

        This call takes control over the radio and the CPU during flash erase and write to make sure that they will not interfere with the flash access. This means that all interrupts will be blocked for a predictable time (depending on the NVMC specification in the device&amp;#39;s Product Specification and the command parameters).
        The data in the p_src buffer should not be modified before the NRF_EVT_FLASH_OPERATION_SUCCESS or the NRF_EVT_FLASH_OPERATION_ERROR have been received if the SoftDevice is enabled.
        This call will make the SoftDevice trigger a hardfault when the page is written, if it is protected.

Parameters
    [in]	p_dst	Pointer to start of flash location to be written.
    [in]	p_src	Pointer to buffer with data to be written.
    [in]	size	Number of 32-bit words to write. Maximum size is the number of words in one flash page. See the device&amp;#39;s Product Specification for details.

Return values
    NRF_ERROR_INVALID_ADDR	Tried to write to a non existing flash address, or p_dst or p_src was unaligned.
    NRF_ERROR_BUSY	The previous command has not yet completed.
    NRF_ERROR_INVALID_LENGTH	Size was 0, or higher than the maximum allowed size.
    NRF_ERROR_FORBIDDEN	Tried to write to an address outside the application flash area.
    NRF_SUCCESS	The command was accepted. &lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;You could also take a look at the &lt;strong&gt;examples\peripheral\flash_fstorage &lt;/strong&gt;example, which uses the &lt;a href="http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v15.2.0%2Fgroup__nrf__fstorage.html&amp;amp;anchor=ga5a37147f85e54eb049d3cad8bf59c807"&gt;&lt;strong&gt;nrf_fstorage_write()&lt;/strong&gt;&lt;/a&gt; API.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;pre class="ui-code" data-mode="text"&gt;ret_code_t nrf_fstorage_write 	( 	nrf_fstorage_t const *  	p_fs,
		uint32_t  	dest,
		void const *  	p_src,
		uint32_t  	len,
		void *  	p_param 
	) 		

Function for writing data to flash.

Write len bytes from p_src to dest.

When using SoftDevice implementation, the data is written by several calls to sd_flash_write if the length of the data exceeds NRF_FSTORAGE_SD_MAX_WRITE_SIZE bytes. Only one event is sent upon completion.

Note
    The data to be written to flash must be kept in memory until the operation has terminated and an event is received.

Parameters
    [in]	p_fs	The fstorage instance.
    [in]	dest	Address in flash memory where to write the data.
    [in]	p_src	Data to be written.
    [in]	len	Length of the data (in bytes).
    [in]	p_param	User-defined parameter passed to the event handler (may be NULL).

Return values
    NRF_SUCCESS	If the operation was accepted.
    NRF_ERROR_NULL	If p_fs or p_src is NULL.
    NRF_ERROR_INVALID_STATE	If the module is not initialized.
    NRF_ERROR_INVALID_LENGTH	If len is zero or not a multiple of the program unit, or if it is otherwise invalid.
    NRF_ERROR_INVALID_ADDR	If the address dest is outside the flash memory boundaries specified in p_fs, or if it is unaligned.
    NRF_ERROR_NO_MEM	If no memory is available to accept the operation. When using the SoftDevice implementation, this error indicates that the internal queue of operations is full. &lt;/pre&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Hope this helps.&lt;/p&gt;
&lt;p&gt;- Andreas&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash initialization in custom section</title><link>https://devzone.nordicsemi.com/thread/153533?ContentTypeID=1</link><pubDate>Thu, 18 Oct 2018 20:24:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7e4e5b67-324b-44d8-bc39-f2c58cad38d8</guid><dc:creator>halls</dc:creator><description>&lt;p&gt;Thanks for your answer Andreas. I already have tried the nrfjprog. My goal was to have the flash initialized when programming the hex file, not having to do an additional step with the nrfjprog.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash initialization in custom section</title><link>https://devzone.nordicsemi.com/thread/153446?ContentTypeID=1</link><pubDate>Thu, 18 Oct 2018 10:53:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3ced3266-f891-4712-bb1b-b8814ebb50a5</guid><dc:creator>AndreasF</dc:creator><description>&lt;p&gt;Hi Imanol.&lt;/p&gt;
&lt;p&gt;You cannot use attributes to write in flash locations, you can only write in RAM locations using attributes.&lt;/p&gt;
&lt;p&gt;But you can write to the flash in nrfjprog using for example: &amp;nbsp;&lt;strong&gt;nrfjprog.exe --memwr 0x7f000 --val 0x55&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;You could take a look at the &lt;a href="http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v15.2.0%2Fgroup__nrf__nvmc.html&amp;amp;resultof=%22%6e%76%6d%63%22%20"&gt;NVMC API &lt;/a&gt;as well.&lt;/p&gt;
&lt;p&gt;- Andreas&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>