cancel
Showing results for 
Search instead for 
Did you mean: 

CP210x usb host class driver

christo
Associate III
Posted on September 19, 2015 at 00:10

Hi to All,

I make a step ahead with adding for testing purposes in usbh_cdc.c alternative staff in case of CP2102:

static USBH_StatusTypeDef USBH_CDC_InterfaceInit (USBH_HandleTypeDef *phost)
{ 
USBH_StatusTypeDef status = USBH_FAIL ;
uint8_t interface;
CDC_HandleTypeDef *CDC_Handle;
if (phost->pActiveClass->idVendor == 0x10c4 && phost->pActiveClass->idProduct == 0xea60) {
// CP2102
USBH_SelectInterface (phost, interface);
phost->pActiveClass->pData = (CDC_HandleTypeDef *)USBH_malloc (sizeof(CDC_HandleTypeDef));
CDC_Handle = (CDC_HandleTypeDef*) phost->pActiveClass->pData;
interface = USBH_FindInterface(phost,
0xff,
0x00,
0x00);
...
status = USBH_OK;
}
}
else {
 // CDC
 

interface = USBH_FindInterface(phost,
COMMUNICATION_INTERFACE_CLASS_CODE,
ABSTRACT_CONTROL_MODEL,
COMMON_AT_COMMAND);
...
status = USBH_OK;
}
}
}
return status;
}

Analogous alternative staff is added in

USBH_StatusTypeDef USBH_CDC_InterfaceDeInit (USBH_HandleTypeDef *phost)
{
CDC_HandleTypeDef *CDC_Handle = (CDC_HandleTypeDef*) phost->pActiveClass->pData;
if (phost->pActiveClass->idVendor == 0x10c4 && phost->pActiveClass->idProduct == 0xea60) {
// CP2102
...
}
else {
// CDC
...
}
return USBH_OK;
}

The result is:

// CP2102
USBH_UserProcess: HOST_USER_CONNECTION
USB Device Attached
PID: ea60h
VID: 10c4h
Address (#1) assigned.
Manufacturer : Silicon Labs
Product : CP2102 USB to UART Bridge Controller
Serial Number : 0001
Enumeration done.
This device has only 1 configuration.
Default configuration set.
Switching to Interface (#0)
Class : ffh
SubClass : 0h
Protocol : 0h
CDC class started.
USBH_UserProcess HOST_USER_CLASS_SELECTED: 255
USBH_UserProcess HOST_USER_DISCONNECTION: 255
USB Device disconnected
// CDC
USBH_UserProcess: HOST_USER_CONNECTION
USB Device Attached
PID: 5740h
VID: 483h
Address (#1) assigned.
Manufacturer : STMicroelectronics
Product : ChibiOS/RT Virtual COM Port
Serial Number : 301
Enumeration done.
This device has only 1 configuration.
Default configuration set.
Switching to Interface (#0)
Class : 2h
SubClass : 2h
Protocol : 1h
CDC class started.
USBH_UserProcess HOST_USER_CLASS_SELECTED: 2
USBH_UserProcess: HOST_CDC_CLASS_ACTIVATED
USBH_UserProcess HOST_USER_DISCONNECTION: 2
USB Device disconnected

The only stage did not present in case of CP2102 is:

HOST_CDC_CLASS_ACTIVATED

I try to follow the state machine logic and see that HOST_CHECK_CLASS passed successfully but next phase HOST_CLASS_REQUEST is not entered. I think that both cases have to follow the same logic so it is easier to test the things in a single file which will be split as CDC and CP210x host class drivers later on. Finally, some control functions have to be rewritten as well. The main difference for now between CDC and CP2102 cases is that CP2102 did not has control end point. Any ideas where to search the problem? Best regards Chris
10 REPLIES 10
IOvch
Associate II

Hello, christo! I am only started to do this. Have you realized this on STM32? Very interesting problem.

christo
Associate III

Hi Ivan

Unfortunately, I did not complete work on this idea. USB host functions enabled on STM32F4 MCU series of devices are not already attractive in times when Linux enabled embedded platforms become very low as a price.

The project (egpr.pro) provoked above work was changed as architecture by putting only the hard real-time functionality in STM32F405 and using its USB device connectivity. The main communications and data processing were put in Linux enabled A20 SOC based part acting as an application server. It gives an access to the low level control and the data processing result as a web service. A customer oriented data processing and control functionality was embedded in HTML 5 application running on any modern browser, OS and device.

Using Linux as a base and A20 communication and processing power turn the system in fully qualified Intranet one servicing the main application functionality and giving the customer advantages to connect to it all needed additional storage, communication etc. staff. In such a way using Ethernet and/or WiFi connectivity the system can run with and without connection to the Internet.

The main advantage in contemporary design is to be powerful but cheap in the software instead of limiting the hardware. Trying to move down a power hungry functionality (like USB Host, Ethernet etc.) in complex systems (with intensive data processing and extensive connectivity) always up the price / outcome ratio in all project stages (creation, usage, maintenance and later on development).

Of course, you can continue to drill down this interesting problem for fun or to learn, but to work professionally you can look at our experience.

Best regards and success

Chris

christo
Associate III

Hi Ivan

Find attached the project as-is. It was generated by STM32CubeMX 4.10.0 installed in Eclipse Mars Release (4.5.0). In addition you can find ab-tests-howto.pdf file with explanation how-to install and configure development environment. The binary can be uploaded and run on stm32f4Discovery and/or stm32f4-e407 board with USB Host connector wired.

In addition you can take a look on other discussions here:

Unfortunately, most of the details about my tests are nor clear so have a luck with the staff. It would be fine to have some feedback from you.

Best regards and success

Chris

christo
Associate III

Hi Ivan

Find attached a/b tests projects archive as described in ab-tests-howto.pdf file. They are simple CDC projects based on STM32CubeMX 4.10.0 and ChibiOS respectively running on stm32-e407 board.

It will be helpful to download and look at ah405-ulpi.zip attached to https://community.st.com/s/question/0D50X00009XkiCLSAZ/stm32f4-and-usb-fshs-with-ulpi discussion from 20 Dec 2018.

Best regards and success

Chris

Hi Christo! Thanks for this! I think all of this will be very helpful!

Hi @christo​ ,

I am trying to communicate with a CP210x based sensor with STM32F4. I can communicate with the sensor via putty at 19200 baud rate (1: Stop bits,8 bits data format, No parity). I have modified my firmware as based on your previous "STM32F4-DISCOVERY-USB-HOST-CDC-DEMO" project. After the modification the enumeration was done and identified the sensor and CDC class starts (output window inserted). But I couldn't communicate with the sensor with desired baud rate. In you project you have not handled the baud rate setting in the "Setlinecoding" function. So i had modified the that section as based on the CP210x linux based driver. But I am not sure I have done correctly. Once I try to communicate with the sensor, the firmware will held on the "CDC_ProcessReception" function, I couldn't get the USBH_URB_DONE in return.

Did you successfully communicate with CP210x based device as a CDC class driver? Can you share any completed example code ?

Thanks,

Param.

//  printf("DataItf.InPipe: %d, URB_Status: %d/%d\r", (int) CDC_Handle->DataItf.InPipe, URB_Status,
 
//			((HCD_HandleTypeDef *) phost->pData)->hc[(int) CDC_Handle->DataItf.InPipe].urb_state);
 
//
 
  printf("%d\r", URB_Status);
 
 
 
  /*Check the status done for reception*/
 
  if(URB_Status == USBH_URB_DONE )
 
  {
 
}
 

//Terminal I/O Output.
 
 
 
Device Connected
 
USB Device Reset Completed
 
PID: 80cah
 
VID: 10c4h
 
Address (#1) assigned.
 
Manufacturer : Silicon Labs
 
Product :  Series Sensor
 
Serial Number : 1211-1057241-010
 
Enumeration done.
 
This device has only 1 configuration.
 
Default configuration set.
 
Switching to Interface (#0)
 
Class  : ffh
 
SubClass : 0h
 
Protocol : 0h
 
Found in USBH_CDC_InterfaceInit:
 
	DataItf.OutPipe/OutEp/EpSize	2/03/64
 
	DataItf.InPipe/InEp/EpSize	3/83/64
 
CDC class started

Hi Param

The firmware based on "STM32F4-DISCOVERY-USB-HOST-CDC-DEMO" project is complete and it works like described at the end (Posted on September 26, 2015 at 11:02) of the following discussion:

Unfortunately, the baud rate and other control set is used as it is set at initialization (115200 bauds, 1 Stop bits, 8 bits data format, No parity). You probably didn't succeeded to control them via CDC protocol so try first to set them like at your device at initial phase. When the communication is successful try to control it via the protocol.

As I remember I have some problems to set port controls via the protocol so it will be good if you share your code at success. I plan to rebuild this demo with latest staff and put it at Github as open source project.

Best regards and success

Chris

Hi @christo​ ,

Sorry for the late reply. I had successfully communicated with the CP210x sensor with different baud rate levels. I had refer the following code for setting the flow control values.

https://github.com/henla464/USB_Host_Shield_Library_2.0/blob/master/CP210x.cpp~

Thanks for your help and much appreciated. :)

Param.

IChak.1
Associate II

Hi everyone, is it the same concept if i want to communicate with "ATmega16U2 (usb/serial bridge of Arduino uno)" by stm32f407g-disc1 USB as a HOST using CDC class ?

Thanks,