<?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>NRF52840 Memory Layout</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/103556/nrf52840-memory-layout</link><description>Hi guys, I&amp;#39;m leading a project with the nrf52840 dongle connected to a Raspberry Pi via the GPIO header. 
 The firmware updating options for the Nordic are a bit limited in the sense that the dongle needs DFU via USB port and I don&amp;#39;t want to make this</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 07 Sep 2023 14:06:37 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/103556/nrf52840-memory-layout" /><item><title>RE: NRF52840 Memory Layout</title><link>https://devzone.nordicsemi.com/thread/444975?ContentTypeID=1</link><pubDate>Thu, 07 Sep 2023 14:06:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6e25b40a-00a8-40e4-a812-e1246b8c7d9b</guid><dc:creator>Fernando Fontes</dc:creator><description>&lt;p&gt;Thank you. Now I have full understanding thanks to you.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 Memory Layout</title><link>https://devzone.nordicsemi.com/thread/444972?ContentTypeID=1</link><pubDate>Thu, 07 Sep 2023 13:59:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0fc6bba8-a3b3-4c86-883e-717801a78b4b</guid><dc:creator>Vidar Berg</dc:creator><description>[quote userid="105292" url="~/f/nordic-q-a/103556/nrf52840-memory-layout/444967"]There is an erase all command. But the reason I don&amp;#39;t want to do it is exactly because of the REGOUT0 register. That part is still a bit confusing to me. How can I enable it before Softdevice?[/quote]
&lt;p&gt;If you need to set it before the softdevice, then you will need use the debugger to write to it. Otherwise, you can run the code snippet I posted before initializing the Softdevice. This will update the register setting on first startup (UICR is in NV memory, so it will only need to be set once).&lt;/p&gt;
[quote userid="105292" url="~/f/nordic-q-a/103556/nrf52840-memory-layout/444967"]code on my application and since the softdevice will call the application the REGOUT0 gets updated&amp;nbsp;and after SystemReset&amp;nbsp;the voltage gets fixed again?[/quote]
&lt;p&gt;Yes.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 Memory Layout</title><link>https://devzone.nordicsemi.com/thread/444967?ContentTypeID=1</link><pubDate>Thu, 07 Sep 2023 13:52:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:19b6aab1-95be-40f2-b9f5-40dfd44251bc</guid><dc:creator>Fernando Fontes</dc:creator><description>&lt;p&gt;Ok now it is a lot clear to me. So right now the reason why it is working is because I&amp;#39;ve erased the memory from address 0x27000 with len of 0xD9000. No bootloader on 0xE0000 and softdevice points the application to 0x27000. However, if for some reason I write something to 0xE0000 it will stop working. Go it.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;There is an erase all command. But the reason I don&amp;#39;t want to do it is exactly because of the REGOUT0 register. That part is still a bit confusing to me. How can I enable it before Softdevice? Isn&amp;#39;t the softdevice that runs first and then calls the program region 0x27000? Or your suggestion is to put that code on my application and since the softdevice will call the application the REGOUT0 gets updated&amp;nbsp;and after SystemReset&amp;nbsp;the voltage gets fixed again?&lt;/p&gt;
&lt;p&gt;Best,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 Memory Layout</title><link>https://devzone.nordicsemi.com/thread/444958?ContentTypeID=1</link><pubDate>Thu, 07 Sep 2023 13:37:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e87cf869-20d5-4bc5-a6ee-62f20c2077b8</guid><dc:creator>Vidar Berg</dc:creator><description>[quote userid="105292" url="~/f/nordic-q-a/103556/nrf52840-memory-layout/444951"]Ok, so I can do something like: `flash erase_address 0x27000 0xD9000` to delete current APP and Bootloader and then `flash write_bank 0 nrf52840_xxaa.bin 0x27000` to set the new app?&amp;nbsp;[/quote]
&lt;p&gt;The problem with that is that you will still have the bootloader start address stored in the UICR @ 0x10001014 which signals the MBR that a bootloader is present. In other words, when erasing the bootloader, you will also need to erase the UICR.&amp;nbsp;&lt;/p&gt;
[quote userid="105292" url="~/f/nordic-q-a/103556/nrf52840-memory-layout/444955"]That seems to work[/quote]
&lt;p&gt;It will work as long as the flash is erased @ 0xE0000, but if the application reaches this address, the MBR&amp;nbsp;may think that a bootloader is present and try to boot it from that address.&lt;/p&gt;
[quote userid="105292" url="~/f/nordic-q-a/103556/nrf52840-memory-layout/444955"]Is the MBR that holds that information?[/quote]
&lt;p&gt;The entry point after reset is always 0x0, for more details, please refer to the&amp;nbsp;&lt;a class="" 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=5_7_3_0_11_2"&gt;Master boot record and SoftDevice reset procedure&lt;/a&gt;&amp;nbsp;section of the softdevice specification.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m not familiar with openocd, and got a 404 error when I tried to access the documentation now, but I assume it should have an &amp;#39;eraseall&amp;#39; command to erase the chip so you can just re-program the Softdevice and app.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;With regards to the&amp;nbsp;&lt;a title="REGOUT0" href="https://infocenter.nordicsemi.com/topic/ps_nrf52840/uicr.html?cp=5_0_0_3_4_0_7#register.REGOUT0"&gt;REGOUT0&lt;/a&gt;&lt;span&gt;&amp;nbsp; register, it can also be set at runtime before enabling the Softdevice:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    // Configure UICR_REGOUT0 register only if it is set to default value.
    if ((NRF_UICR-&amp;gt;REGOUT0 &amp;amp; UICR_REGOUT0_VOUT_Msk) ==
        (UICR_REGOUT0_VOUT_DEFAULT &amp;lt;&amp;lt; UICR_REGOUT0_VOUT_Pos))
    {
        NRF_NVMC-&amp;gt;CONFIG = NVMC_CONFIG_WEN_Wen;
        while (NRF_NVMC-&amp;gt;READY == NVMC_READY_READY_Busy){}

        NRF_UICR-&amp;gt;REGOUT0 = (NRF_UICR-&amp;gt;REGOUT0 &amp;amp; ~((uint32_t)UICR_REGOUT0_VOUT_Msk)) |
                            (UICR_REGOUT0_VOUT_3V0 &amp;lt;&amp;lt; UICR_REGOUT0_VOUT_Pos);

        NRF_NVMC-&amp;gt;CONFIG = NVMC_CONFIG_WEN_Ren;
        while (NRF_NVMC-&amp;gt;READY == NVMC_READY_READY_Busy){}

        // System reset is needed to update UICR registers.
        NVIC_SystemReset();
    }&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 Memory Layout</title><link>https://devzone.nordicsemi.com/thread/444955?ContentTypeID=1</link><pubDate>Thu, 07 Sep 2023 13:26:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2301a7ff-15c2-42ca-8fac-936e00c206d1</guid><dc:creator>Fernando Fontes</dc:creator><description>&lt;p&gt;That seems to work but I&amp;#39;m a bit confused how the MCU knows where the program region is. Is the MBR that holds that information? With the program region pointed to the address 0x27000?&lt;br /&gt;&lt;br /&gt;Nevertheless, I might need to preserve the bootloader. Without the bootloader I&amp;#39;m not able to halt de NRF now. I&amp;#39;m receiving `[nrf52840.cpu] external reset detected` after trying to halt it... I was only able to halt it when in booloader (DFU) mode.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 Memory Layout</title><link>https://devzone.nordicsemi.com/thread/444951?ContentTypeID=1</link><pubDate>Thu, 07 Sep 2023 13:18:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5a5d78f9-fd42-4975-af45-cd9254bc5cf8</guid><dc:creator>Fernando Fontes</dc:creator><description>&lt;p&gt;Ok, so I can do something like: `flash erase_address 0x27000 0xD9000` to delete current APP and Bootloader and then `flash write_bank 0 nrf52840_xxaa.bin 0x27000` to set the new app?&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: NRF52840 Memory Layout</title><link>https://devzone.nordicsemi.com/thread/444947?ContentTypeID=1</link><pubDate>Thu, 07 Sep 2023 13:14:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:99cd9855-4c24-4f42-8f64-0085885f4759</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;The start address will remain the same if you use the Softdevice. If not, you can place it at address 0x0 and overwrite the MBR.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 Memory Layout</title><link>https://devzone.nordicsemi.com/thread/444946?ContentTypeID=1</link><pubDate>Thu, 07 Sep 2023 13:13:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2f4a3162-e871-4048-95a9-14f0e87510cf</guid><dc:creator>Fernando Fontes</dc:creator><description>&lt;p&gt;Ok, I was already thinking that it might be something related to either CRC or missing writes to specify where the end/start of the program would be.&lt;/p&gt;
&lt;p&gt;If I delete the bootloader, at what address should I write the program for it to start?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 Memory Layout</title><link>https://devzone.nordicsemi.com/thread/444939?ContentTypeID=1</link><pubDate>Thu, 07 Sep 2023 13:08:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6b06ed72-d271-45f3-8d59-ee02a966b066</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Sorry, another thing I forgot to mention is that the bootloader performs a checksum validation of the app image before booting it. This checksum is typically updated during the DFU process. Therefore, I believe the simplest approach would be to erase the bootloader after all. The other option is to re-program the Bootloader settings page (see&amp;nbsp; &lt;a title="Generating and displaying bootloader settings" href="https://infocenter.nordicsemi.com/topic/ug_nrfutil/UG/nrfutil/nrfutil_settings_generate_display.html?cp=11_8_6"&gt;Generating and displaying bootloader settings&lt;/a&gt;) with the new CRC value and&amp;nbsp;flash it along with the application hex file. But then you will depend on nrfutil being installed on your Pi to generate the settings page.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 Memory Layout</title><link>https://devzone.nordicsemi.com/thread/444930?ContentTypeID=1</link><pubDate>Thu, 07 Sep 2023 12:46:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:986e3b22-a597-4544-8a1a-ab33f0bee5a5</guid><dc:creator>Fernando Fontes</dc:creator><description>&lt;p&gt;Hi,&lt;br /&gt;Well, the bootloader is not a problem. It can stay as it is. I just want to be able to safely update the dongle using the GPIOs of the raspberry Pi since I will make a HAT for the dongle.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;For that openocd seems to be the way. I&amp;#39;ve successfully erased the program partition without messing with the bootloader thanks to your answer. The only thing that is missing now is the write command. It writes and verifies&amp;nbsp;OK but then the program does not boot. Am I missing something? I&amp;#39;m just writing the hex file.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 Memory Layout</title><link>https://devzone.nordicsemi.com/thread/444896?ContentTypeID=1</link><pubDate>Thu, 07 Sep 2023 11:19:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ec8cd3e7-dda7-4bc3-be35-4b1c80f2f5ca</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Yes, if you want to keep the bootloader. Also, I forgot to add earlier that if you want to remove the bootloader, you should do a full chiperase to erase the bootloader starting address stored in UICR/MBR to prevent the MBR from trying to boot a non-existent bootloader on subsequent startup. If you do this, it is also important that you update the&amp;nbsp;&lt;a title="REGOUT0" href="https://infocenter.nordicsemi.com/topic/ps_nrf52840/uicr.html?cp=5_0_0_3_4_0_7#register.REGOUT0"&gt;REGOUT0&lt;/a&gt;&amp;nbsp;register before resetting to keep the IO voltage at 3 volts.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 Memory Layout</title><link>https://devzone.nordicsemi.com/thread/444891?ContentTypeID=1</link><pubDate>Thu, 07 Sep 2023 11:05:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fcf2c233-d33b-467b-9d1e-1e0f68a18a20</guid><dc:creator>Fernando Fontes</dc:creator><description>&lt;p&gt;Hi Vidar Berg,&lt;/p&gt;
&lt;p&gt;Thank you for the reply.&lt;/p&gt;
&lt;p&gt;So this means that the actual program&amp;nbsp;length should be:&amp;nbsp;B9000 instead of D9000?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thank you,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 Memory Layout</title><link>https://devzone.nordicsemi.com/thread/444887?ContentTypeID=1</link><pubDate>Thu, 07 Sep 2023 11:00:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ae200933-fe8a-4188-83e5-ff346a208f59</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;The bootloader occupies the end of the flash, starting from address 0xE0000. This means the bootloader has been erased in your case. If you want to restore it, you can program the hex file provided at the end of this tutorial&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/guides/short-range-guides/b/getting-started/posts/nrf52840-dongle-programming-tutorial"&gt;nRF52840 Dongle Programming Tutorial&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
[quote user=""]&lt;span&gt;Also, do you know in what region of the memory are the&amp;nbsp;&lt;/span&gt;&lt;span&gt;User Information Configuration Registers (UICR)? I want to avoid deleting it or erasing it by mistake since it would make the regulator use 1.8V instead of 3V.&lt;/span&gt;[/quote]
&lt;p&gt;The UICR starts at address 0x10001000, so it is mapped to a different memory range than the FLASH.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Vidar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>