<?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>why the fs_sys_event_handler() can&amp;#39;t be called--when use fstorage to write flash?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/53672/why-the-fs_sys_event_handler-can-t-be-called--when-use-fstorage-to-write-flash</link><description>SDK11, NRF51822 
 
 if I use the fstorage_test at the applicaiton_init(void), then runs ok. 
 but on my product, I use a key to power the system, if I use the fstorage_test() in the power on function(), then the fs_sys_event_handler() can&amp;#39;t be called</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 12 Nov 2019 01:19:28 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/53672/why-the-fs_sys_event_handler-can-t-be-called--when-use-fstorage-to-write-flash" /><item><title>RE: why the fs_sys_event_handler() can't be called--when use fstorage to write flash?</title><link>https://devzone.nordicsemi.com/thread/219564?ContentTypeID=1</link><pubDate>Tue, 12 Nov 2019 01:19:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f88ef422-4d6f-4d86-a749-a9bd127a64f7</guid><dc:creator>zk017</dc:creator><description>&lt;p&gt;OK， I solved it. it&amp;#39;s the&amp;nbsp;function&amp;nbsp;app_sched_event_put return&amp;nbsp;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code&gt;NRF_ERROR_INVALID_LENGTH. I redefine the parameters of APP_SCHED_INIT();and now is ok!Thank you,tesc, thank you ,msromero!&amp;nbsp;&lt;/code&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: why the fs_sys_event_handler() can't be called--when use fstorage to write flash?</title><link>https://devzone.nordicsemi.com/thread/219404?ContentTypeID=1</link><pubDate>Mon, 11 Nov 2019 09:24:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1674db0d-2eb8-4b9e-b70b-201def94fa0a</guid><dc:creator>zk017</dc:creator><description>&lt;p&gt;tesc, thank you very much! first i&amp;nbsp;Misunderstanding the volatile, now I fixed it , and I use schedule to try it, code as follow:&lt;pre class="ui-code" data-mode="c_cpp"&gt;APP_TIMER_DEF(led1_timer); 

void write_flash(void *p_event_data, uint16_t event_size)
{
	 #if 1
	 NRF_LOG_PRINTF(&amp;quot;write_flash %X\n &amp;quot;, 0x88888888); //here can&amp;#39;t be called!
	 #else
//		static uint32_t data;
//		uint32_t flash_data[4];
//		fs_ret_t ret;
//		
//		// Erase one page (page 0).
//		NRF_LOG_PRINTF(&amp;quot;Erasing a flash page at address 0x%X\r\n&amp;quot;, (uint32_t)fs_config.p_start_addr);
//		fs_callback_flag = 1;
//		ret = fs_erase(&amp;amp;fs_config, fs_config.p_start_addr, 1);
//		while(fs_callback_flag == 1)  { power_manage(); }
//		
//		//Read the first 4 words of the page
//		NRF_LOG_PRINTF(&amp;quot;Data read from flash address 0x%X: &amp;quot;, (uint32_t)fs_config.p_start_addr);
//		for(int i=0; i&amp;lt;4; i++)
//		{
//				flash_data[i] = *(fs_config.p_start_addr + i);
//				NRF_LOG_PRINTF(&amp;quot;%X &amp;quot;, flash_data[i]);
//		}
//		NRF_LOG_PRINTF(&amp;quot;\r\n&amp;quot;);
//		
//		data = 0xAAAAAAAA;
//		NRF_LOG_PRINTF(&amp;quot;Writing data 0x%X to address 0x%X\r\n&amp;quot;, data, (uint32_t)fs_config.p_start_addr);
//		fs_callback_flag = 1;
//		ret = fs_store(&amp;amp;fs_config, fs_config.p_start_addr, &amp;amp;data, 1);      //Write data to memory address 0x0003F00. Check it with command: nrfjprog --memrd 0x0003F000 --n 16
//		if (ret != FS_SUCCESS)
//		{
//				//bsp_indication_set(BSP_INDICATE_FATAL_ERROR);
//		}
//		while(fs_callback_flag == 1)  { power_manage(); }
//		
//		//Read the first 4 words of the page
//		NRF_LOG_PRINTF(&amp;quot;Data read from flash address 0x%X: &amp;quot;, (uint32_t)fs_config.p_start_addr);
//		for(int i=0; i&amp;lt;4; i++)
//		{
//				flash_data[i] = *(fs_config.p_start_addr + i);
//				NRF_LOG_PRINTF(&amp;quot;%X &amp;quot;, flash_data[i]);
//		}
//		NRF_LOG_PRINTF(&amp;quot;\r\n&amp;quot;);
	#endif
}



void led_timer_handler(void *p_contex)
{
		write_event a={5, 0x11223344};
		app_sched_event_put(&amp;amp;a, sizeof(write_event), write_flash);//can run here.
}

void led_timer_init(void)
{
       //创建定时器
       app_timer_create(&amp;amp;led1_timer,APP_TIMER_MODE_REPEATED,led_timer_handler);
}


//启动定时器

void led_timer_start(void)
{

       app_timer_start(led1_timer,

                                   APP_TIMER_TICKS(1000, APP_TIMER_PRESCALER),

                                   NULL);  

      

}
//--------------------------------------------------
void application_init(void)
{
    uint32_t err_code;
    
    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);
    system_gpios_init();
    dx_ble_app_init(); 
  
    app_pwms_init();

    battery_check_init();
    button_check_init();
    wdt_init();
 
    err_code = app_timer_create(&amp;amp;m_app_assist_timer_id,
                                APP_TIMER_MODE_REPEATED,
                                app_assist_meas_timeout_handler);
    APP_ERROR_CHECK(err_code);
    
}
//-----------------------------------------------------
/**@brief Application main function.
 */

int main(void)
{

    NRF_LOG_INIT();
	
	application_init();//
	init_fstorage();

	APP_SCHED_INIT(4,10);
    NRF_LOG_PRINTF(&amp;quot;system start......\r\n&amp;quot;);	
	led_timer_init();
    led_timer_start();
    // Enter main loop.
    for (;;)
    {
		app_sched_execute();
        power_manage();
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;this time I found app_sched_event_put can be execute, but the function write_flash() can&amp;#39;t be called, I don&amp;#39;t know any question occur here. can you help me, thanks again!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: why the fs_sys_event_handler() can't be called--when use fstorage to write flash?</title><link>https://devzone.nordicsemi.com/thread/218673?ContentTypeID=1</link><pubDate>Tue, 05 Nov 2019 18:06:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fde8beee-06cf-485f-a2c4-63698823a1be</guid><dc:creator>tesc</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I do not know if it is an error in translation, but what I meant by &amp;quot;declare volatile&amp;quot; is you must define the variable with the &amp;quot;volatile&amp;quot; keyword. This tells the compiler that the value must be read from and written to memory every time it is used. If it is not &amp;quot;volatile&amp;quot;, the compiler may hold the value in a CPU register or even optimize the code in such a way that the variable is never used. When you set and clear a flag in one context, and check for the flag in another context, you must always use a volatile variable for that flag.&lt;/p&gt;
&lt;p&gt;Please have a look at the &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v11.0.0%2Flib_scheduler.html"&gt;Schedule handling library documentation&lt;/a&gt;. In nRF5 SDK v11, it is used for instance in the HID &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v11.0.0/ble_sdk_app_hids_keyboard.html"&gt;Keyboard&lt;/a&gt; and &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v11.0.0/ble_sdk_app_hids_mouse.html"&gt;Mouse&lt;/a&gt; examples and in the &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v11.0.0/ble_sdk_app_eddystone.html"&gt;Eddystone example&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Terje&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: why the fs_sys_event_handler() can't be called--when use fstorage to write flash?</title><link>https://devzone.nordicsemi.com/thread/218390?ContentTypeID=1</link><pubDate>Tue, 05 Nov 2019 02:00:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:27fe9c5b-0990-488f-89e5-4e9a433e6b2b</guid><dc:creator>zk017</dc:creator><description>&lt;p&gt;It&amp;#39;s can&amp;#39;t be set volatile, for every time before store or erase ,it&amp;#39;s should be set 1 by user. I wonder how to use schedule handling library, Is there any example?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: why the fs_sys_event_handler() can't be called--when use fstorage to write flash?</title><link>https://devzone.nordicsemi.com/thread/217994?ContentTypeID=1</link><pubDate>Fri, 01 Nov 2019 14:44:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:66b2a526-8f7b-47f5-8ed7-4966847620a1</guid><dc:creator>tesc</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;First of all you need to declare fs_callback_flag volatile:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static volatile uint8_t fs_callback_flag;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;You also need to move the call to fstorage_test() out of interrupt context. Now it is called through a button event handler, which means it is called from an interrupt. This will block all interrupts of same or lower priority for as long as the function runs. Please have a look at the schedule handling library as suggested by &lt;a href="https://devzone.nordicsemi.com/members/marjeris-romero"&gt;Marjeris Romero&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Terje&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: why the fs_sys_event_handler() can't be called--when use fstorage to write flash?</title><link>https://devzone.nordicsemi.com/thread/216999?ContentTypeID=1</link><pubDate>Mon, 28 Oct 2019 08:34:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fee56e2e-d3cf-4a2d-8cb0-b3315470b84a</guid><dc:creator>zk017</dc:creator><description>&lt;p&gt;my question like&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/24041/sdk12-3-use-fs_erase-and-fs_store/94648#94648"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/24041/sdk12-3-use-fs_erase-and-fs_store/94648#94648&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: why the fs_sys_event_handler() can't be called--when use fstorage to write flash?</title><link>https://devzone.nordicsemi.com/thread/216863?ContentTypeID=1</link><pubDate>Fri, 25 Oct 2019 13:04:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9c867371-0346-41ea-ae99-9d5bc8134a85</guid><dc:creator>Marjeris Romero</dc:creator><description>&lt;p&gt;Hi, &lt;br /&gt;&lt;br /&gt;It seems like fs_sys_event_handler() has a lower interrupt priority than fstorage_test() and therefore is never called. You can try to use app_scheduler to call fstorage_test() from main context. Take a look at the &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v16.0.0/lib_scheduler.html?cp=5_1_3_39"&gt;schedule handling library&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Marjeris&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>