<?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>Problem with fstorage and ble init</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/42474/problem-with-fstorage-and-ble-init</link><description>Hi: 
 I am having a problem with the fstorage and ble_stack_init. When fstorage is used before the ble_stack_init it works fine. If used after ble_stack_init, the fstorage handler is not called. I tried several combinations among test() and ble_stack_init</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 16 Jan 2019 14:33:53 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/42474/problem-with-fstorage-and-ble-init" /><item><title>RE: Problem with fstorage and ble init</title><link>https://devzone.nordicsemi.com/thread/166028?ContentTypeID=1</link><pubDate>Wed, 16 Jan 2019 14:33:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4fc742e3-ec88-4f40-8be5-647a0b479cb0</guid><dc:creator>pjm</dc:creator><description>&lt;p&gt;Dear Einar:&lt;/p&gt;
&lt;p&gt;An huge thanks to you - it work amazingly well.&lt;/p&gt;
&lt;p&gt;Paulo Matos&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with fstorage and ble init</title><link>https://devzone.nordicsemi.com/thread/165955?ContentTypeID=1</link><pubDate>Wed, 16 Jan 2019 12:18:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e9548248-720e-407f-8429-8adb713d8c0e</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi Paulo,&lt;/p&gt;
&lt;p&gt;You can call&amp;nbsp;wait_for_flash_ready() instead, but then you have to call app_sched_execute() from there as well, for the same reason as described in the previous post. Then it would be something like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void wait_for_flash_ready(){
    /* While fstorage is busy, sleep and wait for an event. */
    while (nrf_fstorage_is_busy(&amp;amp;my_instance)){
        sd_app_evt_wait();
        app_sched_execute();
    }
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with fstorage and ble init</title><link>https://devzone.nordicsemi.com/thread/165941?ContentTypeID=1</link><pubDate>Wed, 16 Jan 2019 11:48:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8989a1da-4ec6-4183-ade8-1be0dce6f6d2</guid><dc:creator>pjm</dc:creator><description>&lt;p&gt;Dear Einar:&lt;/p&gt;
&lt;p&gt;Thanks very much for your reply. It solves the problem, allowing us to continue.&lt;br /&gt;Allow me one more question related with your last comment. Is it possible to replace&lt;/p&gt;
&lt;p&gt;while(fs_callback_flag){&lt;br /&gt;app_sched_execute();&lt;br /&gt;nrf_delay_ms(25);&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;by:&lt;/p&gt;
&lt;p&gt;wait_for_flash_ready();&lt;/p&gt;
&lt;p&gt;I tried, but it is not working ... the program does not wakeup ... what am i missing here? Is it not a feasible solution?&lt;/p&gt;
&lt;p&gt;Once more thanks for your help,&lt;/p&gt;
&lt;p&gt;Paulo Matos&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with fstorage and ble init</title><link>https://devzone.nordicsemi.com/thread/165704?ContentTypeID=1</link><pubDate>Tue, 15 Jan 2019 11:34:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ce81adf8-5299-442d-b637-c863d53d1440</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi Paulo,&lt;/p&gt;
&lt;p&gt;OK, now I see. The&amp;nbsp;&lt;span&gt;ble_app_hids_mouse&amp;nbsp;example use the app_scheduler, which means that the SoftDevice events are handled in the main context when the application calls&amp;nbsp;app_sched_execute(). This does not happen in your code, as you only call&amp;nbsp;nrf_delay_ms(). You can fix it by moving the call to test() after the call to scheduler_init() and modifying your test function like this so that you process the scheduler&amp;nbsp;queue while waiting:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void test(void){
    ret_code_t ret = nrf_fstorage_init(&amp;amp;my_instance, &amp;amp;nrf_fstorage_sd, NULL);
    uint8_t msg = 0;
    wait_for_flash_ready();
    fs_callback_flag = 1;    
    ret = nrf_fstorage_erase(&amp;amp;my_instance, my_instance.start_addr, 1, &amp;amp;msg);
    if (ret == NRF_SUCCESS)
    {
        while(fs_callback_flag)
        {
            app_sched_execute();
            nrf_delay_ms(25);
        }
    }
}&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Alternatively you can stop using the scheduler by setting&amp;nbsp;NRF_SDH_DISPATCH_MODEL to 0 (NRF_SDH_DISPATCH_MODEL_INTERRUPT) in sdk_config.h and commenting out&amp;nbsp;the call to&amp;nbsp;scheduler_init() in main() and&amp;nbsp;app_sched_execute() in idle_state_handle().&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;(As a side note I want to mention something which might be obvious, and that is that you should only use nrf_delay_ms() like this for proof of concept. It will prevent the CPU from sleeping or processing other tasks, so it is not suitable in a low power application.)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Einar&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with fstorage and ble init</title><link>https://devzone.nordicsemi.com/thread/165521?ContentTypeID=1</link><pubDate>Mon, 14 Jan 2019 14:45:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d1b3984f-980e-44b3-8a12-16a2cca5e660</guid><dc:creator>pjm</dc:creator><description>&lt;p&gt;Dear Einar:&lt;/p&gt;
&lt;p&gt;I am using the SDK15.2, with the&amp;nbsp;NRF_FSTORAGE_SD, and even when i initialized the fstorage after the ble, the problem is the same.&lt;/p&gt;
&lt;p&gt;I tested using a &amp;quot;clean&amp;quot; copy of the ble_app_hids_mouse adding the code to deal with the fstorage:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;
#include &amp;quot;nrf_fstorage.h&amp;quot;
#include &amp;quot;nrf_fstorage_sd.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;
uint32_t fs_callback_flag=0;

void fs_evt_handler(nrf_fstorage_evt_t * evt){
  if(evt-&amp;gt;result == NRF_SUCCESS){     
      fs_callback_flag=0;
  }
}

NRF_FSTORAGE_DEF(nrf_fstorage_t my_instance) = {
    .evt_handler    = fs_evt_handler, // Function for event callbacks.
    .start_addr     = 0x00078000,  // Corresponde a 0x7FFFF - 4096 (tamanho de cada p&amp;#225;gina) * 8 p&amp;#225;ginas
    .end_addr       = 0x0007FFFF,  // Topo da mem&amp;#243;ria Flash - ATEN&amp;#199;&amp;#195;O - Deve ser alterado caso se utilize bootloader
};

void wait_for_flash_ready(){
    /* While fstorage is busy, sleep and wait for an event. */
    while (nrf_fstorage_is_busy(&amp;amp;my_instance)){
      (void) sd_app_evt_wait();
    }
}
void test(void){
    ret_code_t ret = nrf_fstorage_init(&amp;amp;my_instance, &amp;amp;nrf_fstorage_sd, NULL);
    uint8_t msg = 0;
    wait_for_flash_ready();
    fs_callback_flag = 1;    
    ret = nrf_fstorage_erase(&amp;amp;my_instance, my_instance.start_addr, 1, &amp;amp;msg);
    if (ret == NRF_SUCCESS) while(fs_callback_flag) nrf_delay_ms(25);         
}

int main(void)
{
    bool erase_bonds;
    ret_code_t rc;
    // Initialize.
    log_init();
    timers_init();
    buttons_leds_init(&amp;amp;erase_bonds);
    power_management_init();
    test(); // Here, it works
    ble_stack_init();
    //test(); // Here, it does not work
    scheduler_init();
    gap_params_init();
    gatt_init();
    advertising_init();
    services_init();
    sensor_simulator_init();
    conn_params_init();    
    peer_manager_init();

    // Start execution.
    NRF_LOG_INFO(&amp;quot;HID Mouse example started.&amp;quot;);
    timers_start();
    advertising_start(erase_bonds);

    // Enter main loop.
    for (;;)
    {
        idle_state_handle();
    }
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The test() function works fine when used before&amp;nbsp;&lt;span&gt;ble_stack_init(). After it, it does not work.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I am testing it on the PCA10040 board.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thanks,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Paulo Matos&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with fstorage and ble init</title><link>https://devzone.nordicsemi.com/thread/165490?ContentTypeID=1</link><pubDate>Mon, 14 Jan 2019 13:53:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e1a72f62-812b-4a3e-ac00-0cfe69083700</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Which SDK version are you using? I will assume SDK 15.2 for now.&lt;/p&gt;
&lt;p&gt;Which of the fstorage implementations are you using? I ask because there are several implementation files:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;nrf_fstorage_nvmc.c works &lt;em&gt;without&lt;/em&gt; the SoftDevice (which is the situation &lt;em&gt;before&lt;/em&gt; you call&amp;nbsp;ble_stack_init ())&lt;/li&gt;
&lt;li&gt;nrf_fstorage_sd.c&amp;nbsp;works &lt;em&gt;with&lt;/em&gt; the SoftDevice (which is the situation &lt;em&gt;after&lt;/em&gt; you call ble_stack_init ())&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When you use the SoftDevice you should initialize it first, then initialize fstorage after, using the SoftDevice compatible implementation.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>