cancel
Showing results for 
Search instead for 
Did you mean: 

Will ST be kind enough to provide a simple and complete example of implementing CDC (simple implementation of USB to UART communication similar to CP2102 and others) on an MCU e.g., STM32F103 or STM32F401, including any caveats?

SGupt.12
Associate
8 REPLIES 8

Aren't there CDC/VCP USB Device examples under the respective CubeF4 CubeF1 packages, and board example subdirectories?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
PHolt.1
Senior III

There are but they need integration and debugging.

I have CDC and MSC (the latter with FatFS, to SPI FLASH) both working in my project but it took a vast amount of work. I don't even know where to begin talking about it.

AScha.3
Chief III

https://wiki.st.com/stm32mcu/wiki/Introduction_to_USB_with_STM32

see:

https://controllerstech.com/usb-cdc-device-and-host-in-stm32/

If you feel a post has answered your question, please click "Accept as Solution".

That's because you did not use it as intended.

The proper usage is:

  1. download as it is to the board it's intended for
  2. lean back and enjoy

As soon as you start tinkering with the innards, it's not an *example* anymore, it's then *your project*. And none of USB, filestystems, SPI FLASH, and what you haven't mentioned, RTOS, none of these is in itself *simple* and their combination and interaction brings out all the devils in the nasty details exponentially.

There ain't no shortcut. You need to read and you need to learn. Examples are only one single fixed starting point, not the solution.

JW

PHolt.1
Senior III

I would debate that, because ST do "offer" the whole thing: USB, FreeRTOS, ETH, LWIP.

0693W00000UFPcPQAX.png 

They just chose to not integrate them properly. It's in bits around the place. Espressif OTOH did pay somebody to integrate all this and it works out of the box. Not bug free (some subtle bugs in their TinyUSB code) but a lot easier.

I would still use ST for commercial reasons (e.g. likely production life of 20 years on these "industrial" chips, chinese political risk on the key component, etc) but I can see why people go the ESP32 route. They save themselves a year of intense R&D.

BTW, my project started off as a hardware (circuit diagram) copy of an ST devt board (almost everybody does that) but still a vast amount of work was needed to get it to work properly.

RTOS itself is not an issue. It needs software to be written to be thread-safe, but it is basically easy and it is how one should be writing code anyway for embedded work. Variables on the stack, etc. I'd say the use of RTOS is the easiest thing on my whole project, and having an RTOS has made writing all the other stuff vastly easier because you don't have to create complicated "main loop" and state machine structures. You can also avoid a lot of ISRs, or at least keep ISRs very short. To create a new task (thread) you just write it, and set the priority, and the amount of stack, and off it goes. At the end (which should never be reached) you put a loop. 5 minutes' work. RTOS is a really brilliant thing to have; a huge timesaver, and enables easy creation of complex products.

I wonder what the OP is trying to do. If he's trying to build a serial to USB converter, he will for ever be dependent on ST to provide windows driver support for the VCP, whereas for the 2102, FT232, etc chips this is pretty well assured.

> BTW, my project started off as a hardware (circuit diagram) copy of an ST devt board (almost everybody does that) but still a vast amount of work was needed to get it to work properly.

I said:

>> download as it is to the board it's intended for

It's as if you'd bought some standard car, changed the engine for some hot rod thingy, and then complained that it fell out of the chassis while racing on a perfectly normal racing course.

JW

SGupt.12
Associate

Thank you all for sharing your thoughts.

I tend to agree that it is not simple. Yes! I have paid my dues, struggling with assembly code with primitive notepad-style compilers, OTP & UV ROMs. But technology has moved on. Thanks to ST for offering Cube MX software for easier program development.

USB-CDC has become almost a ubiquitous communication interface. Arduino-Pico library offers a built-in UDB-CDC interface without requiring any additional knowledge about USB-CDC. I am sure other MCU manufacturers are following suit.

I am an instrumentation and controls engineer and do not wish to spend time learning the nitty-gritty of USB. The USB interface is simply a means of transferring data, similar to UART, IIC, or SPI. Possibly it t is the reason behind the tremendous popularity of FT23, CP210x, and CH340 ICs. I am hoping ST will reevaluate its Middleware strategy and offer a CDC interface with default parameters without requiring any additional configuration. If not, a tiny one-dollar USB-UART module with a USB connector will be the salvation.

Regards,

Sudhir Gupta

Here you can find some free examples.

https://github.com/stm32-hotspot/I-CUBE-STDIO

PDF document

It looks like a library that allows redirecting stdin/stdout to various destinations including USB CDC and HID. I have not checked.