<?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 page size</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/4040/pstorage-page-size</link><description>I try to optmize my code so it can run on the 128k chip.
My issue is with pstorage: I have 7 variables (from 4 bytes to 20 bytes) that I store in individual blocks. But it seems that on a page, there is only one block ? So for each block, I need PSTORAGE_FLASH_PAGE_SIZE</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 14 Jan 2015 11:35:08 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/4040/pstorage-page-size" /><item><title>RE: pstorage page size</title><link>https://devzone.nordicsemi.com/thread/14497?ContentTypeID=1</link><pubDate>Wed, 14 Jan 2015 11:35:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2d57f758-c5a3-4fc8-a64b-358dc3abf2b8</guid><dc:creator>Petter Myhre</dc:creator><description>&lt;p&gt;Please add this as a new question and link to this one if it is relevant.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage page size</title><link>https://devzone.nordicsemi.com/thread/14496?ContentTypeID=1</link><pubDate>Wed, 14 Jan 2015 11:25:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:36cf9fa9-89d6-4318-aa01-861008bd0564</guid><dc:creator>Dibin</dc:creator><description>&lt;p&gt;Hi ,
Can I register for more than 1 page size ??, say i have block size of 16 and I need to reserver 2K memory. So I used count = 128. its returning a 07 error
Thanks &amp;amp; Regards,
DIbin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage page size</title><link>https://devzone.nordicsemi.com/thread/14495?ContentTypeID=1</link><pubDate>Fri, 10 Oct 2014 14:16:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:57c32236-a715-451a-b04a-f3dceeae56c1</guid><dc:creator>Petter Myhre</dc:creator><description>&lt;p&gt;&lt;code&gt;PSTORAGE_FLASH_PAGE_SIZE&lt;/code&gt; is the actual size of one page in flash, so you shouldn&amp;#39;t change that.&lt;/p&gt;
&lt;p&gt;You should be able to use a single flash page for this.&lt;/p&gt;
&lt;p&gt;It is recommended that the block size is a multiple of the flash word size (4B), so if your largest variable is 20B(5*4B), you can use that as block size. It is also recommended that the block size is a divisor of the flash page size (1024B), that flash page size % block size = 0. This doesn&amp;#39;t matter if you use less than 1 page of flash.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m assuming you are developing on one of our S110 BLE projects. Have you increased &lt;code&gt;PSTORAGE_MAX_APPLICATIONS&lt;/code&gt; to 2? Your application + the device manager. This also increases the number of flash pages available to pstorage to 2 (actually 3, if you include the swap page). One for your application, one for the device manager.&lt;/p&gt;
&lt;p&gt;Some variables:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static pstorage_handle_t        m_store_variables_base_handle;
static pstorage_handle_t        m_store_variables_curr_handle;
static int block_number = 0;
static uint8_t block0[4]  __attribute__((aligned(4)));
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You must register your application in the pstorage module with something like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static void store_variables_init(void)
{
    uint32_t err_code;
    
    pstorage_module_param_t param;

    param.block_size  = 20;
    param.block_count = 7;
    param.cb          = store_variables_cb_handler;

    err_code = pstorage_register(&amp;amp;param, &amp;amp;m_store_variables_base_handle);
    APP_ERROR_CHECK(err_code);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You must define the pstorage event handler for your application:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static void store_variables_cb_handler(
                                pstorage_handle_t  * handle,
                                uint8_t              op_code,
                                uint32_t             result,
                                uint8_t            * p_data,
                                uint32_t             data_len)
{
    switch(op_code)
    {
        case PSTORAGE_STORE_OP_CODE:
           if (result == NRF_SUCCESS)
           {
              rdy_for_next = true; // Ready for next store operation
           }
           else
           {
               // Store operation failed. This must be handled
           }
           break;       
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;rdy_for_next is a flag that is checked in the main loop:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// Enter main loop.
for (;;)
{
    if(rdy_for_next)
    {
        store_next_block();
    }
    err_code = sd_app_evt_wait();
    APP_ERROR_CHECK(err_code);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The store_next_block() can look like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static void store_next_block(void)
{
    rdy_for_next = false;
    uint32_t err_code;

    err_code = pstorage_block_identifier_get(&amp;amp;m_store_variables_base_handle, block_number, &amp;amp;m_store_variables_curr_handle);
    APP_ERROR_CHECK(err_code);
    err_code = pstorage_store(&amp;amp;m_store_variables_curr_handle, block0, 4,0);
    APP_ERROR_CHECK(err_code);
    block_number++;            
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This should get you started, please add a comment if anything is unclear or if anything requires a better explanation.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage page size</title><link>https://devzone.nordicsemi.com/thread/14494?ContentTypeID=1</link><pubDate>Fri, 10 Oct 2014 14:00:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a875134c-a9d2-4dab-94c2-e470953fe495</guid><dc:creator>ben38</dc:creator><description>&lt;p&gt;Thanks, some of my variables were in differents services. But I could probably refactor my code to use a single page.&lt;/p&gt;
&lt;p&gt;A quick look at pstorage.c (where PSTORAGE_FLASH_PAGE_SIZE is used) doesn&amp;#39;t indicate to me that it&amp;#39;s a bad idea to change it... So there is probably something that I don&amp;#39;t understand ? Can you explain me what is the problem ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage page size</title><link>https://devzone.nordicsemi.com/thread/14493?ContentTypeID=1</link><pubDate>Fri, 10 Oct 2014 13:09:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c9ffb947-145b-419e-9f6f-bc5442f987ee</guid><dc:creator>John</dc:creator><description>&lt;p&gt;I am not a pstorage expert, but a quick look at how PSTORAGE_FLASH_PAGE_SIZE is used indicates changing it to something other than PSTORAGE_FLASH_PAGE_SIZE would result in some odd behaviors.&lt;/p&gt;
&lt;p&gt;Why not just call pstorage_register once with the block count set to 7 and the block size set to 20? This should give you a single flash page with 7 blocks of 20 bytes to store your data.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>