3

I've been doing a lot of searching to try find some examples for printf debugging over USB for the STM32 (specifically stm32f1x). I have found a few examples for UART/USART however I can't find any for USB. Can anyone tell me if this is indeed possible and if it is point me to some examples?

Thanks.

matben243
  • 353
  • 2
  • 5
  • 10
  • 4
    I've only done a very limited amount with the STM32 series but just thought I'd check if you're aware that equivalent of a UART for USB is the CDC device class? Not sure if any one them work for that particular device but a search on "stm32 cdc" gives a few results. – PeterJ Jan 18 '15 at 13:23
  • I agree with @TurboJ's answer - better to use a UART. You (or future readers) may also find my answer here useful. http://electronics.stackexchange.com/questions/206113/how-do-i-use-the-printf-function-on-stm32/279945#279945 – cp.engr Jan 13 '17 at 05:42

1 Answers1

2

printf debugging over USB for the STM32

There is CDC example code that one could use for printf().

But I would not recommend using this, because USB is rather brittle in case of programming errors: The USB interrupt must be working correctly, the host won't accept the device otherwise.

Printf over UART/USART is far simpler, and you may need this connection for the bootloader anyway. Unless you have a JTAG/SWD debugger - but then there is no need for printf debugging in the first place.

Turbo J
  • 9,969
  • 1
  • 20
  • 28
  • It's indeed true, that especially early in development the brittleness of keeping the USB up is a good reason to break out a UART header as well. Unless the system is extremely space constrained, it's really worth bringing out all of SWD (since pretty much everyone playing with these has a $10 discovery board), UART, and if it's going to ultimately be used, USB. – Chris Stratton Jan 18 '15 at 17:11
  • 1
    "Unless you have a JTAG/SWD debugger - but then there is no need for printf debugging in the first place." - can you expand further? I am using JTAG, but setting breakpoints and manually checking values is not ideal when i want to see values within a multitask application with interrupts. Breaking the program affects the program flow, i.e. interrupts arrive while the program is at a breakpoint. Printf still has a (smaller) affect on timing but I would rather use it in this situation. Unless i can print over the JTAG connection I will invest in a uart-usb converter board and use uart. Thanks – matben243 Jan 18 '15 at 19:17
  • OpenOCD ships with a lib that can `printf()` over JTAG on Cortex M cores: DCC. – Turbo J Jan 18 '15 at 19:26