<?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>pstorage reading other values than writing</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/3588/pstorage-reading-other-values-than-writing</link><description>Hi! 
 Maybe I&amp;#39;m doing something wrong (very possible), but for example, when I want to store array of 3 uint8_t values I use: 
 uint8_t dataToStore[3];
dataToStore[0] = 11;
dataToStore[1] = 22;
dataToStore[2] = 33;

retval = pstorage_store(&amp;amp;block_handle</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 04 Mar 2015 15:34:05 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/3588/pstorage-reading-other-values-than-writing" /><item><title>RE: pstorage reading other values than writing</title><link>https://devzone.nordicsemi.com/thread/13018?ContentTypeID=1</link><pubDate>Wed, 04 Mar 2015 15:34:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:11099a39-d7b9-42f0-ae1a-02b0cfc13d1f</guid><dc:creator>frijj2k</dc:creator><description>&lt;p&gt;Nikita - You&amp;#39;re a legend!&lt;/p&gt;
&lt;p&gt;I have been beating my head on the desk as to why the persistent storage wasn&amp;#39;t working and it was because the buffer needed to be word aligned in ram (which is not made clear in the SDK example).&lt;/p&gt;
&lt;p&gt;Thank you!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage reading other values than writing</title><link>https://devzone.nordicsemi.com/thread/13017?ContentTypeID=1</link><pubDate>Mon, 01 Dec 2014 18:34:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5acd11f1-3e83-4ea6-9e60-d671aac60519</guid><dc:creator>David Robins</dc:creator><description>&lt;p&gt;As I noted in &lt;a href="https://devzone.nordicsemi.com/question/21903/what-does-pstorage_load_op_code-mean/#21909"&gt;this answer&lt;/a&gt;, while &lt;code&gt;pstorage_store&lt;/code&gt; operations are queued, &lt;code&gt;pstorage_load&lt;/code&gt; are not; they are implemented as an immediate &lt;code&gt;memcpy&lt;/code&gt;. So it&amp;#39;s possible to read memory before the write has completed if you don&amp;#39;t wait for the callback notification.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage reading other values than writing</title><link>https://devzone.nordicsemi.com/thread/13014?ContentTypeID=1</link><pubDate>Mon, 15 Sep 2014 22:17:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9dedc578-7ce0-4d08-ae48-ecb65730379b</guid><dc:creator>Nikita</dc:creator><description>&lt;p&gt;You shouldn&amp;#39;t declare variables in headers and don&amp;#39;t use static. Declare them in one of your *.c file as:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;pstorage_handle_t persistant_memory_handle;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And in other *.c files as:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;extern pstorage_handle_t persistant_memory_handle;
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage reading other values than writing</title><link>https://devzone.nordicsemi.com/thread/13013?ContentTypeID=1</link><pubDate>Mon, 15 Sep 2014 09:20:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:448c0c1d-f108-482b-9ae4-69ee9519f8ab</guid><dc:creator>Patriko</dc:creator><description>&lt;p&gt;Now I recognized that the problem occurs only when the function pstorage_update is called from function declared in another file, so probably there is something wrong with data structure declaration.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve all variables associated with pstorage declared in &amp;quot;data_structure.h&amp;quot; included in both files.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;data_strtucture.h&lt;/strong&gt; contains:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;quot;pstorage.h&amp;quot;
static pstorage_handle_t persistant_memory_handle;
static uint32_t retval;
static pstorage_handle_t block_handle;

static uint8_t shutter_state[4] __attribute__((aligned(4)));

#define FULL_MOVE_UP_COUNT_EE_POS			0
#define FULL_MOVE_DOWN_COUNT_EE_POS		1
#define CURRENT_POSITION_EE_POS				2
#define DESIRED_POSITION_EE_POS				3
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So it should work from both files, shouldn&amp;#39;t it?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage reading other values than writing</title><link>https://devzone.nordicsemi.com/thread/13012?ContentTypeID=1</link><pubDate>Mon, 15 Sep 2014 08:43:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2b13a3e1-0fc2-48ac-b3c1-4cfe21fafff0</guid><dc:creator>Patriko</dc:creator><description>&lt;p&gt;Hi!&lt;/p&gt;
&lt;p&gt;That&amp;#39;s wired, but it works when I use it on before load_stored_data.
When I moved it (exactly that same function) to another part of program it stopped working.&lt;/p&gt;
&lt;p&gt;What can cause it?&lt;/p&gt;
&lt;p&gt;Thanks,
Patriko&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage reading other values than writing</title><link>https://devzone.nordicsemi.com/thread/13011?ContentTypeID=1</link><pubDate>Wed, 10 Sep 2014 21:17:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0fef607d-6db4-487b-9f91-d296c4d0eaa3</guid><dc:creator>Nikita</dc:creator><description>&lt;p&gt;What if you try to call pstorage_update() at the beginning in the main at initialization?  NRF_ERROR_INVALID_LENGTH error can only be returned from sd_flash_write() and I don&amp;#39;t know what can be the problem.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage reading other values than writing</title><link>https://devzone.nordicsemi.com/thread/13010?ContentTypeID=1</link><pubDate>Wed, 10 Sep 2014 16:50:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:90dcb984-0080-40b8-905c-1a425d2e0e3a</guid><dc:creator>Patriko</dc:creator><description>&lt;p&gt;Hi!&lt;/p&gt;
&lt;p&gt;After trying to use that same solution which worked before in another project, I discovered a problem with getting &lt;strong&gt;NRF_ERROR_INVALID_LENGTH&lt;/strong&gt; error code as a result of:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;retval = pstorage_update(&amp;amp;block_handle, shutter_state, 4 , 0);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;shutter_state is declared as:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static uint8_t shutter_state[4] __attribute__((aligned(4)));
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and initialized as:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;		shutter_state[FULL_MOVE_UP_COUNT_EE_POS] 	= s-&amp;gt;fullMoveUpCount;
	shutter_state[FULL_MOVE_DOWN_COUNT_EE_POS] = s-&amp;gt;fullMoveDownCount;
	shutter_state[CURRENT_POSITION_EE_POS] 		= s-&amp;gt;currentPosition;
	shutter_state[DESIRED_POSITION_EE_POS] 		= 0;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;What can cause that error?&lt;/p&gt;
&lt;p&gt;Thanks!:)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage reading other values than writing</title><link>https://devzone.nordicsemi.com/thread/13009?ContentTypeID=1</link><pubDate>Sun, 24 Aug 2014 18:57:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1b20f0f8-de55-44f0-a8ce-cdaa66732391</guid><dc:creator>Nikita</dc:creator><description>&lt;p&gt;I think that it&amp;#39;s just the description of capability of Persistent Storage Module interface, but for now SDK implementation is not supporting this functionality.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage reading other values than writing</title><link>https://devzone.nordicsemi.com/thread/13008?ContentTypeID=1</link><pubDate>Sun, 24 Aug 2014 18:49:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dbfdc867-9e61-47fe-8426-dcb1b30ef2c6</guid><dc:creator>leo</dc:creator><description>&lt;p&gt;Hm.. now i read it, thanks.. But what does the third point mean? &amp;quot;- When using the clear operation the Persistent Storage Manager will use a swap area to conserve the blocks not affected. The data page backed up in the swap area, the data page is erased, the non affected blocks are copied back.&amp;quot; So, it deletes the whole content, but it writes back the not affected blocks? Thanks a lot.. i was wondering why it didn&amp;#39;t work.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage reading other values than writing</title><link>https://devzone.nordicsemi.com/thread/13023?ContentTypeID=1</link><pubDate>Sun, 24 Aug 2014 18:06:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ae8110f4-45ef-4c82-a20a-f081086c37f6</guid><dc:creator>Patriko</dc:creator><description>&lt;p&gt;Thank you! It solved the problem :)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage reading other values than writing</title><link>https://devzone.nordicsemi.com/thread/13007?ContentTypeID=1</link><pubDate>Sun, 24 Aug 2014 17:32:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:efbc7cde-d481-4c3f-942a-8fac184a1929</guid><dc:creator>Nikita</dc:creator><description>&lt;p&gt;You need to clear all the allocated memory of module, read in the link above: Clear operation results in clearing all storage blocks allocated to the application. Clearing a single storage block or certain blocks is not implemented. The size parameter of pstorage_clear is currently unused, any value provided will not have any impact on the behaviour of this API.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage reading other values than writing</title><link>https://devzone.nordicsemi.com/thread/13006?ContentTypeID=1</link><pubDate>Sun, 24 Aug 2014 17:29:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f5f2beb9-ee84-43ca-950f-523de66e1662</guid><dc:creator>leo</dc:creator><description>&lt;p&gt;Thanks for clarification. Just a (hopefully) last question. If i want to store block 1 of module a, i have to clear block 1, and then i can store block 1 again. Or do i really have to clear the whole allocated memory of module a?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage reading other values than writing</title><link>https://devzone.nordicsemi.com/thread/13005?ContentTypeID=1</link><pubDate>Sun, 24 Aug 2014 17:12:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:282c02f8-4848-438a-8c73-e8cf31f52a89</guid><dc:creator>Nikita</dc:creator><description>&lt;ol start="3"&gt;
&lt;li&gt;pstorage_update function can be called on clear place. In case on pstorage_update it&amp;#39;s the same what I described in (2.) , but you don&amp;#39;t need to temporary store your data in buffer before clearing manually, it&amp;#39;ll be done inside pstorage_update operation.&lt;/li&gt;
&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage reading other values than writing</title><link>https://devzone.nordicsemi.com/thread/13004?ContentTypeID=1</link><pubDate>Sun, 24 Aug 2014 17:12:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bc597e2c-b052-472b-8f79-080127b9ca70</guid><dc:creator>Nikita</dc:creator><description>&lt;ol&gt;
&lt;li&gt;It is possible to store data with pstorage_store if the place where you want to write is cleared (content 0xFFFFFFFF), you can perform multiple pstorage_store to store your data in different places inside your registered pstorage module, but only once each. If you want to rewrite some values you need to clear all module allocated flash memory with pstorage_clear before you can write new value with pstorage_store. 2. pstorage_clear function can only clear all storage block in allocated module, you can&amp;#39;t just clear some of them at a time, so if you want to have database then before rewriting some data in some block you need first to get all data in blocks in buffer, then perform pstorage_clear and then write back buffer with changed values with pstorage_store.&lt;/li&gt;
&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage reading other values than writing</title><link>https://devzone.nordicsemi.com/thread/13003?ContentTypeID=1</link><pubDate>Sun, 24 Aug 2014 16:58:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9686d485-5af3-4a19-9bda-cd7f52254680</guid><dc:creator>leo</dc:creator><description>&lt;p&gt;Thanks nikita for your fast response. So if i want to implement a &amp;quot;small database&amp;quot; to save small blocks of data, i have to clear always the blocks before storing it, or just update a block? Thus just &amp;quot;overwriting&amp;quot; a block is just possible with update and not with store? (But can i update a block which is clear?)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage reading other values than writing</title><link>https://devzone.nordicsemi.com/thread/13002?ContentTypeID=1</link><pubDate>Sun, 24 Aug 2014 16:51:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c313ab15-c9e7-4fe7-aff6-e6d709416ab8</guid><dc:creator>Nikita</dc:creator><description>&lt;p&gt;You can read it here: &lt;a href="https://devzone.nordicsemi.com/documentation/nrf51/6.0.0/s110/html/a00018.html"&gt;devzone.nordicsemi.com/.../a00018.html&lt;/a&gt; In short pstorage_store is to write data only in previously cleared place in flash, but pstorage_update can update only part of the data in all allocated flash memory, it&amp;#39;s reading all content of this memory in buffer, then updates needed data in bufer with new values, then clears all allocated flash memory and store all bufer data to the flash.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage reading other values than writing</title><link>https://devzone.nordicsemi.com/thread/13001?ContentTypeID=1</link><pubDate>Sun, 24 Aug 2014 16:44:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9c605aba-66ab-4ee9-bfb0-4dc9c85dae5d</guid><dc:creator>leo</dc:creator><description>&lt;p&gt;Hi nikita, could you explain please, whats the difference between calling &amp;quot;pstorage_store&amp;quot; and &amp;quot;pstorage_update&amp;quot; on a already used block?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage reading other values than writing</title><link>https://devzone.nordicsemi.com/thread/13022?ContentTypeID=1</link><pubDate>Sun, 24 Aug 2014 11:48:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:712fca6d-1368-47d8-94e6-5a84083096cc</guid><dc:creator>Nikita</dc:creator><description>&lt;p&gt;I think using pstorage_update is better in your case.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage reading other values than writing</title><link>https://devzone.nordicsemi.com/thread/13000?ContentTypeID=1</link><pubDate>Sun, 24 Aug 2014 11:33:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b228562d-5f71-4c5b-8e58-00b7f20840cd</guid><dc:creator>Patriko</dc:creator><description>&lt;p&gt;Ok, so I should perform pstorage_clear(&amp;amp;base_handle, 16) before writing?
But now I assume that pstorage_write should be placed in event handler (I should also store somewhere identifier of &amp;quot;write position&amp;quot;, to support multiple variables storage) or can I put it in if(retval == NRF_SUCCESS) { } clause?&lt;/p&gt;
&lt;p&gt;Or maybe using pstorage_update should solve this problem?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage reading other values than writing</title><link>https://devzone.nordicsemi.com/thread/12999?ContentTypeID=1</link><pubDate>Sun, 24 Aug 2014 11:29:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bc52e329-7909-4e67-a6a2-f287154dd5e1</guid><dc:creator>Patriko</dc:creator><description>&lt;p&gt;It was called before (app starts from reading values, store is performed only when configuration is changed), but now I added it directly before:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;	retval = pstorage_block_identifier_get(&amp;amp;persistant_memory_handle, 0, &amp;amp;block_handle);
	if (retval == NRF_SUCCESS)
	{
		retval = pstorage_store(&amp;amp;block_handle, receivedData, 4 , 0);
		if (retval == NRF_SUCCESS)
		{
				// Store successfully requested. Wait for operation result.
		}
		else
		{
				// Failed to request store, take corrective action.
		}
	}
	else
	{
			// Failed to get block id, take corrective action.
	}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;but still read value is 0x00,0x00,0x00,0x00&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage reading other values than writing</title><link>https://devzone.nordicsemi.com/thread/13021?ContentTypeID=1</link><pubDate>Sun, 24 Aug 2014 11:28:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:699c073e-6a90-4049-a893-a23268056e0d</guid><dc:creator>Nikita</dc:creator><description>&lt;p&gt;Oh, yeah, you need to clear your allocated memory with pstorage_clear before you can store your data in it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage reading other values than writing</title><link>https://devzone.nordicsemi.com/thread/12998?ContentTypeID=1</link><pubDate>Sun, 24 Aug 2014 11:14:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7e148d92-71ac-488f-80dc-ed39af029453</guid><dc:creator>Nikita</dc:creator><description>&lt;p&gt;You need to call pstorage_block_identifier_get before calling pstorage_store.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage reading other values than writing</title><link>https://devzone.nordicsemi.com/thread/13020?ContentTypeID=1</link><pubDate>Sun, 24 Aug 2014 11:07:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1d76844c-f350-480b-871a-a7705c9acc11</guid><dc:creator>Patriko</dc:creator><description>&lt;p&gt;I&amp;#39;d updated previous post with a full code, please take a look. Thank you!:)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage reading other values than writing</title><link>https://devzone.nordicsemi.com/thread/13019?ContentTypeID=1</link><pubDate>Sun, 24 Aug 2014 10:58:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e64b3d1d-a06d-42af-ba1a-0d8400fe3a88</guid><dc:creator>Nikita</dc:creator><description>&lt;p&gt;Show your full test code with pstorage_register and where and how you calling pstorage_store.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage reading other values than writing</title><link>https://devzone.nordicsemi.com/thread/13016?ContentTypeID=1</link><pubDate>Sun, 24 Aug 2014 10:49:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f3fa3a69-b236-4d8a-8435-5f17dc91d60a</guid><dc:creator>Patriko</dc:creator><description>&lt;p&gt;Thanks!&lt;/p&gt;
&lt;p&gt;Now it reach the end of pstorage_store() function (cmd_queue_enqueue), and retval is equal NRF_SUCCESS, but when trying to read value, is 0x00, 0x00, 0x00, 0x00 :(&lt;/p&gt;
&lt;p&gt;And Event Notification Handler (static void storage_cb_handler), is not fired when writing (it fires when using pstorage_load, so I assume that reference is correct).&lt;/p&gt;
&lt;p&gt;:(&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>