Writing data

When writing is enabled, the NVM is written by writing a word to a word-aligned address in the code or UICR. Only word-aligned writes are allowed. Byte or half-word-aligned writes will result in a hard fault.

To write the data into flash using the standard SWD Arm® CoreSight™ DAP protocol:

  1. Write the value 0x00000001 to the CONFIG register (0x4001E504) of the NVMC.
    This will configure the NVM for writing.
  2. Read the READY register (0x4001E400) of the NVMC until the value is 0x00000001.
    When this value is read, the NVMC is ready and not currently performing any operations.
  3. Write the data to the desired, word-aligned address.
  4. Read the READY register (0x4001E400) of the NVMC until the value is 0x00000001 before continuing to ensure the write operation has completed.
  5. Continue writing and then reading the READY register (0x4001E400) as necessary.
  6. Write the value 0x00000000 to the CONFIG register (0x4001E504) of the NVMC.

    This will configure the NVM back to read only.

    The ranges of writeable addresses are:

    • UICR addresses (located in addresses 0x10001000 through 0x10002000)
      Important: These addresses must be writeable by the production programming tools. Users expect these to be written when the hex file is programmed by the programmer. It is bad practice for application to write these values at run time.
    • All program flash (located in addresses 0x00000000 through ((CODESIZE * CODEPAGESIZE) – 0x00000004)

      Different methods can be used to write flash. For the nRF52, a good flash algorithm should take around 10 seconds to write the entire flash. If you are not able to reach this time, contact Nordic Semiconductor for assistance.