3
\$\begingroup\$

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.

\$\endgroup\$
  • 4
    \$\begingroup\$ 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. \$\endgroup\$ – PeterJ Jan 18 '15 at 13:23
  • \$\begingroup\$ I agree with @TurboJ's answer - better to use a UART. You (or future readers) may also find my answer here useful. electronics.stackexchange.com/questions/206113/… \$\endgroup\$ – cp.engr Jan 13 '17 at 5:42
2
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ 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. \$\endgroup\$ – Chris Stratton Jan 18 '15 at 17:11
  • 1
    \$\begingroup\$ "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 \$\endgroup\$ – matben243 Jan 18 '15 at 19:17
  • \$\begingroup\$ OpenOCD ships with a lib that can printf() over JTAG on Cortex M cores: DCC. \$\endgroup\$ – Turbo J Jan 18 '15 at 19:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.