cancel
Showing results for 
Search instead for 
Did you mean: 

Has anyone created a USB MSC + HID driver for STM32F746 Discovery board?

anonymous.8
Senior II
Posted on May 06, 2017 at 00:47

Has anyone created a USB MSC + HID driver for STM32F746 Discovery board?

I have a working MSC only USB class for the STM32F746G Discovery board using the HAL PCD module and want to extend it to a USB composite device including a generic HID as well. The HID device would allows transfer of a generic 64 byte packet both ways between a PC and the device. I have such a composite device working on the STM32F4 discovery board but its uses the std periph library and the F4 series middleware USB driver.

To save me time and trouble (I always have trouble when using the wretched HAL layer), has anyone already done this for the F7 chips and could share their code with me?

Thanks.
6 REPLIES 6
anonymous.8
Senior II
Posted on June 01, 2017 at 15:36

So, no-one replied as obviously no-one had already achieved this. So I did it alone and now have a working USB composite (MSC + Custom HID)  device. I had to make substantial changes to the USB device core and initialization code as follows:

Several changes have been made to the USB device Init code for the application as well as changes to the usb device core data structures (usbd_def.h) and usbd_core.c/h and usbd_ctlreq.c/h.

1. USB directory structure: There are four sub-directories for the USB Composite device :

i. common - containing code common to both interfaces of the composite device. These are usbd_conf.c/h and usbd_desc_composite.c/h.

ii. devicecore - containing usbd_core.c/h, usbd_ctlreq.c/h, usbd_ioreq.c/h and usbd_def.h.

iii. hid – containing hid class specific code.

iv. msc – containing msc class specific code.

2. Changes to core data structures:

a. The configuration descriptor pointers - GetHSConfigDescriptor, GetFSConfigDescriptor, GetOtherSpeedConfigDescriptor and GetDeviceQualifierDescriptor have been moved out of the USBD_ClassTypeDef class data structure and into the USBD_DescriptorsTypeDef device data structure since they properly belong to the USB Device as a whole, not to any individual class.

b. The void *pClassData; and void *pUserData; pointers have been moved out of the USBD_DescriptorsTypeDef device data structure and into the USBD_ClassTypeDef class data structure since they are specific to each class instance (interface) and not the device as a whole.

c. The USBD_HandleTypeDef data structure now has an array of pointers to USBD_ClassTypeDef class data structures now called *pClass_Cb[USBD_NUM_INTERFACES] where USBD_NUM_INTERFACES is the number of classes (interfaces) comprising this composite device and is defined in usbd_conf.h.

d. In USBD_HandleTypeDef data structure , the USBD_DescriptorsTypeDef *pDesc pointer is renamed to*pDeviceDescriptor since pDesc is too brief and obscure in meaning.

 

3. Changes to usbd_core.c and usbd_ctlreq.c

Multiple changes were made to support the now USBD_NUM_INTERFACES instead of the previous single interface. A typical example in USBD_LL_DataOutStage() is:

for (int intfcNum = 0; intfcNum < USBD_NUM_INTERFACES; intfcNum++)

{

if ((pdev->pClass_Cb[intfcNum] != NULL) &&

(pdev->pClass_Cb[intfcNum]->EP0_RxReady != NULL) &&

(pdev->dev_state == USBD_STATE_CONFIGURED))

pdev->pClass_Cb[intfcNum]->EP0_RxReady(pdev);

}

Several changes similar to this are throughout usbd_core.c and usbd_ctlreq.c

4. Changes to application level USBD initialization code; My initialization code now looks like this:

void InitUSBInterface(void)

{

/* Init USB Device Library and composite USB Device*/

USBD_Init(&USBD_Device, &MSC_HID_DeviceDescriptors, 0);

// Add Supported USBD_MSC_CLASS_Callbacks/EndPoints and Add storage for MSC Class

USBD_Device.pClass_Cb[MSC_INTERFACE_NUM] = &USBD_MSC_CLASS_Callbacks;

USBD_Device.pClass_Cb[MSC_INTERFACE_NUM]->EP_IN_NUM = MSC_EPIN_NUM;

USBD_Device.pClass_Cb[MSC_INTERFACE_NUM]->EP_OUT_NUM = MSC_EPOUT_NUM;

USBD_Device.pClass_Cb[MSC_INTERFACE_NUM]->pUserData = &USBD_DISK_fops;

// Add Supported USBD_HID_CLASS_Callbacks/EndPoints for HID Class

USBD_Device.pClass_Cb[HID_INTERFACE_NUM] = &USBD_HID_CLASS_Callbacks;

USBD_Device.pClass_Cb[HID_INTERFACE_NUM]->EP_IN_NUM = HID_EPIN_NUM;

USBD_Device.pClass_Cb[HID_INTERFACE_NUM]->EP_OUT_NUM = HID_EPOUT_NUM;

USBD_Device.pClass_Cb[HID_INTERFACE_NUM]->pUserData = &USBD_CustomHID_fops;

/* Start Device Process */

USBD_Start(&USBD_Device);

}

The macro MSC_INTERFACE_NUM is defined in usbd_msc.h.

The macro HID_INTERFACE_NUM is defined in usbd_customhid.h.

This code has not been extensively tested but is working for me.

My code was designed to implement a custom HID interface using 64 byte OUT and IN packets that contain completely generic, i.e. vendor defined, data. I have the HID OUT endpoint # 2 working, the HID IN endpoint at address 0x82 is not yet fully verified. Instead I am using the Control Endpoint 0 and the standard HID SET_REPORT AND GET_REPORT requests to send data back and forth between the USB device and my PC.

And in the mean time, the MSC interface seems to be working well.

My USB code has been submitted to STM for consideration for inclusion in a future STM32F7Cube update.

Saeed Saeed
Associate II
Posted on August 04, 2017 at 16:05

I'm sorry to ask a question in your reply:

You have said 'I have such a composite device working on the STM32F4 discovery board but its uses the std periph library and the F4 series middleware USB driver', ST have a package for USB OTG based on std library, I'm trying to use that to have a host for simultaneous MSC and HID classes. But it seems that this is not possible by these libraries. Have you ever done something like this? If yes would you please help me?

I'm using std library for many years and it's not very easy to me to work with HAL drivers, so I have to use this package for USB host MSC+HID.

Thanks.

Posted on August 04, 2017 at 16:50

Sorry I can't help you as I have never had any experience with USB host firmware, only USB Device firmware.

adrian
Associate III
Posted on February 23, 2018 at 09:05

Awesome.  

I'm just about to start making the changes, but was wondering whether you had made your adapted version of the USB framework available anywhere to download?

Posted on March 23, 2018 at 11:36

Hi,

Can you share your code, i have a similar requirement for USB MSC+CDC

Lokesh

Posted on March 23, 2018 at 16:09

I have made a

https://community.st.com/0D50X00009XkVxaSAF

, available on GitHub. It also allows to have multiple interfaces of the same class and it routes the callbacks only to the desired interface. The currently adapted classes are HID and CDC, but it's not a big effort to add new ones to it. MSC class will be added in the near future.