【STM32U5A5ZJ development board】USB device and VCP communication test
[Copy link]
The USB on the STM32U5A5ZJ is an OTG USB device with its own PHY. It not only has power management but also device management functions, and the interface used is also a Type C interface.
The use of USB devices is much more complicated than other serial buses. In addition to initialization and enumeration registration during the communication process, it is also necessary to perform the communication process asynchronously. Therefore, ST has launched the relevant functions of the supporting HAL and LL libraries to cooperate with the development. It is especially complicated in the case of operating systems, but at the same time RTOS also brings convenience to programming and use. This test uses THREADX and the supporting USBX and USBPD middleware.
1. USB device driver settings
The USB device settings consist of two parts: power management and USB communication pin settings. There are two groups of settings: UCPD and USB_OTG_HS.
UCPD1 is the related pin setting of OTG power management specified by ST toolkit. It is mainly used to cooperate with USBPD middleware.
USB_OTG_HS is a setting related to the USB device driver, and it also needs to be set in conjunction with USBX. For settings, please refer to the relevant routines.
These two sets of settings are required for ST drivers.
2. USBX Settings
After selecting THREADX support, if you need USB device support, you need to use the supporting USBX library. USBX is the management library of USB devices supporting THREADX, which supports a variety of USB devices. In this test, CDC_ACM support is used. This device is a USB to serial port device. The converted serial port can work just by using the driver of the host computer.
You can refer to the settings in the picture above.
3. USB PD settings
USBPD is USB power management middleware used to simplify USB power management and provide drivers.
For specific settings, please refer to the relevant routine (Ux_Device_CDC_ACM).
4. Program code and usage
The program code consists of two parts: application and device management and initialization.
The device programming program can refer to the relevant routines. It is in a fixed format and can be used without modification.
This program will internally associate UART1 with the USB VPC, so that UART programming can be converted to VPC.
Testing process
After inserting the USB Type C cable, two serial ports, COM8 and COM5, can be enumerated. COM8 is the UART1 serial port for debugging, and USB5 is the VCP serial port of this OTG.
1. Send a message through COM5.
This message can be received on COM8.
Messages sent on COM8 can also be received on UART1's COM8 serial port.
|