cancel
Showing results for 
Search instead for 
Did you mean: 

USB Virtual Port Com as USB->Serial Converter

LMorr.3
Senior II

I am using a STM32F373 with the USB Middleware set to 'Communication Device Class (Virtual Port Com)'.

Is it possible to have it 'act' as a UART or SPI type port, or do I need to hook into the USB library to TX/RX data over USB?  

I currently use USART2 with a USB->SERIAL converter connected between my PC and STM32, but would like to eliminate the need to have it if I can find a way to get the built-in USB Middleware to act as a converter. 

I'm also looking at using a FTDI FT231XS-U IC as an on-board USB->Serial converter so only a plain USB cable is needed to connect the board.

Thanks,

1 ACCEPTED SOLUTION

Accepted Solutions

There are typically USB CDC Device examples   https://github.com/STMicroelectronics/STM32CubeF3/tree/master/Projects/STM32373C_EVAL/Applications/USB_Device/CDC_Standalone

You need to replace the USART plumbing with your own way of managing the data to/from the USB. ie buffers, parsing, responses, etc.

https://github.com/STMicroelectronics/STM32CubeF3/blob/master/Projects/STM32373C_EVAL/Applications/USB_Device/CDC_Standalone/Src/usbd_cdc_interface.c

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

View solution in original post

4 REPLIES 4

There are typically USB CDC Device examples   https://github.com/STMicroelectronics/STM32CubeF3/tree/master/Projects/STM32373C_EVAL/Applications/USB_Device/CDC_Standalone

You need to replace the USART plumbing with your own way of managing the data to/from the USB. ie buffers, parsing, responses, etc.

https://github.com/STMicroelectronics/STM32CubeF3/blob/master/Projects/STM32373C_EVAL/Applications/USB_Device/CDC_Standalone/Src/usbd_cdc_interface.c

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

> Is it possible to have it 'act' as a UART or SPI type port,

USB isn't going to act like UART or SPI. It's USB and you need to implement the machinery that USB requires. In this case, the CDC device type.

If you use a FT231 chip instead, you can just use a UART, but you will suffer some loss of speed as a result. May or may not be an issue.

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

I was using USART's idle interrupt to detect when the PC was done sending a fixed sized packet of 15 bytes.  I now see that the USB Device in CDC mode's rx callback can be used in the same way as the USART Idle callback.  

My only question; If the PC host sends 15 bytes, will the CDC_Receive_FS callback parameters Len and Buf  always be 15 bytes, or is there a chance the 15 bytes may be received in 2 events?  For example, is it possible the CDC_Receive_FS callback gets called twice, once with a Len of let say 10 bytes, and a second time with a length of 5 bytes?  I'm guessing the Len value will always be 15 bytes if that is what the PC host sends, and that is handled by USB CDC.  ( as long as i've set the max size USB can send to more than 15 bytes )

Piranha
Chief II

No, USART, USB CDC and TCP are stream interfaces and doesn't have a concept of messages. Therefore bytes can come in an arbitrary sized blocks.