<?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>could anybody give an example that pstorage works?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/3468/could-anybody-give-an-example-that-pstorage-works</link><description>[environment: s110_nRF51822_7.0.0 + SDK nrf51_sdk_v6_0_0_43681 + PCA10000(QF AAG0)] 
 I failed to get pstorage working in my own code, then I picked up the sample code from DEV Zone and tried to test with two simple functions, I still failed to get it</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 14 Aug 2014 05:09:07 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/3468/could-anybody-give-an-example-that-pstorage-works" /><item><title>RE: could anybody give an example that pstorage works?</title><link>https://devzone.nordicsemi.com/thread/12546?ContentTypeID=1</link><pubDate>Thu, 14 Aug 2014 05:09:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e0dca642-e43e-4bf3-b6e3-4f3979deb453</guid><dc:creator>frank zhang</dc:creator><description>&lt;p&gt;the problem is solved, please close this question.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: could anybody give an example that pstorage works?</title><link>https://devzone.nordicsemi.com/thread/12545?ContentTypeID=1</link><pubDate>Thu, 14 Aug 2014 04:11:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:71ef79a0-6b12-46a9-a600-1757b52c3bb6</guid><dc:creator>frank zhang</dc:creator><description>&lt;p&gt;The code failed to pass &amp;quot;is_word_aligned&amp;quot; check in pstorage_store function, and after I changed the p_src parameter, pstorage_store and pstorage_load worked in the testing code.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: could anybody give an example that pstorage works?</title><link>https://devzone.nordicsemi.com/thread/12544?ContentTypeID=1</link><pubDate>Thu, 14 Aug 2014 01:35:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6ddc7a00-cf7b-430a-b152-c02a1b5efb49</guid><dc:creator>frank zhang</dc:creator><description>&lt;p&gt;ps: I tested it on QF AAC0 and QF AAG0, both failed.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: could anybody give an example that pstorage works?</title><link>https://devzone.nordicsemi.com/thread/12543?ContentTypeID=1</link><pubDate>Thu, 14 Aug 2014 01:24:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7f016cd2-70b3-4483-bb8e-eb80fbc47208</guid><dc:creator>frank zhang</dc:creator><description>&lt;p&gt;I took all the advices and changed my code, but still failed to get pstorage working. I added the main part of my code below, and what I can tell is the pstorage_clear signal can be received, which means the event handler is set properly;  the code just stuck at the line while(ps_flag == 0); after I called pstorage_store, it means there are no interrupts for pstorage_store. Can anybody help to tell how to make pstorage_store working?&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;/**===============test code========================*/

static uint8_t test_data[4] = {0x01,0x02,0x03,0x04};
static uint8_t ps_flag = 0;

static void sys_evt_dispatch(uint32_t sys_evt)
{
    pstorage_sys_event_handler(sys_evt);
}

static void ble_stack_init(void)
{    
    SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, false);
    uint32_t err_code;
    ble_enable_params_t ble_enable_params;
    memset(&amp;amp;ble_enable_params, 0, sizeof(ble_enable_params));
    ble_enable_params.gatts_enable_params.service_changed = IS_SRVC_CHANGED_CHARACT_PRESENT;
    err_code = sd_ble_enable(&amp;amp;ble_enable_params);
    APP_ERROR_CHECK(err_code);
    
    err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);
    APP_ERROR_CHECK(err_code);
}

static void dm_pstorage_cb_handler(pstorage_handle_t * p_handle,
                                   uint8_t             op_code,
                                   uint32_t            result,
                                   uint8_t           * p_data,
                                   uint32_t            data_len)
{
    switch(op_code)
    {
        case PSTORAGE_ERROR_OP_CODE:
                ps_flag = 1;
            break;
        case PSTORAGE_STORE_OP_CODE: 
                ps_flag = 2;           
            break;
        case PSTORAGE_LOAD_OP_CODE:
                ps_flag = 3;           
            break;
        case PSTORAGE_CLEAR_OP_CODE:
                ps_flag = 4;            
            break;
        case PSTORAGE_UPDATE_OP_CODE:
                ps_flag = 5;
            break;
        default:
                ps_flag = 6;
            break;
    }
}



static void pstorage_test(void)
{
    pstorage_module_param_t flashparam;
    pstorage_handle_t       flashhandle;
    pstorage_handle_t       flash_block_handle;
    
    uint32_t retval;
    
    flashparam.block_size  = 20;
    flashparam.block_count = 1;
    flashparam.cb          = dm_pstorage_cb_handler;
  
    retval = pstorage_init();   
    retval = pstorage_register(&amp;amp;flashparam, &amp;amp;flashhandle);   
    
    retval = pstorage_clear(&amp;amp;flashhandle, 20);  
    
    while(ps_flag == 0);
    ps_flag = 0;
   
    retval = pstorage_block_identifier_get(&amp;amp;flashhandle, 0, &amp;amp;flash_block_handle);      
    retval = pstorage_store(&amp;amp;flash_block_handle, test_data, 4, 0);
       
    while(ps_flag == 0);
    ps_flag = 0;    
   
    retval = pstorage_block_identifier_get(&amp;amp;flashhandle, 0, &amp;amp;flash_block_handle);
     
    uint8_t load_data[4];
    retval = pstorage_load(load_data, &amp;amp;flash_block_handle, 4, 0);
    
    while(ps_flag == 0);
    ps_flag = 0;
    
    if (retval == NRF_SUCCESS)
    {   
        if ((load_data[0] == 0x01)&amp;amp;(load_data[1] == 0x02)&amp;amp;(load_data[2] == 0x03)&amp;amp;(load_data[3] == 0x04))
        {
            ps_flag = 100;
        }
    }   
}

/**=============test code===================================*/
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: could anybody give an example that pstorage works?</title><link>https://devzone.nordicsemi.com/thread/12542?ContentTypeID=1</link><pubDate>Wed, 13 Aug 2014 12:53:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:27887b8d-3417-4030-98de-796df2a97e6e</guid><dc:creator>Nikita</dc:creator><description>&lt;p&gt;Pstorage operations will execute in interrupts.&lt;/p&gt;
&lt;p&gt;pstorage_sys_event_handler will be called from sys_evt_dispatch registered with softdevice handler module for SYS events softdevice_sys_evt_handler_set(sys_evt_dispatch).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: could anybody give an example that pstorage works?</title><link>https://devzone.nordicsemi.com/thread/12541?ContentTypeID=1</link><pubDate>Wed, 13 Aug 2014 12:06:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c297227f-4304-4e71-a240-f84a6a8aa679</guid><dc:creator>John</dc:creator><description>&lt;p&gt;The nrf_delay_us is a tight loop of NOP instructions. You can make it as long as you want, but it is not giving time to allow other processing to occur. You need to wait for the soft device to return an event indicating your pstorage_store command has completed.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: could anybody give an example that pstorage works?</title><link>https://devzone.nordicsemi.com/thread/12538?ContentTypeID=1</link><pubDate>Wed, 13 Aug 2014 11:12:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e06ee4b1-d1e7-4079-89c5-2b3d54ccb566</guid><dc:creator>Nikita</dc:creator><description>&lt;pre&gt;&lt;code&gt;flashparam.block_size  = 20;
flashparam.block_count = 1;
...
retval = pstorage_clear(&amp;amp;flashhandle,512*100);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Read &lt;a href="https://devzone.nordicsemi.com/documentation/nrf51/6.0.0/s110/html/a00018.html"&gt;this&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The size requested to be erased has to
be within or equal the size of a
block. If a size less than block size
is given, the API will clear the
requested number of bytes beginning at
the first memory location in the
block. It is not possible to request a
size which spans to the next block in
the module.&lt;/p&gt;
&lt;/blockquote&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: could anybody give an example that pstorage works?</title><link>https://devzone.nordicsemi.com/thread/12540?ContentTypeID=1</link><pubDate>Wed, 13 Aug 2014 09:53:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9ce04b38-df5c-4701-b3b4-0e25e6dd7472</guid><dc:creator>frank zhang</dc:creator><description>&lt;p&gt;Hi Alseth,
I set the break point at line &amp;quot;if ((load_data[0] == 0x01)&amp;amp;(load_data[1] == 0x02)&amp;amp;(load_data[2] == 0x03)&amp;amp;(load_data[3] == 0x04))&amp;quot; and I am sure test_data was available when pstorage_store get called, and the software should have time to save the data to flash as I called nrf_delay_us(1000000) to give it 1 second time. Could you help to try the code I posted and point out where the problem is?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: could anybody give an example that pstorage works?</title><link>https://devzone.nordicsemi.com/thread/12539?ContentTypeID=1</link><pubDate>Wed, 13 Aug 2014 09:28:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8e4b4805-669c-429f-8abe-2f3e25549eac</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Have you taken a look at this question?
&lt;a href="https://devzone.nordicsemi.com/question/12743/pstorage-block-size/"&gt;devzone.nordicsemi.com/.../&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;It shows how to use the pstorage for application storage.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>