Black Magic Probe on STM32

I am experimenting with a Black Magic Probe (BMP) but I can’t get upload or debug to work:

  • upload works from STM32Cube with ST-LinkV2
  • upload works from Platformio with ST-LinkV2

Now I switch to BMP

[env:genericSTM32F103C8]
platform = ststm32
board = genericSTM32F103C8
framework = stm32cube
upload_protocol = blackmagic
  1. connected the BMP to the generic STM32F103 using SWD
  2. power the STM32F103 from it’s own USB, as the BMP does not provide power to the target (whereas ST-LinkV2 does provide power)
  3. application builds ok,
  4. when doing upload - Im getting some output mixed from two sources:
Uploading .pio\build\genericSTM32F103C8\firmware.elf
Section .isr_vector, range 0x80000\\.\COM25: No such file or directory.
00 "monitor" command not supported by this target.
-- Don't know how to attach.  Try "help target".
0x8You can't do that when your target is `exec'
000warning: One or more sections of the target image does not match
10cthe loaded file
: m
atcThe program is not being run.
hed.
Section .text, range 0x800010c -- 0x8000ae0: matched.
Section .rodata, range 0x8000ae0 -- 0x8000b00: matched.
Section .init_array, range 0x8000b00 -- 0x8000b04: matched.
Section .fini_array, range 0x8000b04 -- 0x8000b08: matched.
Section .data, range 0x8000b08 -- 0x8000b14: MIS-MATCHED!

Anyone having more success with the BMP ?

I was able to solve this with the help from 1BitSquared:

The Black Magic Probe appears as 2 COM ports, one for debugging and one std serial monitor. If you let PlatformIO auto-detect, it auto-detected the wrong one in my case, resulting in the upload task not working. To figure out the correct COM-port, you can do one of the following:

  1. go to Device Manager, open the properties of the COM port and take a look at details | Hardware IDs. You need the port with hardware ID ending on MI_00
    or
  2. open a terminal, start gdb (Gnu Debugger) and manually connect with the gdb command target extended-remote \\.\COM26 (replace 26 with your COM port number). When on the correct port, gdb will return the prompt for additional commands. When on the wrong port, the command above does not work…

Note : note that I refer to the COM port as \\.\COM26 io. COM26. Often the BMP ports get COM port numbers with 2 digits. It seems there is a windows bug that requires those ports to be named with the \\.\ prefix, in order to work with gdb

So here is an example platformio.ini

[env:genericSTM32F103C8]
platform = ststm32
board = genericSTM32F103C8
framework = arduino
upload_protocol = blackmagic
debug_tool = blackmagic
upload_port = \\.\COM26

So upload is working, now onto debugging!

@ivankravets @maxgerhardt Maybe add the above info about how to select the correct port to the documentation. Also, in the documentation the link to the BMP Wiki is out of date.

PlatformIO should handle this correctly, see

Could you provide an output of the following command?

pio device list
PS C:\Users\pasca\Documents\Projects\UA\BlinkPio> pio device list

COM25
-----
Hardware ID: USB VID:PID=1D50:6018 SER=98B71F95 LOCATION=1-3:x.2
Description: USB Serial Device (COM25)

COM26
-----
Hardware ID: USB VID:PID=1D50:6018 SER=98B71F95 LOCATION=1-3:x.0
Description: USB Serial Device (COM26)

I think the x.2 and x.0 also reveal which port is debug / monitor

When letting PlatformIO auto-detect the port, this is my output, it clearly selects the wrong port, then hangs…

Configuring upload protocol...
AVAILABLE: blackmagic, cmsis-dap, dfu, jlink, serial, stlink
CURRENT: upload_protocol = blackmagic
Looking for BlackMagic port...
Auto-detected: \\.\COM25
Uploading .pio\build\genericSTM32F103C8\firmware.elf

Debugging the generic STM32F103C8 via the Black Magic Probe is also working.
Again, the debug_port must be explicitly set, auto detection does not seem to work for me.

This line should handle this

So, the first candidate is a debugging port, and the latest is an upload port.


I’ve just created a separate branch with additional debugging. Could you open PlatformIO Core CLI in VSCode and type

pip install -U https://github.com/platformio/platformio-core/archive/refs/heads/feature/debug-bmp-issue.zip

Try uploading again. You should see debugging information. Please provide it here. Thanks in advance!

Hi @ivankravets,

unfortunately it’s not yet working…

  • the patch installed without issues (see log below)
  • checked the presence of the Black Magic Probe, and it’s still on the same ports : Debug/Upload = COM26, Monitor = COM25 (see log below)
  • then outcommented the upload_port in platformio.ini to let auto-detect do it’s work, but it’s again choosing COM25 and then hangs as the probe does not respond on this port
Configuring upload protocol...
AVAILABLE: blackmagic, cmsis-dap, dfu, jlink, serial, stlink
CURRENT: upload_protocol = blackmagic
Looking for BlackMagic port...
_reveal_device_port [<serial.tools.list_ports_common.ListPortInfo object at 0x00000161EDB606D0>, <serial.tools.list_ports_common.ListPortInfo object at 0x00000161EDB608B0>] True
Auto-detected: \\.\COM25
Uploading .pio\build\genericSTM32F103C8\firmware.elf

Log of the installation of the patch:

PS C:\Users\pasca\Documents\Projects\UA\BlinkPio> pip install -U https://github.com/platformio/platformio-core/archive/refs/heads/feature/debug-bmp-issue.zip
Collecting https://github.com/platformio/platformio-core/archive/refs/heads/feature/debug-bmp-issue.zip
  Downloading https://github.com/platformio/platformio-core/archive/refs/heads/feature/debug-bmp-issue.zip
     \ 559.8 kB 3.9 MB/s 0:00:00
  Preparing metadata (setup.py) ... done
Requirement already satisfied: bottle==0.12.* in c:\users\pasca\.platformio\penv\lib\site-packages (from platformio==6.1.6a4) (0.12.23)
Requirement already satisfied: click<9,>=8.0.4 in c:\users\pasca\.platformio\penv\lib\site-packages (from platformio==6.1.6a4) (8.1.3)
Requirement already satisfied: colorama in c:\users\pasca\.platformio\penv\lib\site-packages (from platformio==6.1.6a4) (0.4.6)
Requirement already satisfied: marshmallow==3.* in c:\users\pasca\.platformio\penv\lib\site-packages (from platformio==6.1.6a4) (3.18.0)
Requirement already satisfied: pyelftools<1,>=0.27 in c:\users\pasca\.platformio\penv\lib\site-packages (from platformio==6.1.6a4) (0.29)
Requirement already satisfied: pyserial==3.5.* in c:\users\pasca\.platformio\penv\lib\site-packages (from platformio==6.1.6a4) (3.5)
Requirement already satisfied: requests==2.* in c:\users\pasca\.platformio\penv\lib\site-packages (from platformio==6.1.6a4) (2.28.1)
Requirement already satisfied: semantic_version==2.10.* in c:\users\pasca\.platformio\penv\lib\site-packages (from platformio==6.1.6a4) (2.10.0)
Requirement already satisfied: tabulate==0.9.* in c:\users\pasca\.platformio\penv\lib\site-packages (from platformio==6.1.6a4) (0.9.0)
Requirement already satisfied: zeroconf<1 in c:\users\pasca\.platformio\penv\lib\site-packages (from platformio==6.1.6a4) (0.39.4)
Requirement already satisfied: aiofiles==22.1.* in c:\users\pasca\.platformio\penv\lib\site-packages (from platformio==6.1.6a4) (22.1.0)
Requirement already satisfied: ajsonrpc==1.* in c:\users\pasca\.platformio\penv\lib\site-packages (from platformio==6.1.6a4) (1.2.0)
Collecting starlette==0.22.*
  Downloading starlette-0.22.0-py3-none-any.whl (64 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 64.3/64.3 kB ? eta 0:00:00
Collecting uvicorn==0.20.*
  Downloading uvicorn-0.20.0-py3-none-any.whl (56 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 56.9/56.9 kB ? eta 0:00:00
Requirement already satisfied: wsproto==1.2.* in c:\users\pasca\.platformio\penv\lib\site-packages (from platformio==6.1.6a4) (1.2.0)
Requirement already satisfied: packaging>=17.0 in c:\users\pasca\.platformio\penv\lib\site-packages (from marshmallow==3.*->platformio==6.1.6a4) (21.3)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\pasca\.platformio\penv\lib\site-packages (from requests==2.*->platformio==6.1.6a4) (2022.9.24)
Requirement already satisfied: idna<4,>=2.5 in c:\users\pasca\.platformio\penv\lib\site-packages (from requests==2.*->platformio==6.1.6a4) (3.4)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in c:\users\pasca\.platformio\penv\lib\site-packages (from requests==2.*->platformio==6.1.6a4) (1.26.12)
Requirement already satisfied: charset-normalizer<3,>=2 in c:\users\pasca\.platformio\penv\lib\site-packages (from requests==2.*->platformio==6.1.6a4) (2.1.1)
Requirement already satisfied: anyio<5,>=3.4.0 in c:\users\pasca\.platformio\penv\lib\site-packages (from starlette==0.22.*->platformio==6.1.6a4) (3.6.2)
Requirement already satisfied: typing-extensions>=3.10.0 in c:\users\pasca\.platformio\penv\lib\site-packages (from starlette==0.22.*->platformio==6.1.6a4) (4.4.0)
Requirement already satisfied: h11>=0.8 in c:\users\pasca\.platformio\penv\lib\site-packages (from uvicorn==0.20.*->platformio==6.1.6a4) (0.14.0)
Requirement already satisfied: async-timeout>=4.0.1 in c:\users\pasca\.platformio\penv\lib\site-packages (from zeroconf<1->platformio==6.1.6a4) (4.0.2)
Requirement already satisfied: ifaddr>=0.1.7 in c:\users\pasca\.platformio\penv\lib\site-packages (from zeroconf<1->platformio==6.1.6a4) (0.2.0)
Requirement already satisfied: sniffio>=1.1 in c:\users\pasca\.platformio\penv\lib\site-packages (from anyio<5,>=3.4.0->starlette==0.22.*->platformio==6.1.6a4) (1.3.0)
Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in c:\users\pasca\.platformio\penv\lib\site-packages (from packaging>=17.0->marshmallow==3.*->platformio==6.1.6a4) (3.0.9)
Building wheels for collected packages: platformio
  Building wheel for platformio (setup.py) ... done
  Created wheel for platformio: filename=platformio-6.1.6a4-py3-none-any.whl size=415499 sha256=8b340286cbd7794bcd725af5d8ffc5a1549fe2a165146809af266550d21544a0
  Stored in directory: c:\users\pasca\appdata\local\pip\cache\wheels\02\37\ca\892e0b2874e6dd9a606616bc5b2004843d2d9210c621923257
Successfully built platformio
Installing collected packages: uvicorn, starlette, platformio
  Attempting uninstall: uvicorn
    Found existing installation: uvicorn 0.19.0
    Uninstalling uvicorn-0.19.0:
      Successfully uninstalled uvicorn-0.19.0
  Attempting uninstall: starlette
    Found existing installation: starlette 0.21.0
    Uninstalling starlette-0.21.0:
      Successfully uninstalled starlette-0.21.0
  Attempting uninstall: platformio
    Found existing installation: platformio 6.1.5
    Uninstalling platformio-6.1.5:
      Successfully uninstalled platformio-6.1.5
Successfully installed platformio-6.1.6a4 starlette-0.22.0 uvicorn-0.20.0

[notice] A new release of pip available: 22.3 -> 22.3.1
[notice] To update, run: python.exe -m pip install --upgrade pip
PS C:\Users\pasca\Documents\Projects\UA\BlinkPio> pio device list
[notice] To update, run: python.exe -m pip install --upgrade pip
PS C:\Users\pasca\Documents\Projects\UA\BlinkPio> pio device list
Please wait while upgrading PlatformIO...
PlatformIO has been successfully upgraded to 6.1.6a4!

Output of pio device list

PS C:\Users\pasca\Documents\Projects\UA\BlinkPio> pio device list
COM12
-----
Hardware ID: BTHENUM\{00001101-0000-1000-8000-00805F9B34FB}_LOCALMFG&0000\7&39577A6B&0&000000000000_00000000
Description: Standard Serial over Bluetooth link (COM12)

COM25
-----
Hardware ID: USB VID:PID=1D50:6018 SER=98B71F95 LOCATION=1-3.3.2.4.4:x.2
Description: USB Serial Device (COM25)

COM13
-----
Hardware ID: BTHENUM\{00001101-0000-1000-8000-00805F9B34FB}_LOCALMFG&0002\7&39577A6B&0&0006666754BB_C00000000
Description: Standard Serial over Bluetooth link (COM13)

COM26
-----
Hardware ID: USB VID:PID=1D50:6018 SER=98B71F95
Description: USB Serial Device (COM26)

Please re-run again this command and provide the output. Thanks.

Output of the script:

PS C:\Users\pasca\Documents\Projects\UA\BlinkPio> pip install -U https://github.com/platformio/platformio-core/archive/refs/heads/feature/debug-bmp-issue.zip
Collecting https://github.com/platformio/platformio-core/archive/refs/heads/feature/debug-bmp-issue.zip
  Downloading https://github.com/platformio/platformio-core/archive/refs/heads/feature/debug-bmp-issue.zip
     \ 559.8 kB 3.9 MB/s 0:00:00
  Preparing metadata (setup.py) ... done
Requirement already satisfied: bottle==0.12.* in c:\users\pasca\.platformio\penv\lib\site-packages (from platformio==6.1.6a4) (0.12.23)
Requirement already satisfied: click<9,>=8.0.4 in c:\users\pasca\.platformio\penv\lib\site-packages (from platformio==6.1.6a4) (8.1.3)
Requirement already satisfied: colorama in c:\users\pasca\.platformio\penv\lib\site-packages (from platformio==6.1.6a4) (0.4.6)
Requirement already satisfied: marshmallow==3.* in c:\users\pasca\.platformio\penv\lib\site-packages (from platformio==6.1.6a4) (3.18.0)
Requirement already satisfied: pyelftools<1,>=0.27 in c:\users\pasca\.platformio\penv\lib\site-packages (from platformio==6.1.6a4) (0.29)
Requirement already satisfied: pyserial==3.5.* in c:\users\pasca\.platformio\penv\lib\site-packages (from platformio==6.1.6a4) (3.5)
Requirement already satisfied: requests==2.* in c:\users\pasca\.platformio\penv\lib\site-packages (from platformio==6.1.6a4) (2.28.1)
Requirement already satisfied: semantic_version==2.10.* in c:\users\pasca\.platformio\penv\lib\site-packages (from platformio==6.1.6a4) (2.10.0)
Requirement already satisfied: tabulate==0.9.* in c:\users\pasca\.platformio\penv\lib\site-packages (from platformio==6.1.6a4) (0.9.0)
Requirement already satisfied: zeroconf<1 in c:\users\pasca\.platformio\penv\lib\site-packages (from platformio==6.1.6a4) (0.39.4)
Requirement already satisfied: aiofiles==22.1.* in c:\users\pasca\.platformio\penv\lib\site-packages (from platformio==6.1.6a4) (22.1.0)
Requirement already satisfied: ajsonrpc==1.* in c:\users\pasca\.platformio\penv\lib\site-packages (from platformio==6.1.6a4) (1.2.0)
Requirement already satisfied: starlette==0.22.* in c:\users\pasca\.platformio\penv\lib\site-packages (from platformio==6.1.6a4) (0.22.0)
Requirement already satisfied: uvicorn==0.20.* in c:\users\pasca\.platformio\penv\lib\site-packages (from platformio==6.1.6a4) (0.20.0)
Requirement already satisfied: wsproto==1.2.* in c:\users\pasca\.platformio\penv\lib\site-packages (from platformio==6.1.6a4) (1.2.0)
Requirement already satisfied: packaging>=17.0 in c:\users\pasca\.platformio\penv\lib\site-packages (from marshmallow==3.*->platformio==6.1.6a4) (21.3)
Requirement already satisfied: charset-normalizer<3,>=2 in c:\users\pasca\.platformio\penv\lib\site-packages (from requests==2.*->platformio==6.1.6a4) (2.1.1)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\pasca\.platformio\penv\lib\site-packages (from requests==2.*->platformio==6.1.6a4) (2022.9.24)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in c:\users\pasca\.platformio\penv\lib\site-packages (from requests==2.*->platformio==6.1.6a4) (1.26.12)
Requirement already satisfied: idna<4,>=2.5 in c:\users\pasca\.platformio\penv\lib\site-packages (from requests==2.*->platformio==6.1.6a4) (3.4)
Requirement already satisfied: anyio<5,>=3.4.0 in c:\users\pasca\.platformio\penv\lib\site-packages (from starlette==0.22.*->platformio==6.1.6a4) (3.6.2)
Requirement already satisfied: typing-extensions>=3.10.0 in c:\users\pasca\.platformio\penv\lib\site-packages (from starlette==0.22.*->platformio==6.1.6a4) (4.4.0)
Requirement already satisfied: h11>=0.8 in c:\users\pasca\.platformio\penv\lib\site-packages (from uvicorn==0.20.*->platformio==6.1.6a4) (0.14.0)
Requirement already satisfied: async-timeout>=4.0.1 in c:\users\pasca\.platformio\penv\lib\site-packages (from zeroconf<1->platformio==6.1.6a4) (4.0.2)
Requirement already satisfied: ifaddr>=0.1.7 in c:\users\pasca\.platformio\penv\lib\site-packages (from zeroconf<1->platformio==6.1.6a4) (0.2.0)
Requirement already satisfied: sniffio>=1.1 in c:\users\pasca\.platformio\penv\lib\site-packages (from anyio<5,>=3.4.0->starlette==0.22.*->platformio==6.1.6a4) (1.3.0)
Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in c:\users\pasca\.platformio\penv\lib\site-packages (from packaging>=17.0->marshmallow==3.*->platformio==6.1.6a4) (3.0.9)

[notice] A new release of pip available: 22.3 -> 22.3.1
[notice] To update, run: python.exe -m pip install --upgrade pip
PS C:\Users\pasca\Documents\Projects\UA\BlinkPio>

Output of the build / upload:

Linking .pio\build\genericSTM32F103C8\firmware.elf
Checking size .pio\build\genericSTM32F103C8\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   4.0% (used 828 bytes from 20480 bytes)
Flash: [==        ]  16.7% (used 10952 bytes from 65536 bytes)
Configuring upload protocol...
AVAILABLE: blackmagic, cmsis-dap, dfu, jlink, serial, stlink
CURRENT: upload_protocol = blackmagic
Looking for BlackMagic port...
_reveal_device_port [<serial.tools.list_ports_common.ListPortInfo object at 0x000001E87B2C6A60>, <serial.tools.list_ports_common.ListPortInfo object at 0x000001E87B2C6340>] True
Auto-detected: \\.\COM25
Uploading .pio\build\genericSTM32F103C8\firmware.elf

I notice the output of pio device list is different from before (very first msg in this topic), ie. the x.0 is no longer there. Other than that, it’s not selecting the correct com port for the probe.

How does it possible? Do you use the same PIO Core? Ok, try to uninstall PlatformIO Core :slight_smile:

pip uninstall platformio

then

pip install -U https://github.com/platformio/platformio-core/archive/refs/heads/feature/debug-bmp-issue.zip

It should print the device name, see Build 2 · platformio/platformio-core@9a62aba · GitHub

It gives a bit more output, but still selects COM25 io COM26

Configuring upload protocol...
AVAILABLE: blackmagic, cmsis-dap, dfu, jlink, serial, stlink
CURRENT: upload_protocol = blackmagic
Looking for BlackMagic port...
_reveal_device_port ['COM25', 'COM26'] True
Auto-detected: \\.\COM25
Uploading .pio\build\genericSTM32F103C8\firmware.elf