<?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>GPREGRET/GPREGRET2 are bitmask registers?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/15183/gpregret-gpregret2-are-bitmask-registers</link><description>We appear to have discovered today that if you do this sequence 
 sd_power_gpregret_clr(0xFF);
sd_power_gpregret_set(0xA0);
sd_power_gpregret_set(0x0B); 
 GPREGRET will contain 0xAB and not 0x0B. 
 Based on the way that BOOTLOADER_DFU_START is used</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sat, 16 Jul 2016 00:02:08 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/15183/gpregret-gpregret2-are-bitmask-registers" /><item><title>RE: GPREGRET/GPREGRET2 are bitmask registers?</title><link>https://devzone.nordicsemi.com/thread/57964?ContentTypeID=1</link><pubDate>Sat, 16 Jul 2016 00:02:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:692f6ecf-b4a3-49a0-9741-b96ffdf33d65</guid><dc:creator>Tony Garland</dc:creator><description>&lt;p&gt;Here&amp;#39;s something I just submitted as a support case (wasn&amp;#39;t able to easily find where SDK suggestions/defects were to be officially submitted).&lt;/p&gt;
&lt;p&gt;this is to alert you to a liability in the example bootloader code in the SDK. Specifically, the bootloader_start() function within&lt;/p&gt;
&lt;p&gt;nRF5_SDK_11.0.0_89a8197.zip/libraries/bootloader/dfu/dfu_app_handler.c has the following code (line 140):&lt;/p&gt;
&lt;p&gt;err_code = sd_power_gpregret_set(BOOTLOADER_DFU_START);&lt;/p&gt;
&lt;p&gt;When the bootloader gains control from bootloader_start(), it checks this value to determine whether the application initiated a DFU operation.  If this value does not match, it assumes a boot from restart, initializes the soft device, and will wind up immediately calling back into the application.  Whereupon the application reinitializes the soft device as if a reset had occurred and a hard fault results.&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s the problem: if any bit happens to be set in the GPREGRET register which is outside of the bit values of the BOOTLOADER_DFU_START value, then the above call will NOT result in GPREGRET having a value of BOOTLOADER_DFU_START--it will just set those bits along with whatever other bit(s) happen to already be set.&lt;/p&gt;
&lt;p&gt;This was happening in our application--where we use GPREGRET for other purposes prior to initiating switch to DFU from the app.  The fix is pretty simple and much more robust:&lt;/p&gt;
&lt;p&gt;// Clear GPREGRET and set our exact DFU value.&lt;/p&gt;
&lt;p&gt;err_code = sd_power_gpregret_clr(0xffffffff);&lt;/p&gt;
&lt;p&gt;APP_ERROR_CHECK(err_code);&lt;/p&gt;
&lt;p&gt;err_code = sd_power_gpregret_set(BOOTLOADER_DFU_START);&lt;/p&gt;
&lt;p&gt;APP_ERROR_CHECK(err_code);&lt;/p&gt;
&lt;p&gt;Perhaps it would be a good change to make in an upcoming SDK release as it would insulate the app-initiated DFU process from this potential glitch.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>