<?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>GPIO reset when Booloader starts Application</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/31033/gpio-reset-when-booloader-starts-application</link><description>I&amp;#39;m developing a project where the device wakes from system_off using a button. I&amp;#39;ve noticed that it takes about half a second from the time the bootloader starts until the application loads. I tested this by turning on an LED at the beginning of the</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 07 Mar 2018 13:49:21 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/31033/gpio-reset-when-booloader-starts-application" /><item><title>RE: GPIO reset when Booloader starts Application</title><link>https://devzone.nordicsemi.com/thread/123261?ContentTypeID=1</link><pubDate>Wed, 07 Mar 2018 13:49:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:24cc37e5-28fd-4881-bc0a-ba144c1e51d6</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Are you sure there is nothing else in the app that reconfigure the IOs after startup? I removed all io configurations from the bootloader code, then configured the LED_4 pin&amp;nbsp;to indicate startup of bootloader and app.&amp;nbsp;&amp;nbsp;I have not managed to reproduce the delays. IO states from bootloader are also kept when entering the main app.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/*bootloader main()*/

int main(void)
{
    nrf_gpio_cfg_output(LED_4);
    nrf_gpio_pin_set(LED_4);
    ...
    
/*App main - used blinky_pca10040_s132 as starting point*/

int main(void)
{
    /*Already configured to output by bootloader*/
    nrf_gpio_pin_clear(LED_4);
    
    /*Configure wake-up pin*/
    nrf_gpio_cfg_sense_input(BUTTON_1,
                             NRF_GPIO_PIN_PULLUP,
                             NRF_GPIO_PIN_SENSE_LOW); 

    /* Toggle LEDs. */
    while (true)
    {
        
        nrf_delay_ms(5000);
        NRF_POWER-&amp;gt;SYSTEMOFF = 1;
        
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;LED_4 pin timing captured with logic analyzer:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-62368b1e8549452e8ff09a4faa2c8c41/pastedimage1520429865410v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;nrf_dfu_mbr_init_sd() tells the MBR to start forwarding interrupts to the softdevice, but it will not start any clock sources.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPIO reset when Booloader starts Application</title><link>https://devzone.nordicsemi.com/thread/123131?ContentTypeID=1</link><pubDate>Tue, 06 Mar 2018 17:31:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ea7ba69b-6e8a-4b95-835b-68a1ac4a7d88</guid><dc:creator>zolotiyeruki</dc:creator><description>&lt;p&gt;Driving the pin low is what turns on the LED--sorry I wasn&amp;#39;t clear on that before.&amp;nbsp; To clarify:&lt;/p&gt;
&lt;p&gt;1) The bootloader turns on the LED&lt;br /&gt;2) 250-ish ms later, something turns off the LED (very soon after calling&amp;nbsp;&lt;span&gt;nrf_bootloader_app_start())&lt;br /&gt;3) 300 ms after the LED turns off, it gets turned on by the Application&amp;#39;s main(), in the supplied code snippet&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;So it looks like something is resetting the gpio configuration, and then something else is&amp;nbsp;requesting a ramp up of the LF crystal, before the Application&amp;#39;s main() is called.&amp;nbsp; I notice that&amp;nbsp;nrf_bootloader_app_start calls&amp;nbsp;nrf_dfu_mbr_init_sd() - would that be the culprit?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPIO reset when Booloader starts Application</title><link>https://devzone.nordicsemi.com/thread/123129?ContentTypeID=1</link><pubDate>Tue, 06 Mar 2018 16:37:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:82a04868-d0c0-470d-bd13-9a76d4c6fafe</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;There are three things that can request ramp up of the LF crystal: call to nrf_drv_clock_lfclk_request() after clock_init(), writing &amp;#39;1&amp;#39; to&amp;nbsp;NRF_CLOCK-&amp;gt;TASKS_LFCLKSTART, or call to&amp;nbsp;&lt;span&gt;ble_stack_init()/sd_softdevice_enable().&amp;nbsp;So it&amp;nbsp;looks like&amp;nbsp;you are turning off the LED before LF start task is triggered. Also,&amp;nbsp; the bootloader should not start the LF clock unless it enters DFU mode (BLE transport will start the crystal)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Maybe you can try with the RCOSC instead to&amp;nbsp;check&amp;nbsp;if this is indeed caused ramp up time of the LF crystal. Startup time for RCOSC is 600 us for comparison.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Code changes to use internal RC as LF clock source:&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/*In sdk_config*/

// &amp;lt;o&amp;gt; CLOCK_CONFIG_LF_SRC  - LF Clock Source
 
// &amp;lt;0=&amp;gt; RC 
// &amp;lt;1=&amp;gt; XTAL 
// &amp;lt;2=&amp;gt; Synth 

#ifndef CLOCK_CONFIG_LF_SRC
#define CLOCK_CONFIG_LF_SRC 0
#endif

/*in ble_stack_init()*/

nrf_clock_lf_cfg_t clock_lf_cfg = {.source = NRF_CLOCK_LF_SRC_RC,
                                   .rc_ctiv = 16,
                                   .rc_temp_ctiv = 2};&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPIO reset when Booloader starts Application</title><link>https://devzone.nordicsemi.com/thread/123102?ContentTypeID=1</link><pubDate>Tue, 06 Mar 2018 14:45:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:018c4e73-063e-4d97-a6d9-1ad07d6e39e7</guid><dc:creator>zolotiyeruki</dc:creator><description>&lt;p&gt;I have not modified the bootloader, but the hardware includes a 32kHz crystal.&amp;nbsp; In the sdk_config.h for the bootloader, I have this:&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define CLOCK_ENABLED 0&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;In the application, I have this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#ifndef CLOCK_ENABLED
#define CLOCK_ENABLED 1
#endif
#if CLOCK_ENABLED
...
// &amp;lt;0=&amp;gt; RC 
// &amp;lt;1=&amp;gt; XTAL 
// &amp;lt;2=&amp;gt; Synth
#ifndef CLOCK_CONFIG_LF_SRC
#define CLOCK_CONFIG_LF_SRC 1
#endif&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This leads me to believe that you&amp;#39;re correct--it&amp;#39;s the ramp-up time of the LF crystal.&amp;nbsp; Also in the application, initializing the LEDs and turning one of them on is literally the first thing in main():&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;int main(void)
{
	configLedPin(LED_PIN_RED);
	configLedPin(LED_PIN_BLU);
	configLedPin(LED_PIN_GRN);
	NRF_P0-&amp;gt;OUTCLR = (1&amp;lt;&amp;lt;LED_PIN_GRN);
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Is there an easy way to turn on the LED before the LF clock is ramped up?&amp;nbsp; From what I can see, the call stack is something like this:&lt;/p&gt;
&lt;p&gt;nrf_clock_lf_src_set&lt;br /&gt;called by nrf_drv_clock_init&lt;br /&gt;called by nrf_drv_clock_on_sd_enable&lt;br /&gt;called by&amp;nbsp;softdevice_handler_init&lt;br /&gt;called by ble_stack_init (within Application)&lt;/p&gt;
&lt;p&gt;In my application, however, ble_stack_init isn&amp;#39;t called until well after main() initializes a bunch of other stuff (gpio, saadc, TWI, UART, app_timer, etc).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPIO reset when Booloader starts Application</title><link>https://devzone.nordicsemi.com/thread/123013?ContentTypeID=1</link><pubDate>Tue, 06 Mar 2018 10:28:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aa132c83-d4c6-48c5-b596-ea523428805c</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;1) Have you modified the bootloader so that it ramps up the HF/LF crystal&amp;nbsp;during startup? Typical startup time for a LF crystal is 250 ms (&lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/clock.html?cp=2_1_0_18_3_3#unique_1385509760"&gt;clock spec&lt;/a&gt;.), which could explain the delay you are seeing.&amp;nbsp; I measured the same to ~13 ms with the default bootloader from SDK 13.0.0&lt;/p&gt;
&lt;p&gt;2)&amp;nbsp;The bootloader does not reset the GPIO module when booting the application, but the app will typically re-initialize the IOs during startup. Do you see the same if you don&amp;#39;t initialize GPIO pins in your app?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>