Black Magic Probe doesn't reset the target after uploading

Hi Everyone!

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?

Some additional information:

  1. I’m using not the original BMP but the clone called Bumpy.
  2. I’m using the custom board based on STM32F334K8T6. Previously I used ST-LINK to upload the firmware and this problem didn’t exist.
  3. I connected {+3V3, GND, SWDIO, SWCLK, NRST} from the debugger to my device.
  4. Please check the content of platfromio.ini below.
  5. Except for this problem uploading and debugging work fine.
  6. 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 :frowning:

platformio.ini:

[env:nucleo_f334k8]
platform = ststm32@9.0.0
board = nucleo_f334k8
framework = arduino

upload_protocol = blackmagic
debug_tool = blackmagic
debug_port = COM9

fragment of initcfgs.py:

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.

Keep trying to figure out the problem myself…

Output of pio run -v -t upload:

...
AVAILABLE: blackmagic, jlink, mbed, stlink
CURRENT: upload_protocol = blackmagic
MethodWrapper(["upload"], [".pio\build\nucleo_f334k8\firmware.elf"])
Auto-detected: COM9
arm-none-eabi-gdb -nx --batch -ex "target extended-remote COM9" -ex "monitor swdp_scan" -ex "attach 1" -ex load -ex compare-sections -ex kill .pio\build\nucleo_f334k8\firmware.elf
...

So, the actual uploading command is:

arm-none-eabi-gdb -nx --batch -ex "target extended-remote COM9" -ex "monitor swdp_scan" -ex "attach 1" -ex load -ex compare-sections -ex kill .pio\build\nucleo_f334k8\firmware.elf

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”? :thinking: 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

@valeros, @ivankravets Could you help please? :pray:

Ok, finally solved the problem.

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!