nRF51 SDK: UICR Config Example

| nRF51 SDK

- Home
- Related Pages
- API Reference
- Data Structures

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, shows how to setup Keil to download and debug the hexfile generated.

The project uses the "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 two lines (intel hex format) shows that we have successfully generated a hex file which 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.

The hex file generated when this file is included will fail to download when using the standard download algorithm provided by Nordic. How to configure Keil to download the hex is shown below.

# Keil Configuration

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

- Open "Target Options" by selecting the target in the project window, then pressing Alt+F7.
- Select the tab labeled "Utilities".
- Select the radio button "Use External Tool for Flash Programming".
- Fill in "nrfjprog.exe" in the "Command" text field.
- Fill "Arguments" according to the chip variant and use of SoftDevice (See below).

`nrfjprog.exe` is an extra tool installed with the SDK. And will be located in system path.

## nrf51422 256K with S210 SoftDevice (ANT)

Figure 1: Example settings for nrf51422.

## nrf51822 128K/256K without SoftDevice

Figure 2: Example settings for nrf51822 without SoftDevice.

## nrf51822 128K/256K with S110 SoftDevice (BLE)

Figure 3: Example settings for nrf51822 with SoftDevice.

# Troubleshooting

This section covers some known issues and their solution for the UICR example project

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, as it does not support writing of UICR. Use `nrjjprog.exe` instead.
— Error: failed to execute '"nrfjprog.exe" ..... | nrfjprog.exe could not be found in windows path. Add nrfjprog.exe to windows %PATH% or specify full path to nrfjprog in Keil-'Options for Target'-'Utilities' as seen in the above figures.

# Testing

The UICR Configuration can be tested as follows:

1. Compile and program the application with the chip variant configuration 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:
   nrfjprog --memrd 0x10001080 --n 4