Hi all!
Does anyone have an experience with making multi-interface (multi-class) USB with STM32F4 device? I am using STM32F4-discovery kit and usb library STM32_USB-Host-Device_Lib_V2.1.0. I have made my HID and MSC applications and now I wanna make a composite device with this classes.
The biggest problem is to set the callback functions for both interfaces. I tried to make one set of universal callbacks (for example one function USBD_HID_MSC_DataOut operating with both interfaces. The code inside the function is divided by endpoint number) but only HID is working. Windows recognize also Mass Storage device but cannot operate with it. I thing the USR_desc (User descriptors: SerialStrDescriptor, ConfigStrDescriptor, InterfaceStrDescriptor and so on) has also some impact. Does anyone made some USB composite application with this library? Thanks for comments.
Jan
I've looked in ST's STM32_USB-Host-Device_Lib_V2.1.0, and found that it isn't so easy to make it a composite device. The core-/ class-layer organization of this library is not good. When we plug-in two or more classes, duplicated processes on classes interfer each other. Such processes should be implemented in the core layer. It is obvious that ST have not achieved any composite device yet, on this library.
In my estimation, around 10-20% of the code in usbd_core.c, usbd_hid_core.c and usbd_msc_core.c should be touched. So, it will take long time. Wait it in patience ;-)
Tsuneo
Thanks, Tsuneo! I have done some progress and I haven't modified usbd_core.c. I have made the set of universal callbacks for both interfaces. The functions Init and Deinit can contain code for both classes without any branching. There was problem only that MSC calls DeInit in Init function. So I call special function for MSC_Deinit (only MSC). Now there is problem only with callback function USBD_HID_MSC_Setup. There are routines for interface requests. The requests are used by both classes.
case USB_REQ_GET_INTERFACE : USBD_CtlSendData (pdev,(uint8_t *)&USBD_HID_AltSet, 1); //USBD_CtlSendData (pdev,&USBD_MSC_AltSet, 1); break;
case USB_REQ_SET_INTERFACE : USBD_HID_AltSet = (uint8_t)(req->wValue); //USBD_MSC_AltSet = (uint8_t)(req->wValue); //MSC break;
I used the routines only for HID. Maybe it is interfering because of that.
In windows everything seems fine. SD card works fine with MSC. But there is always something sending and receiving via MSC endpoint. Even when SD card isn't plug-in. Thanks to this fact it seems the program doesn't have a time to serve buttons, LEDs, ADCs,... it serve only MSC and HID. So now only USB is working :D Can that be because of the things in Setup function? Why do you think I should touch the code in usbd_core.c? Sorry, if I described that unintelligibly. Thank you :)
to make a composite device with STM32_USB-Host-Device_Lib_V2.1.0 you must do this stages: 1-make your composite device describtore and pass it in GetConfigDescriptor class callback function 2-config your endpoints with DCD_EP_Open and DCD_EP_Close function in Init and DeInit class callback functions 3-use DCD_EP_Flush function for all new endpoints and make Out endpoits Prepare to recive data with DCD_EP_PrepareRx function in Init class callback function 4-config TXn_FIFO_FS_SIZE in usb_conf.h file
-note that for full speed device sum of RX_FIFO_FS_SIZE + TX0_FIFO_FS_SIZE + TX1_FIFO_FS_SIZE +TX2_FIFO_FS_SIZE can not be more than 320 so for example if you have 2 bidirectional endpoints(1(in and out) and 2(in and out)) other than endpoint0 correct values for RX_FIFO_FS_SIZE,TX0_FIFO_FS_SIZE,TX1_FIFO_FS_SIZE,TX2_FIFO_FS_SIZE are:
#define RX_FIFO_FS_SIZE 128 #define TX0_FIFO_FS_SIZE 64 //max packet size for endpoint0 #define TX1_FIFO_FS_SIZE 64 //max packet size for endpoint1 #define TX2_FIFO_FS_SIZE 64 //max packet size for endpoint2 #define TX3_FIFO_FS_SIZE 0
5-use your DataOut class callback with epnum parameter to manage which endpoint event callback occure