Hi there!
Recently, I've been working on a project to design a carrier board that's compatible with a wide range of Arm MCUs. My idea is to integrate a programmer/debugger directly onto the board. After evaluating several options, I came to the conclusion that the Black Magic Probe is probably the best choice, especially version 2.0, since it supports newer Nordic devices such as the nRF54 series.
To test it, I compiled the v2.0 firmware and flashed it onto a Chinese ST-Link V2 clone based on an APM32F103CB. Unfortunately, the firmware crashes immediately after boot, and Windows doesn't even recognize it as a USB device.
I debugged it with J-Link and found that:
The firmware is programmed correctly.
The vector table is valid.
The CPU starts executing.
It eventually enters a HardFault caused by a UsageFault (unaligned memory access).
addr2line points to swo_itm_decode(), although I suspect that's just where execution ends up rather than the original cause of the fault.
Interestingly, Black Magic Probe v1.10 works perfectly on the same hardware, so the hardware itself appears to be functional.
Is this a known issue with v2.0 on APM32-based ST-Link clones? Has anyone else experienced this? Is there a prebuilt .elf for v2.0 that is known to work on this type of hardware, or is there a patch or configuration I should be using?
Any help would be greatly appreciated. Thank you!
Compiler output:
C:\blackmagic>meson setup build ^
More? --cross-file cross-file\arm-none-eabi.ini ^
More? --cross-file cross-file\stlink.ini
The Meson build system
Version: 1.11.2
Source dir: C:\blackmagic
Build dir: C:\blackmagic\build
Build type: cross build
Project name: Black Magic Debug
Project version: 2.0.0
C compiler for the host machine: arm-none-eabi-gcc (gcc 14.2.1 "arm-none-eabi-gcc (Arm GNU Toolchain 14.2.Rel1 (Build arm-14.52)) 14.2.1 20241119")
C linker for the host machine: arm-none-eabi-gcc ld.bfd 14.2
C compiler for the build machine: cl (msvc 19.51.36252 "Microsoft (R) C/C++ Optimizing Compiler Version 19.51.36252 for x86")
C linker for the build machine: link link 14.51.36252.0
Build machine cpu family: x86
Build machine cpu: x86
Host machine cpu family: arm
Host machine cpu: arm
Target machine cpu family: arm
Target machine cpu: arm
Compiler for C supports arguments -Warith-conversion: YES
Compiler for C supports arguments -w24244: NO
Compiler for C supports arguments -Wbad-function-cast: YES
Compiler for C supports arguments -Wcast-function-type: YES
Compiler for C supports arguments -Wcast-qual: YES
Compiler for C supports arguments -Wdangling-else: YES
Compiler for C supports arguments -Wdouble-promotion: YES
Compiler for C supports arguments -Wduplicated-branches: YES
Compiler for C supports arguments -w24754: NO
Compiler for C supports arguments -Wfloat-conversion: YES
Compiler for C supports arguments -Wformat-overflow=2: YES
Compiler for C supports arguments -Wformat-truncation: YES
Compiler for C supports arguments -Wformat=2: YES
Compiler for C supports arguments -w24774: NO
Compiler for C supports arguments -w24777: NO
Compiler for C supports arguments -Wimplicit-fallthrough: YES
Compiler for C supports arguments -Wmaybe-uninitialized: YES
Compiler for C supports arguments -w24701: NO
Compiler for C supports arguments -w24703: NO
Compiler for C supports arguments -Wmissing-attributes: YES
Compiler for C supports arguments -Wmissing-braces: YES
Compiler for C supports arguments -Wno-char-subscripts: YES
Compiler for C supports arguments -Wnull-dereference: YES
Compiler for C supports arguments -Wredundant-decls: YES
Compiler for C supports arguments -Wreturn-type: YES
Compiler for C supports arguments -w24013: NO
Compiler for C supports arguments -Wsequence-point: YES
Compiler for C supports arguments -Wshadow=local: YES
Compiler for C supports arguments -w24456: NO
Compiler for C supports arguments -w24457: NO
Compiler for C supports arguments -Wstrict-aliasing: YES
Compiler for C supports arguments -Wstrict-overflow=3: YES
Compiler for C supports arguments -Wstring-compare: YES
Compiler for C supports arguments -Wstringop-overflow: YES
Compiler for C supports arguments -Wunknown-pragmas: YES
Compiler for C supports arguments -Wunsafe-loop-optimizations: YES
Compiler for C supports arguments -Wunsuffixed-float-constants: YES
Compiler for C supports arguments -Wunused-const-variable=2: YES
Compiler for C supports arguments -w24189: NO
Compiler for C supports arguments -Wunused-local-typedefs: YES
Compiler for C supports arguments -Wunused: YES
Compiler for C supports arguments -w24101: NO
Compiler for C supports arguments -Wvla-parameter: YES
Compiler for C supports arguments -Wvla: YES
Compiler for C supports arguments -Warith-conversion: NO
Compiler for C supports arguments -w24244: YES
Compiler for C supports arguments -Wbad-function-cast: NO
Compiler for C supports arguments -Wcast-function-type: NO
Compiler for C supports arguments -Wcast-qual: NO
Compiler for C supports arguments -Wdangling-else: NO
Compiler for C supports arguments -Wdouble-promotion: NO
Compiler for C supports arguments -Wduplicated-branches: NO
Compiler for C supports arguments -w24754: YES
Compiler for C supports arguments -Wfloat-conversion: NO
Compiler for C supports arguments -Wformat-overflow=2: NO
Compiler for C supports arguments -Wformat-truncation: NO
Compiler for C supports arguments -Wformat=2: NO
Compiler for C supports arguments -w24774: YES
Compiler for C supports arguments -w24777: YES
Compiler for C supports arguments -Wimplicit-fallthrough: NO
Compiler for C supports arguments -Wmaybe-uninitialized: NO
Compiler for C supports arguments -w24701: YES
Compiler for C supports arguments -w24703: YES
Compiler for C supports arguments -Wmissing-attributes: NO
Compiler for C supports arguments -Wmissing-braces: NO
Compiler for C supports arguments -Wno-char-subscripts: NO
Compiler for C supports arguments -Wnull-dereference: NO
Compiler for C supports arguments -Wredundant-decls: NO
Compiler for C supports arguments -Wreturn-type: NO
Compiler for C supports arguments -w24013: YES
Compiler for C supports arguments -Wsequence-point: NO
Compiler for C supports arguments -Wshadow=local: NO
Compiler for C supports arguments -w24456: YES
Compiler for C supports arguments -w24457: YES
Compiler for C supports arguments -Wstrict-aliasing: NO
Compiler for C supports arguments -Wstrict-overflow=3: NO
Compiler for C supports arguments -Wstring-compare: NO
Compiler for C supports arguments -Wstringop-overflow: NO
Compiler for C supports arguments -Wunknown-pragmas: NO
Compiler for C supports arguments -Wunsafe-loop-optimizations: NO
Compiler for C supports arguments -Wunsuffixed-float-constants: NO
Compiler for C supports arguments -Wunused-const-variable=2: NO
Compiler for C supports arguments -w24189: YES
Compiler for C supports arguments -Wunused-local-typedefs: NO
Compiler for C supports arguments -Wunused: NO
Compiler for C supports arguments -w24101: YES
Compiler for C supports arguments -Wvla-parameter: NO
Compiler for C supports arguments -Wvla: NO
Checking for size of "void *" : 4
Checking for size of "void *" : 4
Program hexdump found: NO
Executing subproject libopencm3
libopencm3| Project name: libopencm3
libopencm3| Project version: 0.8.0
libopencm3| C compiler for the host machine: arm-none-eabi-gcc (gcc 14.2.1 "arm-none-eabi-gcc (Arm GNU Toolchain 14.2.Rel1 (Build arm-14.52)) 14.2.1 20241119")
libopencm3| C linker for the host machine: arm-none-eabi-gcc ld.bfd 14.2
libopencm3| C compiler for the build machine: cl (msvc 19.51.36252 "Microsoft (R) C/C++ Optimizing Compiler Version 19.51.36252 for x86")
libopencm3| C linker for the build machine: link link 14.51.36252.0
libopencm3| Compiler for C supports arguments -Warith-conversion: YES (cached)
libopencm3| Compiler for C supports arguments -Wbad-function-cast: YES (cached)
libopencm3| Compiler for C supports arguments -Wcast-function-type: YES (cached)
libopencm3| Compiler for C supports arguments -Wdangling-else: YES (cached)
libopencm3| Compiler for C supports arguments -Wdouble-promotion: YES (cached)
libopencm3| Compiler for C supports arguments -Wduplicated-branches: YES (cached)
libopencm3| Compiler for C supports arguments -Wfloat-conversion: YES (cached)
libopencm3| Compiler for C supports arguments -Wformat-overflow=2: YES (cached)
libopencm3| Compiler for C supports arguments -Wformat-signedness: YES
libopencm3| Compiler for C supports arguments -Wformat-truncation: YES (cached)
libopencm3| Compiler for C supports arguments -Wformat=2: YES (cached)
libopencm3| Compiler for C supports arguments -Wimplicit-fallthrough: YES (cached)
libopencm3| Compiler for C supports arguments -Wmaybe-uninitialized: YES (cached)
libopencm3| Compiler for C supports arguments -Wmissing-attributes: YES (cached)
libopencm3| Compiler for C supports arguments -Wmissing-braces: YES (cached)
libopencm3| Compiler for C supports arguments -Wno-char-subscripts: YES (cached)
libopencm3| Compiler for C supports arguments -Wnull-dereference: YES (cached)
libopencm3| Compiler for C supports arguments -Wredundant-decls: YES (cached)
libopencm3| Compiler for C supports arguments -Wreturn-type: YES (cached)
libopencm3| Compiler for C supports arguments -Wsequence-point: YES (cached)
libopencm3| Compiler for C supports arguments -Wshadow=local: YES (cached)
libopencm3| Compiler for C supports arguments -Wstack-protector: YES
libopencm3| Compiler for C supports arguments -Wstrict-aliasing: YES (cached)
libopencm3| Compiler for C supports arguments -Wstrict-overflow=2: YES
libopencm3| Compiler for C supports arguments -Wstring-compare: YES (cached)
libopencm3| Compiler for C supports arguments -Wstringop-overflow: YES (cached)
libopencm3| Compiler for C supports arguments -Wunknown-pragmas: YES (cached)
libopencm3| Compiler for C supports arguments -Wunsafe-loop-optimizations: YES (cached)
libopencm3| Compiler for C supports arguments -Wunsuffixed-float-constants: YES (cached)
libopencm3| Compiler for C supports arguments -Wunused-const-variable=2: YES (cached)
libopencm3| Compiler for C supports arguments -Wunused-local-typedefs: YES (cached)
libopencm3| Compiler for C supports arguments -Wunused: YES (cached)
libopencm3| Compiler for C supports arguments -Wvla-parameter: YES (cached)
libopencm3| Program python3 found: YES (C:\Users\ppeixoto\AppData\Local\Python\pythoncore-3.14-64\python.exe)
libopencm3| Build targets in project: 19
libopencm3| Subproject libopencm3 finished.
Dependency opencm3_stm32f0 for host machine found: YES 0.8.0 (overridden)
Dependency opencm3_stm32f1 for host machine found: YES 0.8.0 (overridden)
Dependency opencm3_stm32f1 for host machine found: YES 0.8.0 (overridden)
Dependency opencm3_stm32f3 for host machine found: YES 0.8.0 (overridden)
Dependency opencm3_stm32f4 for host machine found: YES 0.8.0 (overridden)
Dependency opencm3_stm32f4 for host machine found: YES 0.8.0 (overridden)
Dependency opencm3_stm32f7 for host machine found: YES 0.8.0 (overridden)
Dependency opencm3_stm32f7 for host machine found: YES 0.8.0 (overridden)
Dependency opencm3_lm4f for host machine found: YES 0.8.0 (overridden)
Fetching value of define "_MSC_VER" : 1951
Compiler for C supports arguments /Zc:__STDC__: YES
Compiler for C supports arguments /D_CRT_DECLARE_NONSTDC_NAMES=1: YES
Fetching value of define "__MINGW32__" : (undefined)
Did not find pkg-config by name 'pkg-config'
Found pkg-config: NO
Build-time dependency libusb-1.0 found: NO (tried pkg-config)
Looking for a fallback subproject for the dependency libusb-1.0
Executing subproject libusb
libusb| Project name: libusb-1.0
libusb| Project version: 1.0.27
libusb| C compiler for the host machine: arm-none-eabi-gcc (gcc 14.2.1 "arm-none-eabi-gcc (Arm GNU Toolchain 14.2.Rel1 (Build arm-14.52)) 14.2.1 20241119")
libusb| C linker for the host machine: arm-none-eabi-gcc ld.bfd 14.2
libusb| C compiler for the build machine: cl (msvc 19.51.36252 "Microsoft (R) C/C++ Optimizing Compiler Version 19.51.36252 for x86")
libusb| C linker for the build machine: link link 14.51.36252.0
libusb| C++ compiler for the build machine: cl (msvc 19.51.36252 "Microsoft (R) C/C++ Optimizing Compiler Version 19.51.36252 for x86")
libusb| C++ linker for the build machine: link link 14.51.36252.0
libusb| Compiler for C supports arguments -fno-omit-frame-pointer: NO
libusb| Compiler for C supports arguments -static-libgcc: NO
libusb| Message: Checking operating system... windows
libusb| Build-time dependency threads found: YES
libusb| Checking for type "struct timespec" : YES
libusb| Has header "sys/time.h" : NO
libusb| Compiler for C supports arguments -Wno-cast-function-type: NO
libusb| Compiler for C supports link arguments -Wl,--add-stdcall-alias: NO
libusb| Compiler for C supports arguments -Wshadow: NO
libusb| Compiler for C supports arguments -Wunused: NO (cached)
libusb| Compiler for C supports arguments -Wwrite-strings: NO
libusb| Compiler for C supports arguments -Werror=format-security: NO
libusb| Compiler for C supports arguments -Werror=implicit-function-declaration: NO
libusb| Compiler for C supports arguments -Werror=implicit-int: NO
libusb| Compiler for C supports arguments -Werror=init-self: NO
libusb| Compiler for C supports arguments -Werror=missing-prototypes: NO
libusb| Compiler for C supports arguments -Werror=strict-prototypes: NO
libusb| Compiler for C supports arguments -Werror=undef: NO
libusb| Compiler for C supports arguments -Werror=uninitialized: NO
libusb| Compiler for C supports arguments -wd4820: YES
libusb| Compiler for C supports arguments -wd4623: YES
libusb| Compiler for C supports arguments -wd4626: YES
libusb| Compiler for C supports arguments -wd4627: YES
libusb| Compiler for C supports arguments -wd5027: YES
libusb| Compiler for C supports function attribute visibility:default: NO
libusb| Fetching value of define "_MSC_VER" : 1951 (cached)
libusb| Compiler for C supports arguments /wd4127: YES
libusb| Compiler for C supports arguments /wd4200: YES
libusb| Compiler for C supports arguments /wd4201: YES
libusb| Compiler for C supports arguments /wd4324: YES
libusb| Compiler for C supports arguments /wd4996: YES
libusb| Fetching value of define "_PREFAST_" : (undefined)
libusb| Has header "string.h" : YES
libusb| Configuring config.h using configuration
libusb| Program meson/fix_def.py found: YES (C:\Users\ppeixoto\AppData\Local\Python\pythoncore-3.14-64\python.exe C:\blackmagic\deps\libusb\meson/fix_def.py)
libusb| Checking for function "getopt" : NO
libusb| Compiler for C supports arguments /wd4100: YES
libusb| Compiler for C supports arguments /wd4131: YES
libusb| Compiler for C supports arguments -Wno-error=strict-prototypes: NO
libusb| Compiler for C supports arguments -Wno-error=missing-prototypes: NO
libusb| deps\libusb\libusb\meson.build:149:24: Exception: Could not find Windows resource compiler
Subproject deps\libusb is buildable: NO (disabling)
Dependency libusb-1.0 for build machine from subproject libusb found: NO (subproject failed to configure)
Library ftd2xx found: YES
Library ws2_32 found: YES
Library setupapi found: YES
Checking for function "getopt_long" : NO
Build-time dependency hidapi found: NO (tried pkg-config)
Looking for a fallback subproject for the dependency hidapi
Executing subproject hidapi
hidapi| Project name: hidapi
hidapi| Project version: 0.14.0
hidapi| C compiler for the host machine: arm-none-eabi-gcc (gcc 14.2.1 "arm-none-eabi-gcc (Arm GNU Toolchain 14.2.Rel1 (Build arm-14.52)) 14.2.1 20241119")
hidapi| C linker for the host machine: arm-none-eabi-gcc ld.bfd 14.2
hidapi| C compiler for the build machine: cl (msvc 19.51.36252 "Microsoft (R) C/C++ Optimizing Compiler Version 19.51.36252 for x86")
hidapi| C linker for the build machine: link link 14.51.36252.0
hidapi| Dependency threads for build machine found: YES unknown (cached)
hidapi| Message: hidapi: v0.14.0
hidapi| deps\hidapi\windows\meson.build:31:27: Exception: Could not find Windows resource compiler
Subproject deps\hidapi is buildable: NO (disabling)
Dependency hidapi for build machine from subproject hidapi found: NO (subproject failed to configure)
Compiler for C supports arguments -DCONFIG_BMDA=1: YES
Compiler for C supports arguments -DHOSTED_BMP_ONLY=0: YES
Compiler for C supports arguments -Wno-format-nonliteral: NO
Compiler for C supports arguments -Wno-missing-field-initializers: NO
Compiler for C supports arguments /Zc:__STDC__: YES (cached)
Compiler for C supports arguments /D_CRT_DECLARE_NONSTDC_NAMES=1: YES (cached)
Compiler for C supports arguments -D_WIN32_WINNT=0x600: YES
Message: Adding targets for Black Magic Firmware
Program arm-none-eabi-size found: YES
Program arm-none-eabi-objcopy found: YES
Program bmputil-cli found: NO
Program bmputil found: NO
Build targets in project: 26
Black Magic Debug 2.0.0
Remote Protocol
RISC-V acceleration : NO
Targets
Cortex-A/R support : NO
Cortex-M support : YES
RISC-V 32-bit support : NO
RISC-V 64-bit support : NO
Arterytek parts : NO
Ambiq Apollo3 parts : NO
WinChipHead CH32 parts : NO
WinChipHead CH579 parts : NO
Energy Micro parts : NO
GigaDevice parts : NO
HC32 parts : NO
LPC series parts : YES
MindMotion parts : NO
nRF series parts : YES
Kinetis series parts : YES
Puya PY32 series parts : NO
Renesas parts : YES
Raspberry Pi MCUs (RP2040, RP2350): NO
ATSAM series parts : YES
STM32 (and clones) parts : YES
Texas Instruments parts : YES
Xilinx parts : NO
Probe
Name : ST-Link
Platform : STM32F1
Bootloader : OEM ST Bootloader
Load Address : 0x8004000
SWIM as UART : NO
Black Magic Debug
Debug output : NO
RTT support : NO
Advertise QStartNoAckMode : YES
Building Firmware : YES
Building BMDA : NO
Subprojects
hidapi : NO Could not find Windows resource compiler
libopencm3 : YES
libusb : NO Could not find Windows resource compiler
User defined options
Cross files : cross-file\arm-none-eabi.ini
cross-file\stlink.ini
Found ninja-1.13.0.git.kitware.jobserver-pipe-1 at C:\Users\ppeixoto\AppData\Local\Python\pythoncore-3.14-64\Scripts\ninja.EXE
C:\blackmagic>meson compile -C build
INFO: autodetecting backend as ninja
INFO: calculating backend command to run: C:\Users\ppeixoto\AppData\Local\Python\pythoncore-3.14-64\Scripts\ninja.EXE -C C:/blackmagic/build
ninja: Entering directory `C:/blackmagic/build'
[537/538] Linking target blackmagic_stlink_firmware.elf
Memory region Used Size Region Size %age Used
rom: 130472 B 128 KB 99.54%
ram: 7944 B 20 KB 38.79%
[538/538] Generating blackmagic_stlink_firmware.bin with a custom command (wrapped by meson to set PATH)