2020-08-12 04:19 AM
Hi,
Kindly advice how to communicate with an external device has CP210x with stm32f4 via USB FS mode. Is there any driver?
In my project i want to read an external sensor data via USB. That sensor transmitting the data via CP210x chip . Please advice.
Thanks,
Param.
2020-08-19 01:44 PM
Hi Param,
AFAIK you don't need any special driver for a USB to Serial converter.
Just setup your project with CubeMx so that the USB FS peripheral operates in USB-HOST-Mode and activate the support for the CDC class.
After setup and init the handling is quite easy as you can see in the code snipped below which is from an own, larger project. It handles mass storage devices and VCP devices in a RTOS thread which is called every 50ms. I used it to test the communication with an arduino board where some LEDs have been switched on and off by a serial command send from the host...
...
switch (usbfsHostStates_e) {
case USBFS_RESET:
if (hUsbHostFS.pActiveClass != NULL) {
usbDevClass_u32 = (uint32_t) USBH_GetActiveClass(&hUsbHostFS);
if (usbDevClass_u32 == USB_CDC_CLASS) {
usbfsModes_e = USBFS_MODE_HOST_CDC;
usbfsHostStates_e = USBFS_SERIALHOST;
}
else if (Appli_state == APPLICATION_READY) {
// We're connected and out of reset -> Proceed
usbfsModes_e = USBFS_MODE_HOST_MSC;
usbfsHostStates_e = USBFS_CONNECTED;
}
}
break;
case USBFS_SERIALHOST:
if (hUsbHostFS.pActiveClass == NULL) {
usbfsHostStates_e = USBFS_RESET;
}
else {
// For DEBUGGING: Send "power" to WS2812-Control PCB every 100*50ms = 5s
if (++counter_u32 >= 100) {
counter_u32 = 0;
USBH_CDC_Transmit(&hUsbHostFS, (uint8_t*) "power", 5);
}
}
break;
...
HTH,
Tobias