This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

[NRF81522] Can't enable Read Protection ALL (RBPCONF)

Hello,

I am trying to enable the read protection on the NRF51822 on a custom board. By looking through the forums, I found different ways to try and enable the read protection.

According to the reference manual, bits 8 to 15 from RBPCONF must be set to 1 in order to enable the read protection for all the chip. RBPCONF is a RW register, so we should be able to write to the register directly.

So using sd_flash_write, I have this function.

void UTILS_EnableReadProtection (void)
{
#ifdef RELEASE
uint32_t RegisterValue;

RegisterValue = ~(0x0000FF00);
// Check if read-back mechanism is turned ON.
if((uint32_t)((NRF_UICR->RBPCONF & UICR_RBPCONF_PALL_Msk) >> UICR_RBPCONF_PALL_Pos) != UICR_RBPCONF_PALL_Enabled) {
sd_flash_write((uint32_t *)&NRF_UICR->RBPCONF, &RegisterValue,1);
}
//nrf_nvmc_write_word(0x10001004, 0x0000FF00);
#endif
}

I tried both the method with sd_flash_write, or with nrf_nvmc_write_word to no avail. I tried with and without power cycle and still the same.

What am i missing here?

Thanks,

Jean-Francois

Parents
  • Hi,

    I tested this out, and using nrf_nvmc_write_word(0x10001004, 0x0000FF00); worked on my board (nRF51 DK/PCA10028). Note that the sd_flash_write will report an error if the destination is outside of the flash area, this function cannot be used for writing to UICR. You must write this register before enabling the softdevice, or disable the softdevice before doing the write.

    To be exact, I added this code and called the function from start of main():

    #define RELEASE
    
    void UTILS_EnableReadProtection (void)
    {
    #ifdef RELEASE
    // Check if read-back mechanism is turned ON.
    if((uint32_t)((NRF_UICR->RBPCONF & UICR_RBPCONF_PALL_Msk) >> UICR_RBPCONF_PALL_Pos) != UICR_RBPCONF_PALL_Enabled) {
    	nrf_nvmc_write_word(0x10001004, 0xFFFF0000);
    }
    #endif
    }

    Best regards,
    Jørgen

Reply
  • Hi,

    I tested this out, and using nrf_nvmc_write_word(0x10001004, 0x0000FF00); worked on my board (nRF51 DK/PCA10028). Note that the sd_flash_write will report an error if the destination is outside of the flash area, this function cannot be used for writing to UICR. You must write this register before enabling the softdevice, or disable the softdevice before doing the write.

    To be exact, I added this code and called the function from start of main():

    #define RELEASE
    
    void UTILS_EnableReadProtection (void)
    {
    #ifdef RELEASE
    // Check if read-back mechanism is turned ON.
    if((uint32_t)((NRF_UICR->RBPCONF & UICR_RBPCONF_PALL_Msk) >> UICR_RBPCONF_PALL_Pos) != UICR_RBPCONF_PALL_Enabled) {
    	nrf_nvmc_write_word(0x10001004, 0xFFFF0000);
    }
    #endif
    }

    Best regards,
    Jørgen

Children
  • So maybe my method of testing is wrong. When the protection is enabled, I shouldn't be able to use the SWD right? Because when I run this piece of code (the initial one), I can still JTAG in.

    If it makes a difference, I am using IAR 8.40.1

    How do you confirm that the read protection is correctly applied? Also, I see that you've put PR0 protection as well. It is not clear in the documentation, but I thought that only PALL was needed for a full protection.

    I will try your code in the meantime.

    Thanks,

    Jean-Francois

  • Setting RBPCONF will not prevent you from using the SWD interface, it will only prevent you from reading back content in flash. I used nrfjprog from verification:

    $ nrfjprog --recover
    Recovering device. This operation might take 30s.
    Erasing user code and UICR flash areas.
    
    $ nrfjprog --memrd 0x10001004
    0x10001004: FFFFFFFF                              |....|
    
    ## Flash FW here
    
    $ nrfjprog --memrd 0x10001004
    0x10001004: FFFF00FF                              |....|
    
    $ nrfjprog --memrd 0x1000
    ERROR: The operation attempted is unavailable due to readback protection in
    ERROR: your device. Please use --recover to unlock the device.

    I set both for testing purposes, as you can see above, PALL is sufficient to enable readback protection for full chip. PR0 can be used to protect only the region from 0x0 to the number of pages set in UICR->CLENR0 register.

  • So as a side problem, I thought i bricked my chip before, but turns out that nrfjprog isn't working properly on my machine.

    [2020-Oct-07 09:37:47] [ info] --------------------------------------------------------------------------------
    [2020-Oct-07 09:37:47] [ info] C:\Program Files\Nordic Semiconductor\nrf-command-line-tools\bin\nrfjprog.exe --memrd 0x100010004 --log 
    [2020-Oct-07 09:37:47] [ info] nrfjprog version 10.10.0 
    [2020-Oct-07 09:37:47] [ info] --------------------------------------------------------------------------------
    [2020-Oct-07 09:37:47] [debug] [ nRF0x0] - open_dll
    [2020-Oct-07 09:37:47] [debug] [ nRF0x0] - Load library at C:\Program Files\Nordic Semiconductor\nrf-command-line-tools\bin\JLINKARM_UNKNOWN_NRFJPROG.dll.
    [2020-Oct-07 09:37:47] [debug] [ nRF0x0] - Library loaded, loading member functions.
    [2020-Oct-07 09:37:47] [debug] [ nRF0x0] - Member functions succesfully loaded.
    [2020-Oct-07 09:37:47] [debug] [Backend] - Logger callback at 0x7ff78dd660d0 registered in Segger backend logger.
    [2020-Oct-07 09:37:47] [debug] [  JLink] - [Debug   ] [JLink     ] Logger callback at 0x7ff78dd660d0 registered in JLink logger.
    [2020-Oct-07 09:37:47] [debug] [nRFUnknown] - Just_open_dll_tagged_callback
    [2020-Oct-07 09:37:47] [debug] [Backend] - open_dll
    [2020-Oct-07 09:37:47] [debug] [Backend] - No J-Link DLL path was provided. Attempting to auto detect.
    [2020-Oct-07 09:37:47] [debug] [Backend] - Load library at C:\Program Files (x86)\SEGGER\JLink\JLink_x64.dll.
    [2020-Oct-07 09:37:47] [debug] [Backend] - Library loaded, loading member functions.
    [2020-Oct-07 09:37:47] [debug] [Backend] - Member functions succesfully loaded.
    [2020-Oct-07 09:37:47] [debug] [Backend] - dll_version
    [2020-Oct-07 09:37:47] [debug] [Backend] - Segger dll version 6.84.a loaded.
    [2020-Oct-07 09:37:47] [debug] [Backend] - set_core_data
    [2020-Oct-07 09:37:47] [debug] [ nRF0x0] - enum_emu_snr
    [2020-Oct-07 09:37:47] [debug] [nRFUnknown] - Just_enum_emu_snr
    [2020-Oct-07 09:37:47] [debug] [Backend] - enum_emu_snr
    [2020-Oct-07 09:37:47] [debug] [Backend] - ---just_enum_emu_snr
    [2020-Oct-07 09:37:47] [debug] [Backend] - ---just_get_num_emus
    [2020-Oct-07 09:37:47] [debug] [ nRF0x0] - connect_to_emu_with_snr
    [2020-Oct-07 09:37:47] [debug] [nRFUnknown] - Just_connect_to_emu_with_snr
    [2020-Oct-07 09:37:47] [debug] [Backend] - connect_to_emu_with_snr
    [2020-Oct-07 09:37:47] [debug] [Backend] - is_connected_to_emu
    [2020-Oct-07 09:37:47] [debug] [Backend] - ---just_enum_emu_snr
    [2020-Oct-07 09:37:47] [debug] [Backend] - ---just_get_num_emus
    [2020-Oct-07 09:37:47] [debug] [Backend] - ---just_connect_to_emu_with_snr
    [2020-Oct-07 09:37:47] [debug] [Backend] - ---just_connect_to_emu_without_snr
    [2020-Oct-07 09:37:47] [debug] [Backend] - Segger logging enabled.
    [2020-Oct-07 09:37:47] [debug] [Backend] - ---just_load_core_data
    [2020-Oct-07 09:37:48] [debug] [ nRF0x0] - read_connected_emu_snr
    [2020-Oct-07 09:37:48] [debug] [nRFUnknown] - Just_read_connected_emu_snr
    [2020-Oct-07 09:37:48] [debug] [Backend] - read_connected_emu_snr
    [2020-Oct-07 09:37:48] [debug] [Backend] - is_connected_to_emu
    [2020-Oct-07 09:37:48] [debug] [ nRF0x0] - read_device_family
    [2020-Oct-07 09:37:48] [debug] [nRFUnknown] - Just_read_device_family
    [2020-Oct-07 09:37:48] [debug] [Backend] - is_connected_to_emu
    [2020-Oct-07 09:37:48] [debug] [Backend] - read_debug_port_idr
    [2020-Oct-07 09:37:48] [debug] [Backend] - read_debug_port_register
    [2020-Oct-07 09:37:48] [debug] [Backend] - ---just_read_debug_port_register
    [2020-Oct-07 09:37:48] [debug] [Backend] - coresight_configure
    [2020-Oct-07 09:37:48] [debug] [Backend] - JLinkARM.dll reported "-1", an unknown error.
    [2020-Oct-07 09:37:48] [debug] [Backend] - ---just_abort_debug_action
    [2020-Oct-07 09:37:48] [debug] [Backend] - Attempting to clear any configuration errors in debug port before closing connection. 
    [2020-Oct-07 09:37:48] [debug] [Backend] - JLinkARM.dll reported "-1", an unknown error.
    [2020-Oct-07 09:37:48] [debug] [ nRF0x0] - close_dll
    [2020-Oct-07 09:37:48] [debug] [nRFUnknown] - Just_close_dll
    [2020-Oct-07 09:37:48] [debug] [Backend] - close
    [2020-Oct-07 09:37:48] [debug] [Backend] - disconnect_from_emu
    [2020-Oct-07 09:37:48] [debug] [Backend] - is_connected_to_emu
    [2020-Oct-07 09:37:48] [debug] [Backend] - ---just_disconnect_from_emu
    [2020-Oct-07 09:37:48] [debug] [Backend] - is_connected_to_device
    [2020-Oct-07 09:37:48] [debug] [Backend] - ---just_is_debug_region_powered
    [2020-Oct-07 09:37:48] [debug] [Backend] - ---just_read_debug_port_register
    [2020-Oct-07 09:37:48] [debug] [Backend] - is_connected_to_emu
    [2020-Oct-07 09:37:48] [debug] [Backend] - ---just_write_debug_port_register
    [2020-Oct-07 09:37:48] [debug] [Backend] - JLinkARM.dll reported "-1", an unknown error.
    [2020-Oct-07 09:37:48] [debug] [Backend] - ---just_abort_debug_action
    [2020-Oct-07 09:37:48] [debug] [Backend] - Attempting to clear any configuration errors in debug port before closing connection. 
    [2020-Oct-07 09:37:48] [debug] [Backend] - JLinkARM.dll reported "-1", an unknown error.
    [2020-Oct-07 09:37:48] [debug] [Backend] - Segger Backend closed.

    I downloaded the latest version yesterday, so I am up to date with nrfjprog, but I can't use any commands with it, always the error above. 

    The installation instruction are pretty simple: run the install file and install Segger + nrfjprog, which I did. I have the Segger suite 6.84a that came with the nrfjprog 10.10.0. My probe is up to date according to J-Link Configurator 6.84a.

    What other trouble shooting steps do I need to do?

    Thanks,

    Jean-Francois

  • What is the error you get without the --log option?

    Do the board work with other computers? Are you using a nRF51 DK, or some custom board?

  • The error I am getting is this :

    PS C:\Users\Gagnonje> nrfjprog --memrd 0x100010004 --log
    ERROR: JLinkARM DLL reported an error. Try again. If error condition
    ERROR: persists, run the same command again with argument --log, contact Nordic
    ERROR: Semiconductor and provide the generated log.log file to them.

    The log file I posted above is the result of --log.

    This is a custom board with a     NRF51822. I can use all of the Segger tools on the custom board, but nrfjprog doesn't work. 

    I can JTAG in the board just fine on different computers and we've done the whole dev with the segger tools.

    I did not try nrfjprog on another computer.

    edit : Running powershell in admin doesn't make a difference, still the same errors

Related