cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with USB Host CDC class

mailforspam
Associate II
Posted on July 03, 2014 at 12:01

Hello,

I'm using STM32CubeMX to generate a project for STM32F207 that uses USB Host. The project compiles without problems. I have a custom USB device that uses CDC to send and receive serial data. When the device is attached to the USB host, it is detected correctly and the CDC class is being started. The functions for writing to and reading from the USB device are USBH_CDC_Transmit and USBH_CDC_Receive. These functions are non-blocking, and there are 2 callback functions that are called when the data have been transferred - USBH_CDC_TransmitCallback and USBH_CDC_ReceiveCallback. I have made some tests reading and writing the device and discovered, that I have to wait the last operation to finish before calling again the functions for reading or writing. The problem is that if I call USBH_CDC_Receive and the device is not sending anything at the moment, I cannot use the USB device anymore, I can call USBH_CDC_Transmit or USBH_CDC_Receive as much as I want, they won't block, but they just won't work. The detaching and attaching again of the device won't be detected by the USB Host Library. How can I find a workaround of that issue? I want to be able to read the USB device, but I don't know how much data I'm expecting, otherwise I would stop calling USBH_CDC_Receive.

#stm32cubemx #cdc #usb-host
11 REPLIES 11
qui_x
Associate
Posted on March 30, 2015 at 19:18

try to substitute

USBx_HC(chnum)->HCCHAR &= ~USB_OTG_HCCHAR_CHDIS; 
USBx_HC(chnum)->HCCHAR |= USB_OTG_HCCHAR_CHENA; 

with something like

uint32_t tmp;
tmp = USBx_HC(chnum)->HCCHAR;
tmp |= USB_OTG_HCCHAR_CHENA;
tmp &= ~ USB_OTG_HCCHAR_CHDIS;
USBx_HC(chnum)->HCCHAR = tmp;

all across the HOST code

christo
Associate III