Debugger with C232HM (FTDI) STM32

Hello everyone,
I want to debug and program an STM32F446RE using the C232HM-EDHSL-0. I’ve already read several discussions in the forum, but I can’t quite figure out why it’s not working.
I must also say that I am new to this topic and I am very glad about any help.

; PlatformIO Project Configuration File
;Debugger FTDI C232HM STM32

[env:debug_genericSTM32F446RE]
platform = ststm32
framework = arduino
board = genericSTM32F446RE
monitor_speed= 115200
debug_tool = custom
platform_packages = platformio/tool-openocd@^3.1200.0
upload_port = COM14
debug_server =
    ${platformio.packages_dir}/tool-openocd/openocd
    -f
    ${platformio.packages_dir}/tool-openocd/scripts/board/genericSTM32F446RE.cfg

Configuration File i found on github

# interface/ftdi/c232hm.cfg

#

# FTDI USB Hi-Speed to MPSSE Cable

#

# http://www.ftdichip.com/Products/Cables/USBMPSSE.htm

#

# C232HM-DDHSL-0 and C232HM-EDSL-0 provide 3.3V and 5V on pin 1 (Red),

# respectively.

#

# Adapter: http://www.ftdichip.com/Support/Documents/DataSheets/Cables/DS_C232HM_MPSSE_CABLE.PDF

# Chip: http://www.ftdichip.com/Support/Documents/DataSheets/ICs/DS_FT232H.pdf

# See pinout/colors at end of this file.

#

# Tech notes:

# http://www.ftdichip.com/Support/Documents/AppNotes/AN_135_MPSSE_Basics.pdf

# http://www.ftdichip.com/Support/Documents/AppNotes/AN_129_FTDI_Hi_Speed_USB_To_JTAG_Example.pdf

#

# This was tested with the 3.3V version adapter (FTDI part number C232HM-DDHSL-0). It should also

# work with the 5V version (C232HM-EDHSL-0), but this has not been tested.

#

# In testing, with adapter_khz at 26000 or 30000 MHz, read speed topped out around 2.2 KiB/s.

# This allowed dumping a 4MB flash chip in about 30 minutes, for example.

interface ftdi

#ftdi_device_desc "C232HM-DDHSL-0"

#ftdi_device_desc "C232HM-EDHSL-0"

# Common PID for FT232H

ftdi_vid_pid 0x0403 0x6014

# Layout

# High data 0xff makes ACBUS (which includes LED on ACBUS6) initially high (off).

# Low data byte 0xf8 makes TRST (AD4) and SRST (AD5) initially high (unasserted).

# High direction 0x40 makes only ACBUS6 output (connected to red LED)

# Low direction 0xfb makes GPIOL0/1 output; used for T/SRST signals below. Only TDO is input (low).

ftdi_layout_init 0xfff8 0x40fb

# Optional Signals (Comment out ftdi_layout_signal line(s) below if board doesn't have T/SRST.)

# ---A*BUS-------CCCCCCCC|DDDDDDDD

# --------\______76543210|76543210

# nTRST 0x0010 = 00000000|00010000 = ADBUS4 (gray)

# nSRST 0x0020 = 00000000|00100000 = ADBUS5 (purple)

# LED 0x4000 = 01000000|00000000 = ACBUS6

ftdi_layout_signal nTRST -data 0x0010 -oe 0x0010

ftdi_layout_signal nSRST -data 0x0020 -oe 0x0020

ftdi_layout_signal LED -data 0x4000 -noe 0x4000

# LED toggle procedures

proc c232hm_LED_on {} {

ftdi_layout_signal LED -data 0x4000 -oe 0x4000

}

proc c232hm_LED_off {} {

ftdi_layout_signal LED -data 0x4000 -noe 0x4000

}

# C232HM FT232H JTAG

# Num Color Name Func

# 1 Red VCC N/A - Do not connect

# 2 Orange ADBUS0 TCK

# 3 Yellow ADBUS1 TDI

# 4 Green ADBUS2 TDO

# 5 Brown ADBUS3 TMS

# 6 Grey ADBUS4 (GPIOL0)/nTRST

# 7 Purple ADBUS5 (GPIOL1)/nSRST

# 8 White ADBUS6 (GPIOL2) - not used

# 9 Blue ADBUS7 (GPIOL3) - not used

# 10 Black GND Connect to ground

# end interface/ftdi/c232hm.cfg

With no error message and no wireup info between your FTDI and STM32 chip given, we can hardly help.

At the very start, you should make sure that OpenOCD can at least connect with the config you gave it. That is, open up a new terminal and manually execute

~/.platformio/packages/tool-openocd/openocd -f ~/.platformio/packages/tool-openocd/scripts/board/genericSTM32F446RE.cfg

(adapt paths as needed) and see what happens or what is output.

Thank you for the answer.
I want to use only the STM32F446RE microcontroller from the Nucleo board. The rest of the Nucleo board I have disconnected with the jumpers. Now I want to use the C232HM Cable with JTAG to program and debug the STM32F446RE to test how it works.

If I manually execute the ~/.platformio/packages/tool-openocd/openocd in the terminal in VSCode, I get this message:

The ${platformio.packages_dir} is a PatformIO-only thing. In a regular powershell, you have to give the full paths, e.g.,

C:\Users\<user>\.platformio\packages\tool-openocd\bin\openocd -f ...

I have tried this:

But do not understand what else I need after this command.

I also noticed that the generic STM32F446RE.cfg file is not findable at all under tool-openocd\scripts\board. Could I manually add this file?

Okay when I read this I thought you already had created a custom config file for this.

In this case no, because standard OpenOCD already has the interface definition, so you should not have to add any file. The “interface” (your debug adapter) and the “target” (the microcontroller you’re connecting to) are two different config files. So your invocation should look something like this

C:\Users\<user>\.platformio\packages\tool-openocd\bin\openocd.exe -s C:\Users\<user>\.platformio\packages\tool-openocd\openocd\scripts -f interface/ftdi/c232.cfg -c "transport select swd" -f target/stm32f4x.cfg

Sorry for the confusion, and thanks for the additional information. I now have a problem with the JTAG connection. The microcontroller can do both SWD and JTAG, do I need to define that?

C:\Users\<user>\.platformio\packages\tool-openocd\bin\openocd.exe -s C:\Users\<user>\.platformio\packages\tool-openocd\openocd\scripts -f interface/ftdi/c232hm.cfg -c "transport select jtag" -f target/stm32f4x.cfg
xPack Open On-Chip Debugger 0.12.0-01004-g9ea7f3d64-dirty (2023-01-30-15:04)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
jtag
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : clock speed 2000 kHz
Error: JTAG scan chain interrogation failed: all ones
Error: Check JTAG interface, timings, target power, etc.
Error: Trying to use configured scan chain anyway...
Error: stm32f4x.cpu: IR capture error; saw 0x0f not 0x01
Warn : Bypassing JTAG setup events due to errors
Error: Invalid ACK (7) in DAP response
Error: JTAG-DP STICKY ERROR

But you only have SWD lines (SWDIO, SWDCLK, NRST) hooked up?

If you hook the debugger up to the JTAG pins correctly, it should equivalently be able to connect via JTAG. JTAG is on by default. In fact, SWD is initiated by sending a JTAG-to-SWD transition sequence on what are initially JTAG lines.

The JTAG pins can be found in the microcontroller’s datasheet. A good reference for the nucleo board is mbedos.

Ah, my mistake.
I have reconnected it. Now the connection looks good.
Thanks a lot
image_2023-10-18_151258107

C:\Users\<user>\.platformio\packages\tool-openocd\bin\openocd.exe -s C:\Users\<user>\.platformio\packages\tool-openocd\openocd\scripts -f interface/ftdi/c232hm.cfg -c "transport select jtag" -f target/stm32f4x.cfg
xPack Open On-Chip Debugger 0.12.0-01004-g9ea7f3d64-dirty (2023-01-30-15:04)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
jtag
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : clock speed 2000 kHz
Info : JTAG tap: stm32f4x.cpu tap/device found: 0x4ba00477 (mfg: 0x23b (ARM Ltd), part: 0xba00, ver: 0x4)
Info : JTAG tap: stm32f4x.bs tap/device found: 0x06421041 (mfg: 0x020 (STMicroelectronics), part: 0x6421, ver: 0x0)
Info : [stm32f4x.cpu] Cortex-M4 r0p1 processor detected
Info : [stm32f4x.cpu] target has 6 breakpoints, 4 watchpoints
Info : starting gdb server for stm32f4x.cpu on 3333
Info : Listening on port 3333 for gdb connections
Info : [stm32f4x.cpu] external reset detected

Great, now you can set debug_tool = custom and the debug_server your found correct OpenOCD invocation, as documented in debug_server — PlatformIO latest documentation and that should enable the debugging sidebar → “PIO Debug” task to work.

I now have another error. I have previously played with the driver from the C232HM with Zadig. Is USB Serial (CDC) the right driver?

platformio.ini

;PlatformIO Project Configuration File
;Debugger FTDI C232HM STM32

[env:debug_STM32F446RE]
platform = ststm32
framework = arduino
board = genericSTM32F446RE
monitor_speed= 115200
debug_tool = custom
platform_packages = platformio/tool-openocd@^3.1200.0
debug_server = 
       ${platformio.packages_dir}/packages/tool-openocd/bin/openocd
    -s ${platformio.packages_dir}/packages/tool-openocd/openocd/scripts
    -f interface/ftdi/c232hm
    -c "transport select jtag" 
    -f target/stm32f4x

Error message

Processing debug_STM32F446RE (platform: ststm32; framework: arduino; board: genericSTM32F446RE)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/genericSTM32F446RE.html
PLATFORM: ST STM32 (17.0.0) > STM32F446RE (128k RAM. 512k Flash)
HARDWARE: STM32F446RET6 180MHz, 128KB RAM, 512KB Flash
DEBUG: Current (custom) External (blackmagic, jlink, stlink)
PACKAGES:
 - framework-arduinoststm32 @ 4.20600.231001 (2.6.0)
 - framework-cmsis @ 2.50700.210515 (5.7.0)
 - tool-dfuutil @ 1.11.0
 - tool-dfuutil-arduino @ 1.11.0
 - tool-openocd @ 3.1200.0 (12.0)
 - tool-stm32duino @ 1.0.2
 - toolchain-gccarmnoneeabi @ 1.120301.0 (12.3.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 12 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Checking size .pio\build\debug_STM32F446RE\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   0.6% (used 832 bytes from 131072 bytes)
Flash: [          ]   0.7% (used 3632 bytes from 524288 bytes)
Configuring upload protocol...
AVAILABLE: blackmagic, dfu, jlink, serial, stlink
CURRENT: upload_protocol = serial
Looking for upload port...
Using manually specified: COM15
Uploading .pio\build\debug_STM32F446RE\firmware.bin
stm32flash 0.4

Error probing interface "serial_w32"
http://stm32flash.googlecode.com/

Cannot handle device "COM15"
Using Parser : Raw BINARY
Failed to open port: COM15

*** [upload] Error 1
===================================================================== [FAILED] Took 3.46 seconds =====================================================================

Serial is not the right upload protocol if you want to upload via your FTDI. If you want the “Upload” button to work properly too with your custom debug adapter, you’ll have to teach PlatformIO the right upload command, which again involves OpenOCD. See upload_command — PlatformIO latest documentation. Something along the lines of

upload_protocol = custom
upload_flags =
    -s
    ${platformio.packages_dir}/tool-openocd/openocd/scripts
    -f
    interface/ftdi/c232hm.cfg
    -c
    "transport select jtag"
    -f
    target/stm32f4x.cfg
upload_command = ${platformio.packages_dir}/packages/tool-openocd/bin/openocd $UPLOAD_FLAGS -c "program {$SOURCE} 0x8000000 verify reset; shutdown;"

No, the FTDI 232H chip in the C232 has one channel, that can be either JTAG or UART. So you should undo that change by uninstalling that driver in the Windows device manager or use change it back in Zadig to what it was before (WinUSB probably), since changing that away to USB-CDC has destroyed OpenOCD’s capability to communicate with the adapter properly.

I have changed the driver back to WinUSB. Now I have the error:

The system can not find the specified path.

Platformio.ini

;PlatformIO Project Configuration File
;Debugger FTDI C232HM STM32

[env:debug_STM32F446RE]
platform = ststm32
framework = arduino
board = genericSTM32F446RE
monitor_speed= 115200
platform_packages = platformio/tool-openocd@^3.1200.0
debug_tool = custom
debug_server = 
    ${platformio.packages_dir}/packages/tool-openocd/bin/openocd
    -s 
    ${platformio.packages_dir}/packages/tool-openocd/openocd/scripts
    -f 
    interface/ftdi/c232hm.cfg
    -c 
    "transport select jtag" 
    -f
     target/stm32f4x.cfg

upload_protocol = custom
upload_flags =
    ${platformio.packages_dir}/packages/tool-openocd/bin/openocd
    -s 
    ${platformio.packages_dir}/packages/tool-openocd/openocd/scripts
    -f 
    interface/ftdi/c232hm.cfg
    -c 
    "transport select jtag" 
    -f
     target/stm32f4x.cfg
upload_command = ${platformio.packages_dir}/packages/tool-openocd/bin/openocd $UPLOAD_FLAGS -c "program {$SOURCE} 0x8000000 verify reset; shutdown;"

Error

Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   0.6% (used 832 bytes from 131072 bytes)
Flash: [          ]   0.7% (used 3636 bytes from 524288 bytes)
Building .pio\build\debug_STM32F446RE\firmware.bin
Configuring upload protocol...
AVAILABLE: blackmagic, custom, dfu, jlink, serial, stlink
CURRENT: upload_protocol = custom
Uploading .pio\build\debug_STM32F446RE\firmware.bin
The system cannot find the path specified.
*** [upload] Error 1

When I use the telnet terminal the connection does not work either.

Execute the project task → Advanced → “Verbose Upload” to see the exact uplaod invocation, maybe some error will be apparent there in the paths or command.

I do not see anything special or I am mistaken.

Processing debug_STM32F446RE (platform: ststm32; framework: arduino; board: genericSTM32F446RE; monitor_speed: 115200; platform_packages: platformio/tool-openocd@^3.1200.0; debug_tool: custom; debug_server: C:\Users\pleserf\.platformio\packages/packages/tool-openocd/bin/openocd, -s, C:\Users\pleserf\.platformio\packages/packages/tool-openocd/openocd/scripts, -f, interface/ftdi/c232hm.cfg, -c, "transport select jtag", -f, target/stm32f4x.cfg; upload_protocol: custom; upload_flags: C:\Users\pleserf\.platformio\packages/packages/tool-openocd/bin/openocd, -s, C:\Users\pleserf\.platformio\packages/packages/tool-openocd/openocd/scripts, -f, interface/ftdi/c232hm.cfg, -c, "transport select jtag", -f, target/stm32f4x.cfg; upload_command: C:\Users\pleserf\.platformio\packages/packages/tool-openocd/bin/openocd $UPLOAD_FLAGS -c "program {$SOURCE} 0x8000000 verify reset; shutdown;")
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/genericSTM32F446RE.html
PLATFORM: ST STM32 (17.0.0) > STM32F446RE (128k RAM. 512k Flash)
HARDWARE: STM32F446RET6 180MHz, 128KB RAM, 512KB Flash
DEBUG: Current (custom) External (blackmagic, jlink, stlink)
PACKAGES:
 - framework-arduinoststm32 @ 4.20600.231001 (2.6.0)
 - framework-cmsis @ 2.50700.210515 (5.7.0)
 - tool-dfuutil @ 1.11.0
 - tool-dfuutil-arduino @ 1.11.0
 - tool-openocd @ 3.1200.0 (12.0)
 - tool-stm32duino @ 1.0.2
 - toolchain-gccarmnoneeabi @ 1.120301.0 (12.3.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 12 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
MethodWrapper(["checkprogsize"], [".pio\build\debug_STM32F446RE\firmware.elf"])
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   0.6% (used 832 bytes from 131072 bytes)
Flash: [          ]   0.7% (used 3636 bytes from 524288 bytes)
.pio\build\debug_STM32F446RE\firmware.elf  :

section             size        addr

.isr_vector          452   134217728

.text               3552   134218180

.rodata                0   134221732

.ARM.extab             0   134221732

.ARM                   0   134221732

.preinit_array         0   134221732

.init_array            8   134221732

.fini_array            8   134221740

.data                 84   536870912

.bss                 748   536870996

.noinit                0   536871744

._user_heap_stack   1536   536871744

.ARM.attributes       48           0

.comment              57           0

Total               6493
<lambda>(["upload"], [".pio\build\debug_STM32F446RE\firmware.bin"])
AVAILABLE: blackmagic, custom, dfu, jlink, serial, stlink
CURRENT: upload_protocol = custom
C:\Users\pleserf\.platformio\packages/packages/tool-openocd/bin/openocd C:\Users\pleserf\.platformio\packages/packages/tool-openocd/bin/openocd -s C:\Users\pleserf\.platformio\packages/packages/tool-openocd/openocd/scripts -f interface/ftdi/c232hm.cfg -c ""transport select jtag"" -f target/stm32f4x.cfg -c "program {.pio\build\debug_STM32F446RE\firmware.bin} 0x8000000 verify reset; shutdown;"
The system cannot find the path specified.
*** [upload] Error 1

The quotes seems double. Try and remove them in

If I do it without quotes it does not work either.

Processing debug_STM32F446RE (platform: ststm32; framework: arduino; board: genericSTM32F446RE; monitor_speed: 115200; platform_packages: platformio/tool-openocd@^3.1200.0; debug_tool: custom; debug_server: C:\Users\pleserf\.platformio\packages/packages/tool-openocd/bin/openocd, -s, C:\Users\pleserf\.platformio\packages/packages/tool-openocd/openocd/scripts, -f, interface/ftdi/c232hm.cfg, -c, transport select jtag, -f, target/stm32f4x.cfg; upload_protocol: custom; upload_flags: C:\Users\pleserf\.platformio\packages/packages/tool-openocd/bin/openocd, -s, C:\Users\pleserf\.platformio\packages/packages/tool-openocd/openocd/scripts, -f, interface/ftdi/c232hm.cfg, -c, transport select jtag, -f, target/stm32f4x.cfg; upload_command: C:\Users\pleserf\.platformio\packages/packages/tool-openocd/bin/openocd $UPLOAD_FLAGS -c "program {$SOURCE} 0x8000000 verify reset; shutdown;")
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/genericSTM32F446RE.html
PLATFORM: ST STM32 (17.0.0) > STM32F446RE (128k RAM. 512k Flash)
HARDWARE: STM32F446RET6 180MHz, 128KB RAM, 512KB Flash
DEBUG: Current (custom) External (blackmagic, jlink, stlink)
PACKAGES: 
 - framework-arduinoststm32 @ 4.20600.231001 (2.6.0) 
 - framework-cmsis @ 2.50700.210515 (5.7.0) 
 - tool-dfuutil @ 1.11.0 
 - tool-dfuutil-arduino @ 1.11.0
 - tool-openocd @ 3.1200.0 (12.0)
 - tool-stm32duino @ 1.0.2
 - toolchain-gccarmnoneeabi @ 1.120301.0 (12.3.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 12 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
MethodWrapper(["checkprogsize"], [".pio\build\debug_STM32F446RE\firmware.elf"])
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   0.6% (used 832 bytes from 131072 bytes)
Flash: [          ]   0.7% (used 3636 bytes from 524288 bytes)
.pio\build\debug_STM32F446RE\firmware.elf  :

section             size        addr

.isr_vector          452   134217728

.text               3552   134218180

.rodata                0   134221732

.ARM.extab             0   134221732

.ARM                   0   134221732

.preinit_array         0   134221732

.init_array            8   134221732

.fini_array            8   134221740

.data                 84   536870912

.bss                 748   536870996

.noinit                0   536871744

._user_heap_stack   1536   536871744

.ARM.attributes       48           0

.comment              57           0

Total               6493
<lambda>(["upload"], [".pio\build\debug_STM32F446RE\firmware.bin"])
AVAILABLE: blackmagic, custom, dfu, jlink, serial, stlink
CURRENT: upload_protocol = custom
C:\Users\pleserf\.platformio\packages/packages/tool-openocd/bin/openocd C:\Users\pleserf\.platformio\packages/packages/tool-openocd/bin/openocd -s C:\Users\pleserf\.platformio\packages/packages/tool-openocd/openocd/scripts -f interface/ftdi/c232hm.cfg -c "transport select jtag" -f target/stm32f4x.cfg -c "program {.pio\build\debug_STM32F446RE\firmware.bin} 0x8000000 verify reset; shutdown;"
The system cannot find the path specified.
*** [upload] Error 1

Can you use pathes with \ instead of / and openocd.exe instead ofopenocd?

Ah no actually the error is obvious: Double packages/packages. There’s only supposed to be one. Try


[env:debug_STM32F446RE]
platform = ststm32
framework = arduino
board = genericSTM32F446RE
monitor_speed= 115200
platform_packages = platformio/tool-openocd@^3.1200.0
debug_tool = custom
debug_server = 
    ${platformio.packages_dir}/tool-openocd/bin/openocd
    -s 
    ${platformio.packages_dir}/tool-openocd/openocd/scripts
    -f 
    interface/ftdi/c232hm.cfg
    -c 
    "transport select jtag" 
    -f
     target/stm32f4x.cfg

upload_protocol = custom
upload_flags =
    ${platformio.packages_dir}/tool-openocd/bin/openocd
    -s 
    ${platformio.packages_dir}/tool-openocd/openocd/scripts
    -f 
    interface/ftdi/c232hm.cfg
    -c 
    transport select jtag
    -f
     target/stm32f4x.cfg
upload_command = ${platformio.packages_dir}/tool-openocd/bin/openocd $UPLOAD_FLAGS -c "program {$SOURCE} 0x8000000 verify reset; shutdown;"