Skip to content

Instantly share code, notes, and snippets.

@todbot
Last active May 11, 2023 14:33
Show Gist options
  • Save todbot/0f284c45c38e7418bf7edbb0d1302f2f to your computer and use it in GitHub Desktop.
Save todbot/0f284c45c38e7418bf7edbb0d1302f2f to your computer and use it in GitHub Desktop.
Program a SAMD21 with OpenOCD and a JLINK
# Program a SAMD21 part with a bootloader using a JLINK / J-LINK
# 0a. Wire up your device with SWD & SWC pins to JLINK
# 0b. Also wire up Gnd and Power to Gnd & VTref on JLINK
# 0c. And separately supply power to device
# 0d. Iif you don't have openocd installed, then "brew install openocd"
#
# 1. Put this file in a directory
# 2. Get a samd21 bootloader file.bin and put it in this directory renamed as "bootloader.bin"
# 3. Unplug and replug in the JLINK (to reset it)
# 4. Then do "openocd -f ./openocd-sams21.cfg" and stand back
source [find interface/jlink.cfg]
transport select swd
source [find target/at91samdXX.cfg]
init
reset
halt
program bootloader.bin verify reset
shutdown
@todbot
Copy link
Author

todbot commented Dec 8, 2020

Another way. Uses load_image instead of program. Put this in openocd-samd21-way2.cfg and do openocd -f ./openocd-samd21-way2.cfg:

source [find interface/jlink.cfg]
transport select swd
source [find target/at91samdXX.cfg]
init
reset
halt
load_image bootloader.bin 0
verify_image bootloader.bin 0 bin
reset run
shutdown

@todbot
Copy link
Author

todbot commented Dec 8, 2020

Also, if you get the error:

Error: SAMD: NVM lock error

then add this line after the halt line:

at91samd bootloader 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment