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

Firmware flashing using JLinkExe

I'm using JLinkExe (J link commander) for Linux to flash the application firmware on NRF51822_QF_AA target. The following have worked so far, but I'd like to confirm and have some doubts. The typical JLinkExe session invoked as root on my Linux system is as below:

$ sudo JLinkExe
.....................
Info: Found Cortex-M0 r0p0, Little endian.
Info: FPUnit: 4 code (BP) slots and 0 literal slots
Info: CoreSight components:
Info: ROMTbl 0 @ F0000000
.......................
......................
......................
Cortex-M0 identified.
Target interface speed: 100 kHz

J-Link>si 1
J-Link>speed 2000
J-Link>device nrf51822
J-Link>loadbin testing.bin 0x16000
J-Link>r
J-Link>g
J-Link>exit

The reason, I pass

0x16000

as the address to loadbin, because this is the same load address that I've set in my linker configuration file under ~/nrf_sdk_v6.1.0/nrf51822/Source/templates/gcc/gcc_nrf51_s110_xxab.ld.

snip from gcc_nrf51_s110_xxab.ld:

SEARCH_DIR(.)
GROUP(-lgcc -lc -lnosys)

MEMORY
{
  FLASH (rx) : ORIGIN = 0x00016000, LENGTH = 0xA000 
  RAM (rwx) :  ORIGIN = 0x20002000, LENGTH = 0x2000 
}


INCLUDE "gcc_nrf51_common.ld"

I see the same load address in the final map file. snip from testing.map:

Memory Configuration

Name             Origin             Length             Attributes
FLASH            0x00016000         0x0002a000         xr
RAM              0x20002000         0x00002000         xrw
*default*        0x00000000         0xffffffff

My questions are:

  1. Is it correct way of doing, or Am I missing something ? According to this thread, I should invoke loadbin as

    J-Link>loadbin testing.bin 0
    
  2. In that same thread, what does, w4 4001e504 1 stands for and why is it needed? I'm not sure if I invoked it for the first time or not, but all other times, I'm not invoking that (w4 4001e504 1) command during flashing the application firmware .

    J-Link>w4 
    Syntax: w4 <Addr>, <Data>
    

My environment is:

  • Linux + ARM GNU Toolchain
  • Target: nrf51822QF_AA (256kB flash memory)
  • Flash utility: JLinkExe for Linux
  • Segger J-link interface between the target board and PC
  • Softdevice s110
  • Custom application firmware
  • FormerMember
    0 FormerMember

    If you see the datasheet w4 4001e504 1 means that 1 is written to the NVMC Config register, meaning write is enabled to the flash memory. This is necessary to write the binary to the flash by JLink.

    If you use a SoftDevice, the location that you flash the binary that you compile is at the address that you mentioned. Without Softdevice the binary must be flashed at location 0.

    Overall, with Softdevice follow the steps below:

    First you need to extract the uicr part and the rest of binary from the softdevice hex file. So run these two commands

    [path to the toolchain]/arm-none-eabi-objcopy -Iihex -O binary --remove-section .sec3 [softdevice.hex] _mainpart.bin
    [path to the toolchain]/arm-none-eabi-objcopy -Iihex -O binary --only-section .sec3 [softdevice.hex] _uicr.bin
    

    Replace text in [] with appropriate paths.

    Next flash these binaries in the appropriate location. For this with JLink

    • Set device to nrf51822
    • Set speed to 1000 (or any other that works)
    • w4 4001e504 1
    • loadbin [path]/_mainpart.bin 0
    • loadbin [path]/_uicr.bin 0x10001000 (I wonder why this address ;) )
    • loadbin [path]/_your_binary.bin 0x16000
    • r
    • g

    Making this a script for JLink is convenient. Even better is letting your Makefile create this script and run it with your generated binary. Hope this helps.

  • Thanks a ton @PrithviRaj Narendra for the detailed information. You also provided information about flashing softdevice. So far, I've been using nRFStudio on Windows to flash Softdevice. I'll soon try what you have suggested.

  • There is a little better: copy file 99-jlink.rules (part of the downloaded package) into /etc/udev/rules.d/ and it should work like a charm

Related