| name | embedded-debug-tools |
| description | Debug and flash commands for nRF52 and STM32 development; OpenOCD, nrfjprog, STM32_Programmer_CLI, and J-Link. Use when flashing firmware, starting debug sessions, reading/writing memory, or connecting to targets. |
| allowed-tools | Bash |
| user-invocable | true |
Embedded Debug Tools
Commands for flashing, debugging, and inspecting nRF52 and STM32 targets.
Tool Overview
| Tool | Vendor | Targets | Primary Use |
|---|
| nrfjprog | Nordic | nRF51/52/53/91 | Flash, erase, reset |
| OpenOCD | Open Source | ARM Cortex-M | GDB server, flash |
| STM32_Programmer_CLI | ST | STM32 | Flash, OTP, option bytes |
| J-Link Commander | SEGGER | All ARM | Flash, RTT, SWO |
nrfjprog (Nordic)
Installation
export PATH="$PATH:/opt/nrf-command-line-tools/bin"
Common Commands
nrfjprog --ids
nrfjprog --eraseall
nrfjprog --program firmware.hex --verify
nrfjprog --snr 683123456 --program firmware.hex
nrfjprog --reset
nrfjprog --pinreset
nrfjprog --deviceversion
nrfjprog --memrd 0x10000000 --n 16
nrfjprog --memrd <address> --n <bytes>
nrfjprog --memwr <address> --val <value>
nrfjprog --recover
Programming Workflow
nrfjprog --eraseall && \
nrfjprog --program softdevice.hex --verify && \
nrfjprog --program application.hex --verify && \
nrfjprog --reset
Debug with GDB
JLinkGDBServer -device nRF52840_xxAA -if SWD -speed 4000
arm-none-eabi-gdb build/zephyr/zephyr.elf
(gdb) target remote localhost:2331
(gdb) monitor reset
(gdb) load
(gdb) break main
(gdb) continue
OpenOCD
Installation
sudo apt install openocd
brew install openocd
git clone https://github.com/openocd-org/openocd.git
cd openocd && ./bootstrap && ./configure && make && sudo make install
Configuration Files
ls /usr/share/openocd/scripts/
interface/stlink.cfg
interface/jlink.cfg
interface/cmsis-dap.cfg
target/stm32f4x.cfg
target/stm32l4x.cfg
target/nrf52.cfg
Starting OpenOCD
openocd -f interface/stlink.cfg -f target/stm32f4x.cfg
openocd -f interface/jlink.cfg -c "transport select swd" -f target/nrf52.cfg
openocd -f board/my_board.cfg
OpenOCD Commands (via telnet or GDB)
telnet localhost 4444
> reset halt
> flash write_image erase firmware.bin 0x08000000
> flash write_image erase firmware.hex
> verify_image firmware.bin 0x08000000
> reset run
> halt
> resume
> reg
> mdw 0x20000000 16
> mww 0x20000000 0x12345678
GDB with OpenOCD
openocd -f interface/stlink.cfg -f target/stm32f4x.cfg
arm-none-eabi-gdb build/firmware.elf
(gdb) target extended-remote localhost:3333
(gdb) monitor reset halt
(gdb) load
(gdb) break main
(gdb) continue
OpenOCD Config Example
# board/custom_stm32f4.cfg
source [find interface/stlink.cfg]
transport select hla_swd
source [find target/stm32f4x.cfg]
# Set flash size (for auto-detect issues)
set FLASH_SIZE 0x100000
# Increase adapter speed
adapter speed 4000
# Reset configuration
reset_config srst_only srst_nogate
STM32_Programmer_CLI
Installation
Part of STM32CubeProgrammer - download from ST website.
export PATH="$PATH:/opt/stm32cubeprogrammer/bin"
STM32_Programmer_CLI --version
Common Commands
STM32_Programmer_CLI --connect port=SWD --list
STM32_Programmer_CLI --connect port=SWD
STM32_Programmer_CLI --connect port=SWD --erasechip
STM32_Programmer_CLI --connect port=SWD --write firmware.hex --verify
STM32_Programmer_CLI --connect port=SWD --write firmware.bin 0x08000000 --verify
STM32_Programmer_CLI --connect port=SWD --read 0x08000000 0x10000 read.bin
STM32_Programmer_CLI --connect port=SWD --hardRst
STM32_Programmer_CLI --connect port=SWD --optionbytes display
STM32_Programmer_CLI --connect port=SWD -ob RDP=0xAA
Programming with Reset Modes
STM32_Programmer_CLI --connect port=SWD --mode UR --write firmware.hex --hardRst
STM32_Programmer_CLI --connect port=SWD --mode UR --reset HWrst
External Loader (for QSPI/external flash)
STM32_Programmer_CLI --connect port=SWD \
--extload "path/to/loader.stldr" \
--write firmware.bin 0x90000000 --verify
J-Link Commander
Installation
Download from SEGGER website.
JLinkExe
JLinkExe -device nRF52840_xxAA -if SWD -speed 4000 -autoconnect 1
Common Commands
J-Link> connect # Interactive connect
J-Link> device nRF52840_xxAA # Set device
J-Link> si SWD # Select interface
J-Link> speed 4000 # Set speed in kHz
J-Link> r # Reset and halt
J-Link> g # Go (run)
J-Link> h # Halt
J-Link> loadfile firmware.hex # Load hex file
J-Link> loadbin firmware.bin 0x0 # Load binary at address
J-Link> erase # Erase flash
J-Link> mem32 0x20000000 16 # Read 16 words
J-Link> w4 0x20000000 0x1234 # Write word
J-Link> rtt start # Start RTT
J-Link> rtt read 0 # Read from RTT channel 0
Batch Mode
r
loadfile firmware.hex
r
g
exit
JLinkExe -device nRF52840_xxAA -if SWD -speed 4000 -CommandFile commands.jlink
RTT (Real-Time Transfer)
JLinkRTTClient
JLinkRTTViewerExe
West (Zephyr Build Tool)
Build and Flash
west build -b nrf52840dk_nrf52840 app/
west flash
west flash --runner jlink
west flash --runner nrfjprog
west flash --runner openocd
west debug
west attach
Useful West Commands
west boards | grep nrf
west build -b nrf52840dk_nrf52840 -p auto app/
west build -b nrf52840dk_nrf52840 -- -DCONF_FILE=prj_debug.conf
west build -b nrf52840dk_nrf52840 -- -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
Troubleshooting
Target Not Found
sudo usermod -a -G dialout $USER
lsusb | grep -i "segger\|stlink\|nordic"
Flash Verification Failed
Connection Under Reset
nrfjprog --recover
openocd -f interface/stlink.cfg -f target/stm32f4x.cfg \
-c "init; reset halt; flash write_image erase firmware.hex; reset run; exit"
STM32_Programmer_CLI --connect port=SWD mode=UR reset=HWrst
References