I’ve been confused for quite a while now w.r.t. openocd and st-flash - at some point there was a
tool-stlink package or similar, but I can’t find it. That’s the
texane/stlink tool on GitHub, somewhat confusingly named since the executable is actually
st-flash and the hardware is called “ST-Link”.
The puzzle I’m running into is that I can’t reliably upload to a Nucleo-L432KC board. The board probably doesn’t matter, only that it has an ST-Link v2.1 on-board (upgraded to the latest rev from STM). This happens under various conditions: having the µC in deep sleep is a known case where JTAG & SWD cease to work, but also enabling PA15 as UART RX on this Nucleo board, which disables JTDI. Which is surprising: I thought that only the two SWD pins were needed.
Anyway, it turns out that the default
upload_protocol = stlink can’t re-flash the µC, whereas
upload_protocol = mbed works 100% all the time. Likewise,
st-flash write doesn’t work, but here’s the clue to what is needed:
st-flash --connect-under-reset write works just fine. So the good news is that there are two reliable upload mechanisms. The third (somewhat tedious) option is to keep the tiny reset button pressed, start an upload, then release the button at just the right time, before openocd times out.
Is there a way to force OpenOCD to upload-under-reset? I tried all the srts/trst
-cvariants, but none of them seemed to do the trick.
How do I get PIO to install
packages/tool-stlink? It used to be on my system, but it no longer is and I haven’t figured out what triggers this tool dependency.
P.S. Mbed uploads are quite a bit slower than openocd & st-flash, which is why I’m more interested in these alternatives.
FWIW, this works - using an
st-flash installed locally (on MacOS in my case):
upload_protocol = custom
upload_command = st-flash --connect-under-reset write $SOURCE 0x8000000
(but I’d prefer to avoid a separate tool dependency)
Update - The essence stands that reset is needed to get out of some use cases, but “enabling PA15 as UART RX” messing up uploads was entirely my fault (bad bit masking in my code, doh).