These are my notes on J-link debugging, mostly for ARM.

Software

Head over to the jlink downloads page to grab the latest software for your platform.

Install the package then connect your debugger.

Pinout

I just used some Dupont jumper cables to connect the SWD lines. You could get one of these breakout boards, but that seems unnecessary.

You would connect the Dupont cables like this. Note that when using the grey 20 pin Jtag cable, the pinout should be viewed from the "back".

SWD

Here is an example SWD connection. I check that my J-Link was sending 3.3v on the VCC pin, and I think this is standard, but if you want to be sure, double check it before connecting.

Where:

RED <-> VCC
YELLOW <-> GND
BLUE <-> SWDIO
GREEN <-> SWDCLK
ORANGE <-> RESET

Here is an example connection to the FlySky FS-i6.

Flashing

Find your device in the device list.

Once you know the device, run JLinkExe from your terminal. These examples are from my mac, using the MKL16Z64VLH4 I was working with in my FlySky FS-i6 hacking guide.

Create a file, it doesn't matter what it's called. I'll call mine dump.jtag and put this in it:

si 1
speed 4000
device MKL16Z64XXX4
r
h
savebin fsi6.bin, 0x0, 0x10000
exit

Note that the syntax for savebin is filename, start addr, size. Our target has 64kb of flash.

Then run:

JLinkExe -CommanderScript dump.jtag

Now you should have a file called fsi6.bin

You can run xxd fsi6.bin > fsi6.txt to see a readable output of the binary.

Make any edits and run xxd -r fsi6.txt > modified-fsi6.bin

Then create another file called loadbin.jlink with the contents:

si 1
speed 4000
device MKL16Z64XXX4
r
h
loadbin modified-fsi6.bin
exit

To just connect to the target, run:

JLinkExe -device MKL16Z64xxx4
si 1
speed 4000
r
h

You'll see:

› JLinkExe -device MKL16Z64xxx4
...
Type "connect" to establish a target connection, '?' for help
J-Link>si 1
Selecting SWD as current target interface.
J-Link>speed 4000
Selecting 4000 kHz as target interface speed
J-Link>r
Target connection not established yet but required for command.
Device "MKL16Z64XXX4" selected.


Found SWD-DP with ID 0x0BC11477
Found SWD-DP with ID 0x0BC11477
AP-IDR: 0x04770031, Type: AHB-AP
Found Cortex-M0 r0p0, Little endian.
FPUnit: 2 code (BP) slots and 0 literal slots
CoreSight components:
ROMTbl 0 @ F0002000
ROMTbl 0 [0]: FFFFE000, CID: B105900D, PID: 000BB932 MTB-M0+
ROMTbl 0 [1]: FFFFF000, CID: B105900D, PID: 0008E000 MTBDWT
ROMTbl 0 [2]: F00FD000, CID: B105100D, PID: 000BB4C0 ROM Table
ROMTbl 1 @ E00FF000
ROMTbl 1 [0]: FFF0F000, CID: B105E00D, PID: 000BB008 SCS
ROMTbl 1 [1]: FFF02000, CID: B105E00D, PID: 000BB00A DWT
ROMTbl 1 [2]: FFF03000, CID: B105E00D, PID: 000BB00B FPB
Cortex-M0 identified.
Reset delay: 0 ms
Reset type NORMAL: Resets core & peripherals via SYSRESETREQ & VECTRESET bit.
J-Link>h
PC = 000001A0, CycleCnt = 00000000
R0 = 80000000, R1 = 40000000, R2 = 00000004, R3 = 0000FF00
R4 = 40076000, R5 = 40008100, R6 = 00000001, R7 = 200015F0
R8 = 3FBFDFDF, R9 = FF5EFFBF, R10= 0000F3D4, R11= 0000F3D4
R12= BFFBFEFF
SP(R13)= 20001460, MSP= 20001460, PSP= FF4FEFF8, R14(LR) = 0000A311
XPSR = A1000000: APSR = NzCvq, EPSR = 01000000, IPSR = 000 (NoException)
CFBP = 00000000, CONTROL = 00, FAULTMASK = 00, BASEPRI = 00, PRIMASK = 00