USB - FS
Clock Settings
USB requires a relatively precise 48MHz clock supplied to the peripheral module. Thus, it requires us to use external crystal as the clock source.
In the RCC section, enable HSE.

Configure the clock tree to supply 48MHz to USB clock domain.
As Virtual COM Port (COM)
1.Enable USB FS support

Enable USB_DEVICE
Select class as "Communication Device Class (Vistual Port Com)"

Generate code
In addition to the default folders, it will also generate "USB_DEVICE" folder.

In the usbd_cdc_if.c file, we have the receive and transmit functions
Every message received will invoke the static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len) function.
And we can use the uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len) function to transmit data.
Simple Echo USB VCP Device
To build a simple echo program, we just need to implement the transmit in the USB receive handler.
CAN-USB Adapter
Here's a more complete code example, implementing CAN-USB message transfer.
main.c:
usbd_cdc_if.c:
Last updated