| nRF5 SDK v12.0.0 |

Choose documentation: | nRF5 SDK | S130 SoftDevice API | S132 SoftDevice API | S212 SoftDevice API | S332 SoftDevice API

All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
UICR Config Example

This example shows how to include UICR values into the application hex file. Also, it shows how to set up Keil to download and debug the generated hexfile.

The project uses `uicr_config.h` to define the User Information Configuration Registers (UICR) values to be included into the hex file.

The file declares one variable per register of the UICR area and informs the linker where to place them. To include the desired value in the desired address, uncomment the variable with the proper address at the target area and update the assignment value. As shown below, the UICR register with address 0x10001080 will be assigned the value 0x12345678.

const uint32_t UICR_ADDR_0x80 __attribute__((at(0x10001080))) __attribute__((used)) = 0x12345678;
// const uint32_t UICR_ADDR_0x84 __attribute__((at(0x10001084))) __attribute__((used)) = 0xFFFFFFFF;
// const uint32_t UICR_ADDR_0x88 __attribute__((at(0x10001088))) __attribute__((used)) = 0xFFFFFFFF;

When compiling the project with the uicr_config.h stated above, it will add the section shown below into the hex. The following two lines (intel hex format) show that we have successfully generated a hex file that will fill the value 0x12345678 into the UICR address.

:020000041000EA
:041080007856341258

Note that UICR values are stored in a reserved area of the flash and should only be stored into when downloading a hex file. Do not use these defined variables to store data at run time.

Note
  The file uses one non-standard attribute ("at"). It will only function with the ARMCC compiler toolset.

You can find the source code and the project file of the example in the following folder: `<InstallFolder>\examples\peripheral\uicr_config`

# Keil Configuration

The generated hex file will fail to download when using the standard download algorithm. Therefore, you must add a programming algorithm that handles the programming of the UICR.

To configure Keil to not use the standard download algorithm, follow these steps:

1. Open "Target Options" by selecting the target in the project window and then pressing Alt+F7.
2. Select the Utilities tab.
3. The following steps differ depending on the device that you use:
   - If you are using an nRF52 Series device:
     1. Make sure that "Use Target Driver for Flash Programing" is selected.
        Use Target Driver for Flash Programing
     2. Click the Settings button.
        Target Driver Setup
     3. If the programming algorithm nRF52xxx_UICR is not included in the list, you must add it:
        1. Click the Add button.
        2. Select nRF52xxx_UICR from the list of programming algorithms and click Add.
           Add Flash Programming Algorithm
     4. On the Flash Download tab, select nRF52xxx_UICR and click OK.
        Select nRF52xxx_UICR programming algorithm

   - If you are using an nRF51 Series device:

     1. Select the radio button "Use External Tool for Flash Programming".
     2. As command, fill in `nrfjprog.exe`. nrfjprog.exe is a tool that is installed with the MDK. It must be located in the system path.
     3. Fill in the arguments. Note that the following configuraton applies to nRF51422 without a SoftDevice:
        Example settings for nRF51422
     1. If an error occurs, see the following table:

        Error | Solution
        --- | ---
        No Algorithm found for: 10001014H - 10001017H Partial Erase Done (areas with no algorithms skipped!) No Algorithm found for: 10001014H - 10001017H | Those error messages are seen when trying to flash with the J-Link Target Driver, because it does not support writing of UICR. Use `nrjjprog.exe` instead.
        Error: failed to execute '"nrfjprog.exe" ..... | nrfjprog.exe could not be found in the Windows path. Add nrfjprog.exe to the Windows %PATH% variable or specify the full path to nrfjprog in Keil-'Options for Target'-'Utilities' as seen above.

# Testing

Test the UICR Configuration Example application by performing the following steps:

1. Compile and program the application with the special programming algorithm as described in Keil Configuration.
2. Verify that the UICR register with the address 0x10001080 has been assigned the value 0x12345678 with this nrfjprog command (for nRF51 Series devices, change "NRF52" to "NRF51"):
   nrfjprog -f NRF52 --memrd 0x10001080 --n 4