I am attempting to use openocd (STLINK-V2) to program a nrf device with both a soft device (bluetooth stack) and an application firmware (latest.hex).
This is the command I am using:
openocd -f interface/stlink.cfg -f target/nrf52.cfg -c init -c "reset init" -c halt -c "nrf5 mass_erase" -c "program btstack.hex verify" -c "program latest.hex verify" -c reset -c exit
It completes, but what I am not sure about is, is this the correct way of doing it ?
I have used esptool.py to flash esp devices and you need to specify the address that you want each hex file to be flashed to, but is this not necessary for openocd ? - does it know what to do automatically ?
The firmware runs, but the bluetooth does not appear to be active, and I was wondering whether the second hex file is overwriting the first one ?
This is the command that uses Segger programmer via nrfjprog (which I don't have)
nrfjprog --eraseall -f nrf52
nrfjprog --program drivers/bluetooth/s132_nrf52_6.0.0/s132_nrf52_6.0.0_softdevice.hex -f nrf52
nrfjprog --program build-pca10040-s132/firmware.hex --sectorerase -f nrf52
nrfjprog --reset -f nrf52
And there is an additional "--sectorerase" in this, what exactly is this doing and do I also need to add something similar into my openocd command ?
Also, there is an error: "set WORKAREASIZE 0" but if I set this as suggested, then it reports that there's not enough room and programming takes several minutes.
** Programming Started **
auto erase enabled
Info : Padding image section 0 at 0x00000a18 with 1512 bytes
Warn : using fast async flash loader. This is currently supported
Warn : only with ST-Link and CMSIS-DAP. If you have issues, add
Warn : "set WORKAREASIZE 0" before sourcing nrf51.cfg/nrf52.cfg to disable it
target halted due to breakpoint, current mode: Thread
xPSR: 0x61000000 pc: 0x2000001e msp: 0xfffffffc
wrote 155648 bytes from file btstack.hex in 7.037133s (21.600 KiB/s)
** Programming Finished **
** Verify Started **
target halted due to breakpoint, current mode: Thread
xPSR: 0x61000000 pc: 0x2000002e msp: 0xfffffffc
target halted due to breakpoint, current mode: Thread
xPSR: 0x61000000 pc: 0x2000002e msp: 0xfffffffc
verified 151008 bytes in 0.529927s (278.281 KiB/s)
** Verified OK **
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x00000998 msp: 0x20000400
** Programming Started **
auto erase enabled
Warn : using fast async flash loader. This is currently supported
Warn : only with ST-Link and CMSIS-DAP. If you have issues, add
Warn : "set WORKAREASIZE 0" before sourcing nrf51.cfg/nrf52.cfg to disable it
target halted due to breakpoint, current mode: Thread
xPSR: 0x61000000 pc: 0x2000001e msp: 0x20000400
wrote 155648 bytes from file latest.hex in 7.042735s (21.583 KiB/s)
** Programming Finished **
** Verify Started **
target halted due to breakpoint, current mode: Thread
xPSR: 0x61000000 pc: 0x2000002e msp: 0x20000400
verified 154652 bytes in 0.462758s (326.364 KiB/s)
** Verified OK **