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

Can I write to the UICR registers with a Segger and JLink?

I want to write a device ID to the UICR registers at the same time as I flash the app code. I don't use Keil or that nrfproj.exe thing, I'm on a Mac. I have these targets in my Makefile:

# Write the device ID to the start of the UICR registers. Replace 0x0123 below with the ID. w2 means write 16 bit items.
deviceid-write: deviceid-write.jlink
	$(JLINK) $(OUTPUT_PATH)deviceid-write.jlink
deviceid-write.jlink:
	echo "r\nw2 0x0000000010001080 0x0123\nr\nexit\n" > $(OUTPUT_PATH)deviceid-write.jlink
	
# Read the device ID from the start if the UICR registers, if it's there. mem8 means read 8 bit items.
deviceid-read: deviceid-read.jlink
	$(JLINK) $(OUTPUT_PATH)deviceid-read.jlink
deviceid-read.jlink:
	echo "r\nmem8 0x0000000010001080 0x2\nr\nexit\n" > $(OUTPUT_PATH)deviceid-read.jlink

The write fails with this output:

Processing script file...

Reset delay: 0 ms
Reset type NORMAL: Resets core & peripherals via SYSRESETREQ & VECTRESET bit.

Writing 0123 -> 10001080

Reset delay: 0 ms
Reset type NORMAL: Resets core & peripherals via SYSRESETREQ & VECTRESET bit.
Info: J-Link: Flash download: Flash programming performed for 1 range (1024 bytes)

****** Error: Programming failed @ address 0x10001080 (block verification error)
Verification failed @ address 0x10001000
Info: J-Link: Flash download: Total time needed: 0.113s (Prepare: 0.093s, Compare: 0.001s, Erase: 0.008s, Program: 0.002s, Verify: 0.000s, Restore: 0.007s)


Script processing completed.

Is this possible? I think I've done the same thing in the past with the bootloader address.

(Edit)

I also have a target for "erase-all":

erase-all: erase-all.jlink
    $(JLINK) $(OUTPUT_PATH)erase-all.jlink
erase-all.jlink:
    printf "w4 4001e504 2\nw4 4001e50c 1\nsleep 100\nr\nexit\n" > $(OUTPUT_PATH)erase-all.jlink

Do I need to run that, then write to the UICR, then flash the softdevice, then flash my code?

Parents
  • You cannot write to already written UICR register without erasing it. And to erase a register you need to erase everything if there is a softdevice. devzone.nordicsemi.com/.../

     if your old value is         0234(11101010'b), 
    then writing                  0123(01111011'b)            to this value will make it 
                                      ------------------------------------------------------
                                  0106(01101010'b)  -> could just toggle '1's to 0's
    

    That is why your write was completed but verification failed. because you wanted to write 0123 but it actually wrote and read 0106 in our example.

Reply
  • You cannot write to already written UICR register without erasing it. And to erase a register you need to erase everything if there is a softdevice. devzone.nordicsemi.com/.../

     if your old value is         0234(11101010'b), 
    then writing                  0123(01111011'b)            to this value will make it 
                                      ------------------------------------------------------
                                  0106(01101010'b)  -> could just toggle '1's to 0's
    

    That is why your write was completed but verification failed. because you wanted to write 0123 but it actually wrote and read 0106 in our example.

Children
Related