HAL Library Development Notes - USB Communication 🚧
This article is based on the in-house RobotCtrl development kit, with the microcontroller core being the STM32F407ZET6. The USB_Slave pins are PA11 and PA12. For the schematic and detailed information, please refer to RobotCtrl - STM32 Universal Development Kit.
Simple Loopback Test Steps
Configuration in CubeMX
- Configure for an external high-speed clock (HSE).
- Set up the clock tree, ensuring that the "48MHz Clocks (MHz)" at the end of the clock tree is set to 48MHz.
- On the
USB_OTG_FSpage, configure theModeasDevice_Only, with the default pins beingPA11andPA12. - On the
USB_DEVICEpage, set theClass For FS IPtoCommunication Device Class (Virtual Port Com).
Configuration in Code
To implement data loopback functionality, you only need to add one line within the CDC_Receive_FS function in the usbd_cdc_if.c file:
Testing
Open Device Manager to check if the device is displayed. If you cannot find the device or see a yellow exclamation mark, please download the driver from the ST website: STM32 Virtual COM Port Driver.
If you have installed the driver and still cannot recognize the device correctly, try adjusting the Minimum Heap Size to 0x600 or higher in CubeMX - Project Manager - Project - Linker Settings.
Open a terminal tool (baud rate can be set arbitrarily), and you will observe that when you send any character, it will return the same character.
References and Acknowledgments
Original: https://wiki-power.com/
This post is protected by CC BY-NC-SA 4.0 agreement, should be reproduced with attribution.This post is translated using ChatGPT, please feedback if any omissions.