cancel
Showing results for 
Search instead for 
Did you mean: 

STM32Cube USB Composite device CDC + MSC

Lori B.
Associate III
Posted on July 25, 2016 at 17:08

 

 

The original post was too long to process during our migration. Please click on the attachment to read the original post.
9 REPLIES 9
tsuneo
Senior
Posted on July 26, 2016 at 07:42

Hi Iori,

> The MSC interface instead seems a little bit more reliable and almost performs well when I leave the TxFifo and RxFifo function to their default value, so once again I think that the major problem is in that 3/4 lines. The rules to determine FIFO value are pretty complicated. 1. The value of ''size'' argument on HAL_PCD(Ex)_SetRxFiFo() and HAL_PCD(Ex)_SetTxFiFo() is represented in terms of 32-bit DWORD (4bytes). The total of these values should not exceed the size of the USB data RAM (OTG_FS: 1.25 KB, OTG_HS: 4 KB) 2. To the RxFIFO, the device engine stores these data, - 10 DWORDs are reserved for SETUP packets (up to 3) + single counter DWORD - 2 DWORDs status + payload (packet) of each OUT transaction Minimum value is, 10 DWORDs + {2 DWORDS + the largest MPS (Max Packet Size) among the OUT endpoints (including EP0OUT)}, or 16 DWORDs Maximum value is 256 DWORDs 3. Each TxFIFO size must be no less than the endpoint's MPS. Minimum value is 16 DWORDs. Maximum value is min( 8 x MPS, 256 DWORDs ). No status DWORD is assigned to each packet. Recommended setup is as follows,

HAL_PCD_SetRxFiFo(&hpcd_USB_OTG_FS, 0x80); // RxFIFO: 512 bytes
HAL_PCD_SetTxFiFo(&hpcd_USB_OTG_FS, 0, 0x10); // EP0IN: 64 bytes
HAL_PCD_SetTxFiFo(&hpcd_USB_OTG_FS, 1, 0x80); // MSC bulk IN: 512 bytes
HAL_PCD_SetTxFiFo(&hpcd_USB_OTG_FS, 2, 0x10); // CDC interrupt IN: 64 bytes
HAL_PCD_SetTxFiFo(&hpcd_USB_OTG_FS, 3, 0x20); // CDC bulk IN: 128 bytes
// total 1280 bytes

> The problem is that I can use correctly the virtual com port when i set the original PID=0x5470 (5740 ?), while switching to 0x5471 (also changing it in the .inf file and reinstalling the driver) doesn't work. To support the CDC interface at the interface number 1 (&MI_01), INF file should be modified as follows,

[DeviceList.NT]
%DESCRIPTION%=DriverInstall,USB\VID_0483&PID_5741&MI_01
[DeviceList.NTamd64]
%DESCRIPTION%=DriverInstall,USB\VID_0483&PID_5741&MI_01

To apply new INF, delete (uninstall) former device instance on the Device Manager.

http://www.nirsoft.net/utils/usb_devices_view.html

is a handy tool to manage installed USB devices. Tsuneo
Lori B.
Associate III
Posted on July 26, 2016 at 09:07

Hi Tsuneo! I have to tell you: I was hoping for you to answer me, so thanks for posting!

1, 2. I wouldn't have known where to find the info you just wrote, so thank you for your clarity. Even now the mechanism is pretty hard for me but at least I can make some counts. 3. Trying your recommended setup didn't work for me, I would get a not recognized usb device. But tuning to this configuration seems to work, what do you think about it?

 HAL_PCD_SetRxFiFo(&hpcd_USB_OTG_FS, 0x80); 
// RxFIFO: 512 bytes = 128 * 4BytesPerWord
HAL_PCD_SetTxFiFo(&hpcd_USB_OTG_FS, 0, 0x40); 
// EP0IN: 256 bytes
HAL_PCD_SetTxFiFo(&hpcd_USB_OTG_FS, 1, 0x40); 
// MSC bulk IN: 256 bytes
HAL_PCD_SetTxFiFo(&hpcd_USB_OTG_FS, 2, 0x10); 
// CDC interrupt IN: 64 bytes
HAL_PCD_SetTxFiFo(&hpcd_USB_OTG_FS, 3, 0x20); 
// CDC bulk IN: 128 bytes
// total 1216 bytes

In this way I can have the MSC working and the CDC installed and open, but when I try to write data to the PC I get stucked on

while
(pCDC->TxState) { }

in myCDC_Transmit() function. Beside that, I still don't know how to merge the registration of the two interfaces at the same time. I'm talking about getting togheter this two distinct class functions

USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS);
USBD_MSC_RegisterStorage(&hUsbDeviceFS, &USBD_Storage_Interface_fops_FS);

Do you have any hint about that? Talking about the .inf driver, I was already adding the ''&MI_01'' and now with the right FIFO settings, it succeded installing the virtual com (finally!!) with PID 0x5741 (sorry about switching the two numbers, my bad :) ) I was using ''DeviceCleanup'' tool for uninstalling the device at every change, but your application seems to go a little deeper, so once again, thank you!
tsuneo
Senior
Posted on July 26, 2016 at 15:11

> But tuning to this configuration seems to work, what do you think about it?

 

>  HAL_PCD_SetTxFiFo(&hpcd_USB_OTG_FS, 0, 0x40);  // EP0IN:           256 bytes

Maybe, it suggests a bug in the stack.

Your setup assigns greater size to EP0IN FIFO than the config descriptor. But the EP0IN FIFO should work with MPS, at least, less than the config descriptor. With quick look in the stack code, I found a couple of suspicious lines. After confirming it, I'll report it to the Software Tools forum.

> but when I try to write data to the PC I get stucked on

 

> while (pCDC->TxState) { }

Before calling CDC_Transmit(), confirm that the device reaches to CONFIGURED state,

  if (hUsbDeviceFS.dev_state == USBD_STATE_CONFIGURED)

in which USBD_CDC_Init() opens the CDC bulk endpoints.

 

> Beside that, I still don't know how to merge the registration of the two interfaces at the same time.

The contents of USBD_CDC_RegisterInterface() and USBD_MSC_RegisterStorage() are identical. You may apply one of them, as your first post does.

Tsuneo

Lori B.
Associate III
Posted on July 26, 2016 at 17:45

>Maybe, it suggests a bug in the stack.

 

This goes far beyond my knokledge of the peripheral. I would be grateful to follow the discussion and eventual fixesthough.

>Before calling CDC_Transmit(), confirm that the device reaches to CONFIGURED state,I already check this before checking the TxState.

>The contents of USBD_CDC_RegisterInterface() and USBD_MSC_RegisterStorage() are identical. You may apply one of them, as your first post does.

Are you shure about that? The functions act the same way, but thefops parameter are different from cdc and msc.

USBD_CDC_ItfTypeDef USBD_Interface_fops_FS =
{
CDC_Init,
CDC_DeInit,
CDC_Control, 
CDC_Receive
};
USBD_StorageTypeDef USBD_Storage_Interface_fops_FS =
{
STORAGE_Init_FS,
STORAGE_GetCapacity_FS,
STORAGE_IsReady_FS,
STORAGE_IsWriteProtected_FS,
STORAGE_Read_FS,
STORAGE_Write_FS,
STORAGE_GetMaxLun_FS,
(int8_t *)STORAGE_Inquirydata_FS,
};

Today i worked on a cdc and msc interface wrapper, starting from a fops structure that holds all the necessary functions.

USBD_CDC_MSC_ItfTypeDef USBD_CDC_MSC_Interface_fops_FS = 
{
CDC_MSC_Init,
CDC_MSC_GetCapacity,
CDC_MSC_IsReady,
CDC_MSC_IsWriteProtected,
CDC_MSC_Read,
CDC_MSC_Write,
CDC_MSC_GetMaxLun,
(int8_t *)CDC_MSC_Inquirydata, 
CDC_MSC_DeInit,
CDC_MSC_Control, 
CDC_MSC_Receive,
};

Since I saw a lot of casts to

USBD_CDC_ItfTypeDef and

USBD_StorageTypeDef in the init and setup functions of the cdc and msc classes, I also rewrote my cdc_msc class differently.

You can find the two files

attached.

In this way I can install correclty the two interfaces. MSC works fine, also after disconnecting and reconnectinf the usb cable.

CDC though isn't ok yet. I can open the virtual com port recive and write a buffer, but apart from the first one I can't recive any other buffer.

Looks like my RxBuffer doesn't get set and filled anymore. I'm getting quite crazy!

________________

Attachments :

usbd_cdc_msc.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0uu&d=%2Fa%2F0X0000000bfW%2FCUn8g.iPTditq3mZncoGzcJ2tU9X.bbpad87TcMqneQ&asPdf=false
dgrobinson
Associate
Posted on February 21, 2017 at 22:34

Did you ever get a good answer to this?

I am working through the same issues.

--Daniel

Posted on February 23, 2017 at 08:20

Hi Daniel,

I managed to have a composite class device working, but the CDC part was not 100% reliable.

So I gave up and I used the two classes separatly in my project.

Anyway I planned to write an example on composite class based on STM32Cube to share.

Once it will be ok, I'm posting it here!
Posted on March 12, 2017 at 16:49

Bruno.Lorenzo

‌ any updates on composite device looking to get it running to make my life easier testing my prototype.

Posted on July 25, 2017 at 15:48

hi Lori ,  could you send link to your project ? it will be very helpfull

Hau Lam
Associate II
Posted on April 04, 2018 at 10:02

Bruno.Lorenzo

‌ : i also working on composite MSC and CDC together, Is it possible if I use USB HS for MSC and USB FS for CDC ? Thank you very much.