2023-11-25 12:07 PM - edited 2023-11-25 12:09 PM
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,
Solved! Go to Solution.
2023-11-25 01:37 PM - edited 2023-11-25 03:45 PM
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.
2023-11-25 01:37 PM - edited 2023-11-25 03:45 PM
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.
2023-11-25 03:29 PM
> 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.
2023-11-25 05:46 PM
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 )
2023-11-26 04:04 PM
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.