<?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>Buttonless DFU works on dev kits but not on custom board</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/80344/buttonless-dfu-works-on-dev-kits-but-not-on-custom-board</link><description>Hello, 
 I’m using the secure bootloader for serial DFU (UART, not USB). To enter bootloader mode from the application, I write 0xB1 to GPREGRET, then call NVIC_SystemReset(). On the dev boards I have (PCA10056 and Particle Boron), this works to reboot</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 13 Oct 2021 07:30:00 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/80344/buttonless-dfu-works-on-dev-kits-but-not-on-custom-board" /><item><title>RE: Buttonless DFU works on dev kits but not on custom board</title><link>https://devzone.nordicsemi.com/thread/333835?ContentTypeID=1</link><pubDate>Wed, 13 Oct 2021 07:30:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:19463409-ffbf-45b4-8d0d-4442e74660cc</guid><dc:creator>Vidar Berg</dc:creator><description>[quote user="cwmoreiras"]&lt;p&gt;Also, I don&amp;#39;t believe that the bootloader is code is running, then resetting, then running again. I have inserted in the first line of the bootloader&amp;#39;s main function: nrf_delay_ms(5000);&lt;/p&gt;
&lt;p&gt;When I power cycle my device, the application code loads after about 5 seconds (indicated by an LED). If it was resetting from the bootloader (so bootloader code is essentially running twice), I would expect that when I reset the device using the ENTER_DFU command I send to my application code, I would have to wait 10 seconds for the application code to start running. But the application code will load after 5 seconds, even when I am using the serial command.&lt;/p&gt;[/quote]
&lt;p&gt;Yes, I agree. It sounds like the startup delay should have been 10 seconds and not 5 if an assert was raised after entering DFU mode.&lt;/p&gt;
&lt;p&gt;If you haven&amp;#39;t done it already, please try to debug the Bootloader project while sending the ENTER_DFU command to the main app and then check if the dfu_enter_check() function sets the &amp;#39;dfu_enter&amp;#39; to true or false.&lt;/p&gt;
&lt;p&gt;Also, this should not be board specific, but have you verified that the GPREGRET register is set correctly in the application before it resets into the bootloader? A common mistake is to access the GPREGRET register directly while the Softdevice is enabled instead of going through the SD API &lt;span&gt;&lt;a title="sd_power_gpregret_set" href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s140.api.v7.3.0/group___n_r_f___s_o_c___f_u_n_c_t_i_o_n_s.html?cp=4_7_4_1_2_7_2_16#ga62737e6515d380aa3eeba6582d061592"&gt;sd_power_gpregret_set&lt;/a&gt;&lt;/span&gt;(). Writing directly to POWER registers will trigger the Softdevice&amp;#39;s &lt;span&gt;&lt;a title="Memory isolation and runtime protection" href="https://infocenter.nordicsemi.com/topic/sds_s140/SDS/s1xx/sd_mgr/mem_isolation_runtime_protection.html?cp=4_7_4_0_4_3"&gt;Memory isolation and runtime protection&lt;/a&gt;&lt;/span&gt; mechanism.&lt;/p&gt;
&lt;p&gt;Bootloader enters DFU mode when &amp;#39;dfu_enter&amp;#39; flag is &amp;#39;true&amp;#39;&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1634108929019v1.png" alt=" " /&gt;&lt;/p&gt;
[quote user="cwmoreiras"]Is there some minimum hardware requirements in terms of how many LEDs must be designated in the board file for the bootloader to work? My board only has 2 LEDs and implementations on the dev kits I have seen use more LEDs than that (I have done this with PCA10056 and the particle boron which has more than 4 LEDs[/quote]
&lt;p&gt;There are not really any minimum requirements. But in addition to creating the custom board header file, you should comment the&amp;nbsp; bsp_board_led_off(BSP_BOARD_LED_2); and the bsp_board_led_on(BSP_BOARD_LED_2); line in main.c to make the project use 2 instead of 3 LEDs for state indication.&lt;/p&gt;
&lt;p&gt;The NRF_BL_DFU_ENTER_METHOD_BUTTON setting in sdk_config.h must be disabled if you don&amp;#39;t have a dedicated button for entering DFU mode.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Buttonless DFU works on dev kits but not on custom board</title><link>https://devzone.nordicsemi.com/thread/333790?ContentTypeID=1</link><pubDate>Tue, 12 Oct 2021 17:24:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5aec588a-cc46-4751-81b7-cb5ca2c68b99</guid><dc:creator>cwmoreiras</dc:creator><description>&lt;p&gt;I tried what you&amp;#39;ve suggested, and the breakpoint was never hit. Also, in my application code I use UART to send the command to switch to DFU mode. I have that set up as the same pins as what I designate in the custom.h board file I wrote for my board.&lt;/p&gt;
&lt;p&gt;Also, I don&amp;#39;t believe that the bootloader is code is running, then resetting, then running again. I have inserted in the first line of the bootloader&amp;#39;s main function: nrf_delay_ms(5000);&lt;/p&gt;
&lt;p&gt;When I power cycle my device, the application code loads after about 5 seconds (indicated by an LED). If it was resetting from the bootloader (so bootloader code is essentially running twice), I would expect that when I reset the device using the ENTER_DFU command I send to my application code, I would have to wait 10 seconds for the application code to start running. But the application code will load after 5 seconds, even when I am using the serial command.&lt;/p&gt;
&lt;p&gt;Is there some minimum hardware requirements in terms of how many LEDs must be designated in the board file for the bootloader to work? My board only has 2 LEDs and implementations on the dev kits I have seen use more LEDs than that (I have done this with PCA10056 and the particle boron which has more than 4 LEDs&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Buttonless DFU works on dev kits but not on custom board</title><link>https://devzone.nordicsemi.com/thread/333406?ContentTypeID=1</link><pubDate>Mon, 11 Oct 2021 08:17:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e544f058-5161-4b55-a89d-81cd7e645376</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;The dfu flag in GPREGRET gets cleared by the bootloader when it reaches the dfu_enter_flags_clear() function in nrf_bootloader.c after entering DFU mode, so this is probably to be expected.&lt;/p&gt;
&lt;p&gt;Based on your findings thus far, I suspect the problem must be an error occurring in the bootloader after entering DFU mode that leads to the device being reset again. Maybe something related to the UART pinout considering the problem only happens with your board. Could you try to place a breakpoint in nrf_dfu_serial_uart.c::uart_event_handler()::NRF_DRV_UART_EVT_ERROR and see if it gets hit?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Buttonless DFU works on dev kits but not on custom board</title><link>https://devzone.nordicsemi.com/thread/333314?ContentTypeID=1</link><pubDate>Fri, 08 Oct 2021 17:15:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:24d19241-4fda-4420-a8c0-b9677a946db5</guid><dc:creator>cwmoreiras</dc:creator><description>&lt;p&gt;Well, I have discovered something interesting.&lt;/p&gt;
&lt;p&gt;After I send the reset into DFU command to my device, I can verify that GPREGRET has the correct contents in the following way&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;(gdb) p/x *0x4000051c
$1 = 0xb1&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;However, when my device then resets into the bootloader, I run the same command to check the contents of GPREGRET, right at the beginning of main(), and it appears the value has been erased or overwritten&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;(gdb) p/x *0x4000051c
$1 = 0x0&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The documentation states that retained registers will only be overwritten on power cycle or brownout. I&amp;#39;ve also discovered that the RESETREAS register is set to 0 after the reset, which suggests that the device might be browning out or power cycling?&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;(gdb) p/x *0x40000400
$3 = 0x0&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;However, I&amp;#39;m seeing that NVIC_SystemReset() doesn&amp;#39;t actually write anything to RESETREAS, so it makes sense that value would be 0 as far as I can tell. So I&amp;#39;m not really sure why GPREGRET is being overwritten, especially since it doesn&amp;#39;t seem to happen on the other boards&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Buttonless DFU works on dev kits but not on custom board</title><link>https://devzone.nordicsemi.com/thread/333148?ContentTypeID=1</link><pubDate>Fri, 08 Oct 2021 00:06:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6b80a6cf-5083-4d79-a21c-9b3e60b9c25c</guid><dc:creator>cwmoreiras</dc:creator><description>&lt;p&gt;I put a 10 second delay in the beginning of main() so that I would have time to attach the debugger after sending the command to boot into DFU mode. In this way I have discovered that the bootloader does make it into the main() function. I will see tomorrow if I can find out more&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Buttonless DFU works on dev kits but not on custom board</title><link>https://devzone.nordicsemi.com/thread/333141?ContentTypeID=1</link><pubDate>Thu, 07 Oct 2021 20:08:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:27bceb41-c050-47ca-b1a4-89be23508c72</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;It&amp;rsquo;s not a requirement&amp;nbsp;to turn off optimization for more simple debugging like this, so I&amp;rsquo;d suggest to leave it as is for now.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;For breakpoints I would recommend to use the breakpoint command&amp;nbsp;in GDB. E.g. breakpoint main.c:&amp;lt;insert line number&amp;gt; Or breakpoint main to break on main(). Using the NRF_BREAKPOINT macro is also an option, but note that it will halt the CPU even when you are not debugging.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Buttonless DFU works on dev kits but not on custom board</title><link>https://devzone.nordicsemi.com/thread/333130?ContentTypeID=1</link><pubDate>Thu, 07 Oct 2021 18:45:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:058ad59f-ac2f-4ae4-b382-c71b3d88d7ee</guid><dc:creator>cwmoreiras</dc:creator><description>&lt;p&gt;Sure, I have a question about this though. I read on a different thread that I would have to turn off optimization for the bootloader, and this would make it too big to fit in flash at the address designated by the linker script. What address should I place the bootloader at for this to work with optimization set to 0?&lt;/p&gt;
&lt;p&gt;Also, for the breakpoints do you recommend using NRF_BREAKPOINT?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Buttonless DFU works on dev kits but not on custom board</title><link>https://devzone.nordicsemi.com/thread/333007?ContentTypeID=1</link><pubDate>Thu, 07 Oct 2021 11:27:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:399fe92f-b5a9-47ed-b092-5f9ae1c8cfe1</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Torbj&amp;oslash;rn asked me to follow up on this.&lt;/p&gt;
&lt;p&gt;Thanks for confirming the that the bootloader start address was set correctly.&amp;nbsp;The MBR knows a bootloader is present when this register is set, see &lt;span&gt;&lt;a title="Master boot record and SoftDevice reset procedure" href="https://infocenter.nordicsemi.com/topic/sds_s132/SDS/s1xx/mbr_bootloader/mbr_sd_reset_behavior.html?cp=4_7_3_0_11_2"&gt;Master boot record and SoftDevice reset procedure&lt;/a&gt; for details&lt;/span&gt;. So this means the bootloader should executing&amp;nbsp; before the application on startup. &lt;span&gt;&lt;/span&gt;The problem might be that it fails to enter DFU mode for some reason.&lt;/p&gt;
&lt;p&gt;Could you try to start a GDB session with the bootloader project and see if it reaches main()?&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Edit: &lt;/strong&gt;you may also want to place breakpoints in the fault handlers in main.c to catch any code assertions.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Buttonless DFU works on dev kits but not on custom board</title><link>https://devzone.nordicsemi.com/thread/332893?ContentTypeID=1</link><pubDate>Wed, 06 Oct 2021 16:35:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ccf6d79e-0c29-42b1-b5d0-a10d62d2a56d</guid><dc:creator>cwmoreiras</dc:creator><description>&lt;p&gt;Unfortunately I can&amp;#39;t use a JLink device with this board. I would have to make a special breakout adapter for that. I flash/debug through an FT2232H with OpenOCD and GDB.&lt;/p&gt;
&lt;p&gt;When I read the contents of that register with GDB the result is:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;(gdb) p/x *0x10001014
$3 = 0xf8000&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;That matches the start address from secure_bootloader_gcc_nrf52.ld:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;MEMORY
{
  FLASH (rx) : ORIGIN = 0xf8000, LENGTH = 0x6000
  RAM (rwx) :  ORIGIN = 0x20000008, LENGTH = 0x3fff8
  uicr_bootloader_start_address (r) : ORIGIN = 0x10001014, LENGTH = 0x4
  bootloader_settings_page (r) : ORIGIN = 0x000FF000, LENGTH = 0x1000
  uicr_mbr_params_page (r) : ORIGIN = 0x10001018, LENGTH = 0x4
  mbr_params_page (r) : ORIGIN = 0x000FE000, LENGTH = 0x1000
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Here is the memory layout from the linker script I use for the application code:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;MEMORY
{
  FLASH (rx) : ORIGIN = 0x1000, LENGTH = 0xff000
  RAM (rwx) :  ORIGIN = 0x20000008, LENGTH = 0x3fff8
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Buttonless DFU works on dev kits but not on custom board</title><link>https://devzone.nordicsemi.com/thread/332831?ContentTypeID=1</link><pubDate>Wed, 06 Oct 2021 12:16:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:52d76b20-f773-4bb5-bc90-43261049a27e</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Carlos&lt;/p&gt;
&lt;p&gt;It could be that the bootloader start address is not added correctly to the UICR,&amp;nbsp;which the bootloader will not run without.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In order to check this, could you run the following command when you have a debugger connected to your board, and let me know what you get in return?&lt;/p&gt;
&lt;p&gt;&lt;em&gt;nrfjprog --memrd 0x10001014&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>