peter-tanner.github.io/_posts/2024-03-02-Debugging-steps-for-CDC-USB-on-STM32-and-Platformio.md

2.0 KiB

title author date categories tags
Debugging steps for CDC USB on STM32 and Platformio peter 2024-03-02 21:58:54 +0800
Electronics
electronics
STM32
platformio

Progress to the next step if it still isn't working

Step 1: Have you put the required defines in your build flags?

The build flags enable the USB CDC functionality. Make sure to also set the CPU frequency, on my board I've used a 16 MHz crystal.

[env:genericSTM32F103C8]
platform = ststm32
board = genericSTM32F103C8
framework = arduino
upload_protocol = stlink
debug_tool = stlink
board_build.f_cpu = 16000000L   ; This should match your crystal oscillator frequency (On my board I've used a 16 MHz crystal)
monitor_dtr = 1

build_flags =
   -D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
   -D USBCON

Step 2: Does your MCU require a 1.5kR pullup resistor?

Consult ST application note AN4879, Table 3. Find your MCU series and check the "Embedded pull-up resistor on USB_DP line" column. In my case, unfortunately, I forgot to put the 1.5kR pullup resistor and I am using an STM32F103, which has a - in that column. The note (2) states:

To be compliant with the USB 2.0 full-speed electrical specification, the USB_DP (D+) pin must be pulled up to a voltage in the 3.0 to 3.6 V range with a 1.5 kΩ resistor.

Try putting a resistor on USB_DP, then reset and re-connect the MCU to your host device. It should work with any low-value resistor, in my case I used a 10kR through hole resistor since I was not at my lab. This worked and I received characters as long as the resistor was held there.

Step 3: ???

I've solved my issue with my custom board, but if you took more debugging steps feel free to leave your solutions in the comments below and I'll add them here.