-
Notifications
You must be signed in to change notification settings - Fork 981
Description
Hi all,
hope I'm not missing anything obvious, but the bluepill-clone
target, whose main purpose as of now is setting a different expected idcode for openocd
than the regular bluepill
, fails at this very task:
> tinygo version
tinygo version 0.38.0 linux/amd64 (using go version go1.24.4 and LLVM version 19.1.2)
> tinygo flash -target bluepill-clone
Open On-Chip Debugger 0.12.0
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
WARNING: interface/stlink-v2.cfg is deprecated, please switch to interface/stlink.cfg
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select <transport>'.
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
0x2ba01477
Info : clock speed 1000 kHz
Info : STLINK V2J17S4 (API v2) VID:PID 0483:3748
Info : Target voltage: 3.239128
Warn : UNEXPECTED idcode: 0x2ba01477
Error: expected 1 of 1: 0x1ba01477
** OpenOCD init failed **
shutdown command invoked
failed to flash /tmp/tinygo3776027685/main.hex: exit status 1
Printing the involved commands gave me some hint:
> tinygo flash -target bluepill-clone -x
#...
openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg -c 'set CPUTAPID 0x2ba01477' -c 'program /tmp/tinygo2666434505/main.hex reset exit'
#...
From what I can tell, the issue is that stm32f1x.cfg needs that CPUTAPID
variable to be set before it gets sourced, but at the time it is evaluated that variable is yet to be set, and thus it falls back to default one. The variable only gets set after stm32f1x.cfg is evaluated and as such no longer relevant. In fact trying to run openocd
directly by inverting the order of the two options results in a successful flash operation:
> openocd -f interface/stlink-v2.cfg -c "set CPUTAPID 0x2ba01477" -f target/stm32f1x.cfg -c 'program out.hex reset exit'
Open On-Chip Debugger 0.12.0
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
WARNING: interface/stlink-v2.cfg is deprecated, please switch to interface/stlink.cfg
0x2ba01477
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select <transport>'.
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Info : clock speed 1000 kHz
Info : STLINK V2J17S4 (API v2) VID:PID 0483:3748
Info : Target voltage: 3.235955
Warn : target stm32f1x.cpu examination failed
Info : starting gdb server for stm32f1x.cpu on 3333
Info : Listening on port 3333 for gdb connections
Info : [stm32f1x.cpu] Cortex-M3 r2p1 processor detected
Info : [stm32f1x.cpu] target has 6 breakpoints, 4 watchpoints
[stm32f1x.cpu] halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x080030f8 msp: 0x20000800
** Programming Started **
Info : device id = 0x20036410
Info : flash size = 128 KiB
Warn : Adding extra erase range, 0x08009608 .. 0x080097ff
** Programming Finished **
** Resetting Target **
shutdown command invoked
So more generically, it seems the part that builds the openocd
command line probably needs to be reworked taking into account that the position of the extra commands matter.