cancel
Showing results for 
Search instead for 
Did you mean: 

USB composite device first packet always empty

Nix Wayne
Associate III
Posted on November 13, 2017 at 23:41

Hi,

I am working with STM32F072RB and I am developing composite device. The device consists of 3 different interfaces but only one has in and out endpoints. It's custom HID with input and output report of 64 bytes. Really nothing special. My code includes many define switched so I can easily switch from composite device with 3 interfaces to simple Custom HID device. 

So to my question...

I am sending data from PC to device. If I am using device as a custom hid device I can receive data and DataOut function gets always called. 

static uint8_t USBD_HID_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum)

{...}

Received data is valid.

Then I switch to composite device configuration and that same Custom HID is just one those 3 interfaces in that composite device. In that case I experience strange behaviour...

The first packet I send from PC to device has all zeros inside... so no data is present. If I retry to send same data again I get valid data. So the first packet is always filled with zeros.  

Also

 USBD_HID_HandleTypeDef     *hhid = (USBD_HID_HandleTypeDef*)pdev->pClassData;  

hhid->IsReportAvailable is set to zero first time and next time to a some non-zero value (0xD0).

Any idea what I should look at?

Thank you in advance.

#usb #discovery #cubemx #usb-composite #stm32f072 #stm32f072-discovery #usb-device
2 REPLIES 2
Ben K
Senior III
Posted on November 14, 2017 at 11:06

How exactly did you (could you) implement a composite USB device using the STM32 USB Device Library? It is not designed to support devices with multiple classes. If you are using the classes from this library in your composite device, then the handling of 

pClassData definitely messed up, meaning that each class interprets the same memory as their own context. This is the most likely cause of the erratic behavior, and explains why you have invalid values in there.

Posted on November 14, 2017 at 16:00

Hi,

Well it's composed of composite device descriptor and one class as regular non-composite device. Then I have a wrapper for that class which includes list of links between subclasses and endpoints... so when there is a read or write request to main class I can parse EP address and I know to which 'subclass' I should dispatch data. 

Enumeration of device works fine. I checked it that I get all information in Windows with several different USB sniffers and descriptor readers and it just works.

Another thing... regarding my question... As soon as you mentioned variable pClassData I figured out... since I have subclasses.. every class wants to allocate data for pClassData so... you were right... I was actually overidding pointer value and of course data buffers... so what I did... I removed pClassData and replaced it by every subclass own variable such as pClass1Data, pClass2Data, pClass3Data. So every subclass allocates own instance of Class data structure.  And now it's working... and it has sense to.   I am reading and writting proper data into/from proper memory. 

Thank you for giving me a hint! I owe you a beer!