Skip to content

Flashing nRF with OpenOCD ST Link

Alexander Heinrich edited this page Aug 25, 2021 · 5 revisions

Some nRF chips in a small form factor need to be flashed manually. Either by using a J-Link (which can be expensive) or a cheaper ST-Link in combination with openocd.

Steps

  1. Install openOCD

  2. Connect the pins to the correct ST-Link pins. A sample schematic of an nRF52 Beacon can be found below

  3. Build your firmware with the correct keys

  4. Run openocd with the correct configuration

    openocd -f share/openocd/scripts/interface/stlink.cfg -f share/openocd/scripts/target/nrf52.cfg

    The first parameter here uses the configuration file for the connected interface (stlink-v2) and the second parameter loads the config file for the nrf52 boards

  5. Now openocd is running. You can connect to it using telnet:

    telnet localhost 4444

    You can get all available commands using the help command

  6. Stop the execution with halt

  7. You can backup the existing firmware:

    dump_image /Your/File/Path/flash.bin 0 0x40000`
  8. Erase the flash using

     nrf5 mass_erase
  9. Verify and program your device by using (use the .bin not .hex file)

    program /your/path/to/the/firmware.bin verify
    program /your/path/to/the/firmware.bin
  10. Resume the execution

resume

This tutorial is largely based on comment of @sthorley here

NRF52 Pins

Clone this wiki locally