Writing data - SECUREAPPROTECT enabled

Use the standard Serial Wire Debug (SWD) Arm® CoreSight™ Debug Access Port (DAP) protocol to write data into flash.

  1. Check the corresponding SPU.FLASHREGION[n].PERM (0x4003600 + (n*4)), where n is the flash page.
    If the 4th bit is ‘0’, the flash region is in non-secure, otherwise it is secure. With Secure Access Port Protection (SECUREAPPROTECT) enabled, secure flash regions cannot be written to.
  2. Write the value 0x00000001 to the CONFIGNS register (0x400395084) of the Non-volatile Memory Controller (NVMC).
    This configures the non-volatile memory for writing.
  3. Read the READY register (0x40039400) of the NVMC until the value is 0x00000001.
    When this value is read, the NVMC is ready and not currently performing any operations.
  4. Write the data to the desired, word-aligned address.
  5. Read the READY register (0x40039400) of the NVMC until the value is 0x00000001 before continuing to ensure the write operation has completed.
  6. Continue writing and then reading the READY register (0x40039400) as necessary.
  7. Write the value 0x00000000 to the CONFIGNS register (0x40039584) of the NVMC.
    This configures the non-volatile memory back to read-only.
The range of writeable addresses are all program flash that is configured to be non-secure. The size and addresses of the non-secure flash are dependent on earlier programmed firmware.

You can write to flash using different methods. For nRF9160, a good flash algorithm should take around 10 seconds to write the entire flash . If you cannot achieve this time, contact Nordic Semiconductor for assistance.