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

UICR / FICR in linux

Hello Community,

Does anyone know how to read/write configuration registers (UICR, FICR) on nRF51822 in a linux environment ?

So far, I have to stick with Windows for these operations (nrfjprog, nRFgo Studio).

  • The way to do it is to download JLink and run it from the command line. I have described how to program and erase the nRF51 chip in this blog post. I have not tried manipulating the UICR or FICR, but it should be a normal register write. See the nRF51 reference manual to find the memory addresses.

  • I have never used nrfjprog or nrfgo studio, I do everything in gdb.

    I build the UICR data into a hex file and then just manually load it in gdb.

    With the rev2 silicon I never managed to get the NVMC_ERASEUICR to work, so I just do a eraseall prior to program UICR.

    From my gdb.jlink config file:

    set $NVMC_READY              = ((uint32_t*)0x4001E400)
    set $NVMC_CONFIG             = ((uint32_t*)0x4001E504)
    set $NVMC_ERASEALL           = ((uint32_t*)0x4001E50C)
    set $UICR_BOOTLOADERADDR     = ((uint32_t*)0x10001014)
    
    define wait-nvmc-ready
       if *$NVMC_READY != 1
           printf "Wait for NVMC_READY\n"
           while *$NVMC_READY != 1
               shell sleep 0.1
           end
       end
    end
    
    define erase-all
       mon halt
    
       wait-nvmc-ready
       printf "Erasing entire flash...\n"
       # 0=REN, 1=WEN, 2=EEN
       set *$NVMC_CONFIG    = 2  
    
       # 1=start chip erase
       set *$NVMC_ERASEALL  = 1
       wait-nvmc-ready
       mon sleep 500
    
       # 0=REN, 1=WEN, 2=EEN
       set *$NVMC_CONFIG    = 0
    
       mon reset
    
       printf "Done...\n"
    end
    
    define program-uicr
       mon halt
    
       printf "UICR.BOOTLOADERADRR = 0x%08X\n", *$UICR_BOOTLOADERADDR
    
       printf "Compile bin/xxx.UICR.hex\n"
       make bin/xxx.UICR.hex
    
       printf "Loading bin/xxx.UICR.hex\n"
       wait-nvmc-ready
    
       # 1=WEN
       set *$NVMC_CONFIG    = 1
    
       load bin/xxx.UICR.hex
       wait-nvmc-ready
       mon sleep 500
    
       # 0=REN
       set *$NVMC_CONFIG    = 0
    
       # verify
       printf "UICR.BOOTLOADERADRR    = 0x%08X\n", *$UICR_BOOTLOADERADDR
       printf "xxxInfoUICR.magic = 0x%08X\n", xxxInfoUICR.magic
       printf "xxxKeysUICR.magic = 0x%08X\n", xxxKeysUICR.magic
       printf "xxxKeysUICR.crc   = 0x%08X\n", xxxKeysUICR.crc
    end
    
  • Nice post. It works with the magic register writes and exit sequence, as follows : J-Link>w4 4001e504 2 J-Link>w4 4001e50c 1 J-Link>w4 10001014 00038000 J-Link>r J-Link>g

Related