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

APPROTECT FEATURE ON FIRMWARE WITH FREERTOS.

Hello Everyone, 

                       I am working on NRF52840 and we had enabled the APPROTECT feature in our firmware. The code for implementing this is as follows:-

void init_mem(void)

{

   if (NRF_UICR->APPROTECT == 0xFFFFFFFF)
   {
      NRF_LOG_INFO("PROTECTING FIRMWARE...SETTING APPROTECT");
      nrf_nvmc_write_word((uint32_t)&(NRF_UICR->APPROTECT), 0xFFFFFF00);

      NVIC_SystemReset();
   }

}

static void nrf_nvmc_write_word(uint32_t address, uint32_t value)
{
// Enable write.
NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen;
__ISB();
__DSB();

*(uint32_t*)address = value;
while (NRF_NVMC->READY == NVMC_READY_READY_Busy) {;}

NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren;
__ISB();
__DSB();
}

This code was working fine in our device. Recently we had updated the code and introduced FREERTOS in it. Now this particular APPROTECT feature is implemented in a particular device_init() task. After introducing FREERTOS, this feature of APPRTOTECT is not working anymore. Moreover, when I try to write the APPROTECT register in firmware, the device hangs totally and nothing works. Also in the logs, i get a message "SOFTDEVICE: INVALID MEMORY ACCES" after I try to write the register. Please help me what might be the issue??

Parents
  • Hi,

    This is not related to FreeRTOS specifically, not even APPROTECT. You get the invalid memory access error because you write directly to flash after the SoftDevice has been enabled. The key point here is that you need to do this before you enable the SoftDevice. I suggest you do this also before starting the FreeRTOS scheduler.

    Note that enabling APPROTECT only needs to happen once, as it is a persistent field in the UICR. You can either do it in production programming, by making it included in the hex file or you check to see if it is enabled, if not write it and reset. The next time, and all subsequent times it will be enabled and no more writes to flash will be needed. See for instance this post, or check the implementation of nrf_bootloader_debug_port_disable() in <nRF5 SDK 17>\components\libraries\bootloader\nrf_bootloader_info.c.

Reply
  • Hi,

    This is not related to FreeRTOS specifically, not even APPROTECT. You get the invalid memory access error because you write directly to flash after the SoftDevice has been enabled. The key point here is that you need to do this before you enable the SoftDevice. I suggest you do this also before starting the FreeRTOS scheduler.

    Note that enabling APPROTECT only needs to happen once, as it is a persistent field in the UICR. You can either do it in production programming, by making it included in the hex file or you check to see if it is enabled, if not write it and reset. The next time, and all subsequent times it will be enabled and no more writes to flash will be needed. See for instance this post, or check the implementation of nrf_bootloader_debug_port_disable() in <nRF5 SDK 17>\components\libraries\bootloader\nrf_bootloader_info.c.

Children
No Data
Related