Restoring the MBED Bootloader to nRF52 Dongles

This is more or less a point form of the information available at Nordic’s Devzone. I do not trust external site links to stay valid, which is why it is repeated here.

The PCA10059 nRF52 dongle does not have an on-board J-Link like the nRF51 dongles before it, nor the PCA10056 “Arduino form factor” development kits. Instead, they ship with an Open USB Bootloader, which is basically the stock mbed bootloader, tweaked for this specific architecture. To restore this bootloader, you will need the pca10059_bootloader.zip from Nordic. I have attached a copy of this file to this wiki page.

Take the enclosed .hex file and, using a J-Link, flash it to the dongle. If you’re lucky, that is all that is needed.

The nRF52 Dongle is Unresponsive

This is where you end up if you are unlucky. The dongle defaults to high voltage mode, which uses the internal REG0 to create a 1.8V supply. This is, unfortunately, too low to be reprogrammed with the less expensive programmers. It is common to end up here if you performed a chip erase, or if you have reprogrammed UICR and accidentally reset the registers which configure REG0. Fortunately there is a fix:

SB1 and SB2 must be modified from their default state. The default state is with SB1 open and SB2 shorted. This supplies the nRF52 with the output of its internal regulator. In order to recover from the situation where the supply voltage is too low, short SB1 and cut SB2, and then supply an external 1.8-3.6V on the VDD_OUT castellated pin. You should then be able to reprogram the device with the bootloader (or any other program) and continue working with the device.

NOTE: It is important that SB1 and SB2 are not both shorted at the same time. This would connect the REGOUT0 regulator output to whatever your external supply is, and could very likely damage the regulator.

Creating Your Own Luck

In order to prevent the unfortunate situation where you cannot reprogram or debug the device because the REGOUT0 voltage is too low, you can add this snippet somewhere very early on in your program. It will reset REGOUT0 to 3.0V if it is not already set to that value. Note that it will reset the device once the regulator voltage has been changed:

 1if ((NRF_UICR->REGOUT0 & UICR_REGOUT0_VOUT_Msk) ==
 2    (UICR_REGOUT0_VOUT_DEFAULT << UICR_REGOUT0_VOUT_Pos)) {
 3    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen;
 4    while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
 5
 6    NRF_UICR->REGOUT0 = (NRF_UICR->REGOUT0 & ~((uint32_t)UICR_REGOUT0_VOUT_Msk)) |
 7                        (UICR_REGOUT0_VOUT_3V0 << UICR_REGOUT0_VOUT_Pos);
 8
 9    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren;
10    while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
11
12    // System reset is needed to update UICR registers.
13    NVIC_SystemReset();
14}

I go a step further in my own code, as I want P0.9 and P0.10 to be GPIO as opposed to NFC, which is the default:

 1/*
 2 * sets the REGOUT0 voltage to 3.3V
 3 * sets the P0.9/10 to GPIO (default is NFC)
 4 * only does this if the register is at its erased default
 5 * performs a system reset afterward
 6 */
 7static void _set_uicr(void)
 8{
 9        bool update;
10
11        update = false;
12        if ((NRF_UICR->REGOUT0 & UICR_REGOUT0_VOUT_Msk) == (UICR_REGOUT0_VOUT_DEFAULT << UICR_REGOUT0_VOUT_Pos)) {
13                update = true;
14        }
15
16        if ((NRF_UICR->NFCPINS & UICR_NFCPINS_PROTECT_Msk) == (UICR_NFCPINS_PROTECT_NFC << UICR_NFCPINS_PROTECT_Pos)) {
17                update = true;
18        }
19
20        if (update) {
21                NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen;
22                while (NRF_NVMC->READY == NVMC_READY_READY_Busy) ;
23
24                NRF_UICR->REGOUT0 = (NRF_UICR->REGOUT0 & ~((uint32_t)UICR_REGOUT0_VOUT_Msk)) | (UICR_REGOUT0_VOUT_3V3 << UICR_REGOUT0_VOUT_Pos);
25                NRF_UICR->NFCPINS = UICR_NFCPINS_PROTECT_Disabled;
26
27                NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren;
28                while (NRF_NVMC->READY == NVMC_READY_READY_Busy) ;
29
30                NVIC_SystemReset();
31        }
32}

pca10059_bootloader.zip (43.3 KB) Andrew Kohlsmith, 08/21/2019 09:44 AM

nrf52-dongle-bootloader.pdf (448 KB) Andrew Kohlsmith, 08/21/2019 09:44 AM

nRF52840_dongle_back.svg (75.3 KB) Andrew Kohlsmith, 08/21/2019 09:44 AM

nRF52840_dongle_front.svg (134 KB) Andrew Kohlsmith, 08/21/2019 09:44 AM

configuring_external_power_source.svg (89.2 KB) Andrew Kohlsmith, 08/21/2019 09:44 AM

Add picture from clipboard (Maximum size: 1 GB)