PlatformIO Community

STM32F407 debugging with STLINK V2, what debug_port?

Hi,
I am encountering some problem in the debugging of my genuine STM32F407VGT6.

There occurs following error message when I open the debugger:

Error: Please specify `debug_port` for environment
The terminal process terminated with exit code: 1

What should I specify for the debug port when I am using STLINK V2?

Here is my platformio.ini:

[env:black_f407vg]
platform = ststm32
board = black_f407vg
framework = arduino
[env:debug]
platform = ststm32
board = black_f407vg
framework = arduino
debug_init_cmds =
  target extended-remote $DEBUG_PORT
  $INIT_BREAK
  monitor reset halt
  $LOAD_CMDS
  monitor init
  monitor reset halt

I don’t think you need these debug_init_cmds at alls here, you should just remove it. Then, the environment is already exactly the same as the first one, so it can be removed entirely. Should work out of the box.

As this is a GDB command it expects an IP and port to connect to the debug server – usually 127.0.0.1:3333 for openocd. See docs. But as I said, you don’t need that at all.

I have updated the platformio.ini, but still the same problem.

[env:black_f407vg]
platform = ststm32
board = black_f407vg
framework = arduino
[env:debug]
platform = ststm32
board = black_f407vg
framework = arduino

Unfortunately still asking for debug port. So do I need so specify the local IP of the GDB somehow?

It seems that the JLink is the default debugging tool for Black STM32F407VG.

Can you add the following line to your configurations:

debug_tool = stlink

If it still doesn’t work, please add the full log so we can see all details of the used configurations and tools.

1 Like

Sure your STM32 platform is up-to-date? stlink is the standard uplink protocol and this debug protocol.

You can still specifiy

debug_port = 127.0.0.1:5555

(if openocd starts the GDB server on port 5555).

Does the default upload protocol become the default debug protocol if no other default has been specified? Or what’s the logic?

The documentation of Black STM32F407VG seems to add to the confusion as is declares Black Magic Probe as the default debug protocol.

Oh that’s interesting. Does it alphabetically sort the upload protocols first now o_O?

My understanding is that due to the Python logic for adding default debug tools, it gets it default upload protocol and uses that:

But if the docs show that, maybe the logic is different and indeed debug_tool = stlink must be added.

1 Like

I’ve just discovered two related issues:

It seems that PlatformIO can indeed raise this confusing error message if no default is specified in board definition. Setting debug_tool should fix it.

1 Like

Thanks a lot for all these informative posts. It is working now perfect.

I checked again, if no debug tool specified it is blackmagic:

CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/black_f407vg.html
PLATFORM: ST STM32 6.0.0 > Black STM32F407VG
HARDWARE: STM32F407VGT6 168MHz, 128KB RAM, 512KB Flash
DEBUG: Current (blackmagic) External (blackmagic, jlink, stlink)