How to Initiate JTAG Without DFU Mode / Automating Flashing

FYI, I finally found away to initiate JTAG/SWD without having to interact with USB. As mentioned in other posts, the system firmware is the thing that locks down JTAG. However, it’s possible to put the device into JTAG accessible mode while holding the RST pin low for <1s during the start of the JTAG process. The specific procedure is as follows:

  1. Pull RST low
  2. begin running openocd / equivalent command:
    openocd -f interface/jlink.cfg -f target/stm32f2x.cfg -c "init" -c "{etc}"
  3. Pull RST high within 1 sec

The device will stay in JTAG accessible mode for future commands unless there is an error in your command or you add -c "resume" before you exit.

Example output with a J-Link that flashes user firmware over SWD and then lets the device run:

Justices-MBP-2:0.10.0-particle.1 justicereed$ openocd -f interface/jlink.cfg -f target/stm32f2x.cfg -c "init" -c "program ./firmware.bin verify 0x80A0000" -c "resume" -c "exit"
Open On-Chip Debugger 0.10.0+dev-00925-g08195413 (2019-09-05-17:24)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
swd
Info : J-Link EDU Mini V1 compiled Jul 24 2017 17:07:14
Info : Hardware version: 1.00
Info : VTarget = 3.266 V
Info : clock speed 1000 kHz
Info : SWD DPIDR 0x2ba01477
Info : stm32f2x.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : stm32f2x.cpu: external reset detected
Info : Listening on port 3333 for gdb connections
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x08003700 msp: 0x20020000
** Programming Started **
Info : device id = 0x200f6411
Info : flash size = 1024 kbytes
** Programming Finished **
** Verify Started **
** Verified OK **