<?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>Using app_timer to determine if boot loader should start</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/40742/using-app_timer-to-determine-if-boot-loader-should-start</link><description>Background: 
 We have a product that has one button that both power it on and that is used for simple commands, there is also one led to indicate its status. The button is latching the power on so that the device is not consuming any power when it is</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 22 Nov 2018 07:53:24 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/40742/using-app_timer-to-determine-if-boot-loader-should-start" /><item><title>RE: Using app_timer to determine if boot loader should start</title><link>https://devzone.nordicsemi.com/thread/158543?ContentTypeID=1</link><pubDate>Thu, 22 Nov 2018 07:53:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:290c4c9a-530c-4579-8c28-24d2d3901cc3</guid><dc:creator>Edvin</dc:creator><description>[quote user="esa"]Hmm, I tried to&amp;nbsp;add the&amp;nbsp;nrf_dfu_mbr_init_sd() back in to nrf_bootloader_app_start() again, but it fails if it is already called, which it now is. So I&amp;#39;ll leave it commented out.[/quote]
&lt;p&gt;&amp;nbsp;Yes. Sorry. That is correct. Leave that commented out.&lt;/p&gt;
[quote user="esa"]&lt;br /&gt;The reason I start the SD is that I didn&amp;#39;t get the app_timer to run/count without it. I guess the RTC interrupts need the SD to be enabled to propagate them to the app_timer or something?[/quote]
&lt;p&gt;&amp;nbsp;It should be possible to use without the SoftDevice. However, if your application works now, I assume it is fine, but look into the&amp;nbsp;nrf_drv_clock_init() function. It behaves a bit differently when the softdevice is enabled and when it isn&amp;#39;t, depending on whether SOFTDEVICE_PRESENT is defined in your preprocessor defines or not.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Regarding the button3, I see your point. It is difficult to make it work &amp;quot;out of the box&amp;quot; on a DK, and at the same time be completely modifiable from one file. But I agree that the button 3 3 handling could be done in a different way.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;One way is of course to modify your custom_board.h file, and define the BOOTLOADER_BUTTON from there, which will lead to a redefinition, but it could work as a reminder to remove the default define when porting to new SDKs.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;BR,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using app_timer to determine if boot loader should start</title><link>https://devzone.nordicsemi.com/thread/158488?ContentTypeID=1</link><pubDate>Wed, 21 Nov 2018 16:08:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a9c020d0-db92-4d8b-98c5-2bf946474101</guid><dc:creator>Erik</dc:creator><description>&lt;p&gt;Thank you so much, that made me more confident that the modifications are&amp;nbsp;robust. I also added the clearing of the ICPR.&lt;br /&gt;&lt;br /&gt;Yes, I am aware of the newer SDKs and would love to upgrade to those, but I am not sure if the product-owner wants to pay for those developing hours so we stay at a minimum of SDK12 for now.&lt;br /&gt;&lt;br /&gt;The reason I start the SD is that I didn&amp;#39;t get the app_timer to run/count without it. I guess the RTC interrupts need the SD to be enabled to propagate them to the app_timer or something?&lt;/p&gt;
&lt;p&gt;Hmm, I tried to&amp;nbsp;add the&amp;nbsp;nrf_dfu_mbr_init_sd() back in to nrf_bootloader_app_start() again, but it fails if it is already called, which it now is. So I&amp;#39;ll leave it commented out.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;BR Erik&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using app_timer to determine if boot loader should start</title><link>https://devzone.nordicsemi.com/thread/158463?ContentTypeID=1</link><pubDate>Wed, 21 Nov 2018 14:36:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6ce74c2a-20d8-44e6-8abb-677f38af777b</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello Erik,&lt;/p&gt;
&lt;p&gt;You mention that you use IAR 7.60.2 and IAR 8.30.1, so I just want to mention the &lt;a href="http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v15.2.0%2Findex.html"&gt;release notes for our later SDKs regarding IAR versions&lt;/a&gt;. I don&amp;#39;t think your are directly impacted by this, as your bootloader use IAR7, but it is worth keeping in mind for the future, in case you want to update the bootloader, and then use IAR8.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Questions:&lt;/p&gt;
[quote user=""]Is this ok? (it seems to work, but I need it to be bulletproof)[/quote]
&lt;p&gt;I don&amp;#39;t see any issues with moving the ble_stack_init() to before the nrf_dfu_enter_check(), but is there a particular reason why you want to start it in the bootloader if the transport layer isn&amp;#39;t used? Do you use the softdevice to decide whether or not to enter DFU or application? I see that the softdevice&amp;#39;s vector table is set in nrf_bootloader_app_start(), but softdevice_enable() is not called by default.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;As long as you disable the softdevice before entering the app, I don&amp;#39;t see a problem with it. I spoke to our SDK team, who has designed the bootloader, and he told me that there is no reason to change the&amp;nbsp;&lt;span&gt;nrf_bootloader_app_start() function, as long as you disable the softdevice before entering this. It doesn&amp;#39;t actually start the softdevice, it only sets the vector tables. He actually also advised to clear the ICPR in addition to the ICER, like it is done in the bootloader from SDK15.2.0:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    // Disable and clear interrupts
    // Notice that this disables only &amp;#39;external&amp;#39; interrupts (positive IRQn).
    NRF_LOG_DEBUG(&amp;quot;Disabling interrupts. NVIC-&amp;gt;ICER[0]: 0x%x&amp;quot;, NVIC-&amp;gt;ICER[0]);

    NVIC-&amp;gt;ICER[0]=0xFFFFFFFF;
    NVIC-&amp;gt;ICPR[0]=0xFFFFFFFF;
#if defined(__NRF_NVIC_ISER_COUNT) &amp;amp;&amp;amp; __NRF_NVIC_ISER_COUNT == 2
    NVIC-&amp;gt;ICER[1]=0xFFFFFFFF;
    NVIC-&amp;gt;ICPR[1]=0xFFFFFFFF;
#endif&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
[quote user=""]Are there any thing else I need to de-init before jumping to the app now that I have initialized the ble_stack and SD?[/quote]
&lt;p&gt;If you enable the softdevice, you have to disable before entering the application. It is also a good idea to disable any other hardware peripherals, such as timers, that you may have started in the bootloader, or else they will keep running, drawing power.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user=""]Are there any stability reasons for these design changes in the secure bl vs the legacy?[/quote]
&lt;p&gt;&amp;nbsp;The bootloader has become easier to understand in the later SDKs, so it is easier to work with, in my opinion at least. As mentioned earlier, the latest bootloader clears the ICPR, which is an improvement, to prevent any old interrupts to fire right after you start the application. So I guess there are some improvements. In addition to these, softdevice changes are the main reason for updating the bootloader in the later SDKs (as well as in the other examples).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote user=""]In the legacy bootloader the SD was not initialized&amp;nbsp;if the app_reset was&amp;nbsp;set. Do I need to do a&amp;nbsp;similar check in the secure BL with my modification?[/quote]
&lt;p&gt;I guess that the reason for this is that there is no need to start the softdevice if it isn&amp;#39;t used in the bootloader. It takes a bit of time, and hence, a bit of power to do this. If the chip resets without the intention of doing a DFU, there is no reason to start the SoftDevice in the bootloader.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I hope this answered some of your questions. Let me know if anything is unclear, or if you have other bootloader-related questions.&lt;/p&gt;
&lt;p&gt;&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>