<?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>flashwrite operation does not work under specific circumstances</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/36510/flashwrite-operation-does-not-work-under-specific-circumstances</link><description>Hi, 
 I&amp;#39;ve been trying to read/write data from/to the internal flash storage of my nRF52 development board. 
 I am using SDK11 and softdevice s132 
 I have modified the flashwrite main function as follows- 
 
 It initially showed the LED1 (else case)</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 20 Jul 2018 11:44:21 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/36510/flashwrite-operation-does-not-work-under-specific-circumstances" /><item><title>RE: flashwrite operation does not work under specific circumstances</title><link>https://devzone.nordicsemi.com/thread/140819?ContentTypeID=1</link><pubDate>Fri, 20 Jul 2018 11:44:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bc9668b5-1a2c-4d3a-a68a-eea7b59709c3</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Can you try to put err_code =&amp;nbsp; in front of your sd_ calls?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;err_code = sd_ble_gap_adv_stop();
if (err_code != NRF_ERROR_INVALID_STATE)
{
    APP_ERROR_CHECK(err_code);
}
err_code = sd_ble_gap_scan_stop();
if (err_code != NRF_ERROR_INVALID_STATE)
{
    APP_ERROR_CHECK(err_code);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;See if any of those APP_ERROR_CHECKS() are hit if you debug. Note that if you set a breakpoint in the code while in a connection or advertising/scanning, it will hardfault after that, because the softdevice will miss some time critical events.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I also saw that the flash_page_erase() and flash_word_write() functions from SDK11 does the waiting for you. If these functions are executed, but does not finish, can you please try to set some breakpoints inside them to see if you can figure out what event that it is waiting for which does not occur?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Regarding including fds.c:&lt;/p&gt;
&lt;p&gt;I believe that the problem just is that it is missing some header files or .c files. Can you please try to add fds.c and fstorage.c, and make sure that the following paths are included in your projects &amp;quot;include paths&amp;quot; settings:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;..\..\..\..\..\components\libraries\fds
..\..\..\..\..\components\libraries\fds\config
..\..\..\..\..\components\libraries\fstorage
..\..\..\..\..\components\libraries\fstorage\config
..\..\..\..\..\components\libraries\experimental_section_vars&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If that doesn&amp;#39;t work, what sort of compiler errors do you get?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: flashwrite operation does not work under specific circumstances</title><link>https://devzone.nordicsemi.com/thread/140810?ContentTypeID=1</link><pubDate>Fri, 20 Jul 2018 10:01:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a3db9513-62ef-411e-b7ba-6b2588cc5cf6</guid><dc:creator>DMS</dc:creator><description>&lt;p&gt;Yes but I am unable to add the necessary dependencies in my uvision project as described in the previous comment.That&amp;#39;s the reason why i resorted to flashwrite. I am unable to add dependencies under fds.c which gives errors during compilation saying certain header files are missing (even though i have them as dependencies, just not under fds.c)&lt;/p&gt;
&lt;p&gt;Since development is almost completed, I doubt it will be easy for me change SDKs at this point.&lt;/p&gt;
&lt;p&gt;I am actually trying to use the flash r/w code in the following way-&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;case BLE_GAP_EVT_DISCONNECTED:
            err_code = bsp_indication_set(BSP_INDICATE_IDLE);
            APP_ERROR_CHECK(err_code);
            m_conn_handle = BLE_CONN_HANDLE_INVALID;
			sd_ble_gap_adv_stop();
			sd_ble_gap_scan_stop();
			NRF_UART0-&amp;gt;TASKS_STOPTX = 1;
			NRF_UART0-&amp;gt;TASKS_STOPRX = 1;
			NRF_UART0-&amp;gt;ENABLE = 0;
					
			uint32_t * addr;
            uint8_t    patwr;
            uint8_t    patrd;

      
            uint32_t   pg_size;
            uint32_t   pg_num;

            pg_size = NRF_FICR-&amp;gt;CODEPAGESIZE;
            pg_num  = NRF_FICR-&amp;gt;CODESIZE - 1;  // Use last page in flash

    
            // Start address:
            addr = (uint32_t *)(pg_size * pg_num);
            // Erase page:
            flash_page_erase(addr);
		    patwr=0x45;
		    flash_word_write(addr, (uint32_t)patwr);
		    memcpy(&amp;amp;patrd,addr,1);
	        //patrd = (uint8_t)*(addr);
	    	uint8_t flag=4;
		    if(patrd==0x45){
		    	flag=1;
		    	LEDS_ON(BSP_LED_0_MASK);
	        }
		    else{
			    flag=0;
			    LEDS_ON(BSP_LED_1_MASK); 
			}
	    	
	    	err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
			APP_ERROR_CHECK(err_code);
		
			//Start scanning for peripherals which advertise. 
			scan_start();
            break;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;This results in a kind of runtime error causing all LEDs to light up and freezing the device. I observed using debug mode that this occurs at&amp;nbsp;sd_ble_gap_adv_stop(); when the flash code is present but does not occur when the flash code is absent. This is confusing because the flash part of the code appears after the&amp;nbsp;sd_ble_gap_adv_stop(); and I&amp;#39;m assuming if the code is executed sequentially there shouldn&amp;#39;t be any difference at that step.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;So i need help in either getting flashwrite or the dependencies for FDS to work&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thank you&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: flashwrite operation does not work under specific circumstances</title><link>https://devzone.nordicsemi.com/thread/140704?ContentTypeID=1</link><pubDate>Thu, 19 Jul 2018 14:28:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:faf76f0f-39a6-4eec-b41c-b4085fefd8eb</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;You are right. The later SDKs does not support nRF51. However, the SDKs up to SDK12.3.0 does support nRF51, so if you are in the beginning of your development, I would recommend that you use this version. One of the reasons is the logging module that is included in this SDK, which makes development a bit easier.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you want to use the FDS library, I suggest that you check out &lt;a href="http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v12.3.0%2Flib_fds_format.html"&gt;this site&lt;/a&gt;&amp;nbsp;(there is an equivalent for SDK11 &lt;a href="http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v11.0.0%2Flib_fds_usage.html"&gt;here&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In addition, you should wait for a process to finish before moving on, when you are doing flash operations. E.g. a flash write takes some time, so if you call flash read right after, it will fail.&lt;/p&gt;
&lt;p&gt;If I remember correctly, you must also add a function to your event dispatcher to get the events. Please see &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/22265/can-t-get-a-callback-from-fds-no-matter-what---help"&gt;this thread&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: flashwrite operation does not work under specific circumstances</title><link>https://devzone.nordicsemi.com/thread/140597?ContentTypeID=1</link><pubDate>Thu, 19 Jul 2018 06:20:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a857e10c-b441-4899-a50a-a329570ce083</guid><dc:creator>DMS</dc:creator><description>&lt;p&gt;I&amp;#39;m using functions&amp;nbsp;flash_word_write() and&amp;nbsp;flash_page_erase() from the flashwrite example of SDK11 under peripheral examples.&lt;/p&gt;
&lt;p&gt;I am currently testing using nRF52 and keil uvision5, however the actual implementation will be performed on a custom nRF51 board. Thus I haven&amp;#39;t used the higher SDKs since i beileve they don&amp;#39;t support nRF51 anymore.&lt;/p&gt;
&lt;p&gt;I did find an FDS example online for SDK11 but when i try to use snippets from that in my code, i&amp;#39;m not able to add the dependencies for the dependencies properly (I&amp;#39;m inexperienced with keil). For eg-in the example i found online a dependency is like this -&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1531980759527v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;but when i try adding fds.c using &amp;lt;add existing files to group&amp;gt; i get something like this-&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1531980941038v2.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;This results in compile time errors for fds_config.h and fds_internal_defs.h because i&amp;#39;m not able to make them come directly under fds.c but they are defined within fds.c&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;If you could help me figure out either FDS or flashwrite issue, my problem would be solved.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: flashwrite operation does not work under specific circumstances</title><link>https://devzone.nordicsemi.com/thread/140564?ContentTypeID=1</link><pubDate>Wed, 18 Jul 2018 17:55:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:028d479b-c032-412c-93f1-75aa43d0e974</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Is flash_word_write() a function that you have written? In that case, it would be useful to see what it looks like,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Usually, issues regarding flash operation errors that a flash operation is not finished before starting the next one. For all I know, you do this in flash_word_write(), but I don&amp;#39;t know. If it is a function from the SDK, could you please specify what SDK you are using?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If would recommend you to check out the flash_fds example (at least what it is called in SDK15).&lt;/p&gt;
&lt;p&gt;There you will see that there is an event handler in main.c called&amp;nbsp;fds_evt_handler(). This is used to set flags telling the application that the previous&amp;nbsp;operation is done, so that it can start the next operation. In the main() function you can see that it calls:&lt;/p&gt;
&lt;p&gt;rc = fds_init();&lt;br /&gt;APP_ERORR_CHECK(rc);&lt;/p&gt;
&lt;p&gt;wait_for_fds_ready();&lt;/p&gt;
&lt;p&gt;...&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>