I’m trying to use Black Magic Probe to update the firmware in my device and to debug it. I faced this problem: debugger doesn’t restart the board automatically, so I should do it manually every time (power off and power on). Could someone please help me to make the BMP reset the board automatically after each firmware update?
I’m using the custom board based on STM32F334K8T6. Previously I used ST-LINK to upload the firmware and this problem didn’t exist.
I connected {+3V3, GND, SWDIO, SWCLK, NRST} from the debugger to my device.
Please check the content of platfromio.ini below.
Except for this problem uploading and debugging work fine.
I tried to look into this problem and that’s what I found: there is a file called initcfgs.py which defines which GDB command pio will use to interact with the debugger. As I understand, to restart the target there should be something like monitor reset. In fact, the content of pio_reset_run_target for GDB_BLACKMAGIC_INIT_CONFIG entry is quite strange for me (again, you can check it below). Of course, I could be wrong as I know almost nothing about GDB
GDB_BLACKMAGIC_INIT_CONFIG = """
define pio_reset_halt_target
set language c
set *0xE000ED0C = 0x05FA0004
set $busy = (*0xE000ED0C & 0x4)
while ($busy)
set $busy = (*0xE000ED0C & 0x4)
end
set language auto
end
define pio_reset_run_target
pio_reset_halt_target
end
target extended-remote $DEBUG_PORT
monitor swdp_scan
attach 1
set mem inaccessible-by-default off
$LOAD_CMDS
$INIT_BREAK
set language c
set *0xE000ED0C = 0x05FA0004
set $busy = (*0xE000ED0C & 0x4)
while ($busy)
set $busy = (*0xE000ED0C & 0x4)
end
set language auto
"""
Ok, it looks like my guess about initcfgs.py was incorrect. It looks like that commands from this file are used for debugging, but not for regular uploading.
And I found a place where this command is generated:
So, it looks like the uploading sequence is: “… → load → compare-sections → kill”.
Could someone please explain how should it work? Should the MCU restart automatically after “kill”? Or should there be a separate command to restart? For example, BMP supports this command:
monitor hard_srst -- Force a pulse on the hard SRST line - disconnects target
The problem was discussed earlier. Current behavior is the result of the bug in the BMP fimware. So, I just updated the firmware of the BMP to the latest one and now it works fine!