2025-09-03 2:08 AM
Hello,
I'm working on a firmware which currently run in USB vendor interface (bInterfaceClass = 0xFF) and it's working.
Now I want to add MassStorage. My Firmware is a bit older so I add all usb composite parte by my self (in usbd_core ...) . I defined USE_USBD_COMPOSITE and set :
#define USBD_CMPSIT_ACTIVATE_MSC 1
#define USBD_CMPSIT_ACTIVATE_CUSTOMHID 1
#define USBD_MAX_CLASS_INTERFACES 2U
#define USBD_MAX_SUPPORTED_CLASS 2U
#define USBD_MAX_CLASS_ENDPOINTS 2U
(I use custom HID class for the Vendor interface and I edited USBD_CMPSIT_CUSTOMHIDDesc )
I set Msc first 'cause I read that some OS prefer.
Init function :
void MX_USB_DEVICE_Init(void)
{
#ifdef STM32H7xx
HAL_PWREx_EnableUSBVoltageDetector();
#endif //STM32H7xx
/* Init Device Library, add supported class and start the library. */
if (USBD_Init(&hUsbDeviceHS, &HS_Desc, DEVICE_HS) != USBD_OK)
{
DEBUG_PRINTF("[MX_USB_DEVICE_Init] USB failed to init \r\n");
}
//register classes
MassStorage_InstID = hUsbDeviceHS.classId;
USBD_RegisterClassComposite(&hUsbDeviceHS, &MassStorageDevice, CLASS_TYPE_MSC,MassStorage_EpAdress);
Usb_InstID = hUsbDeviceHS.classId;
USBD_RegisterClassComposite(&hUsbDeviceHS, &Usb_STM32xx, CLASS_TYPE_CHID, Usb_EpAdress);
if (USBD_CMPSIT_SetClassID(&hUsbDeviceHS, CLASS_TYPE_MSC, 0) != 0xFF)
{
if(RegisterStorage(&hUsbDeviceHS, &MassStorage_fops_HS) != USBD_OK)
{
DEBUG_PRINTF("[MX_USB_DEVICE_Init] register MassStorage interface failed to init \r\n");
}
}
//register interfaces
if (USBD_CMPSIT_SetClassID(&hUsbDeviceHS, CLASS_TYPE_CHID, 0) != 0xFF)
{
if (Usb_RegisterInterface(&hUsbDeviceHS, &Usb_fops_HS) != USBD_OK)
{
DEBUG_PRINTF("[MX_USB_DEVICE_Init] register Usb interface failed to init \r\n");
}
}
}
But when I run I feel like the first interface start (Msc) and then stop responding when the second try to start and when nothing works.
Does anyone have any idea what I'm doing wrong?
Solved! Go to Solution.
2025-09-05 7:34 AM
On Wireshark we can see that host (PC) ask to read Len:8 that means 8*512 =4 096 and the firmware answer with a 576 data packet. So host reset the usb because he doesn't like the answer.
My issue was a SD read issue not USB.
2025-09-03 2:14 AM
I didn't specify, but it's a Vendor type with two bulk endpoints (1 IN and 1 OUT).
2025-09-03 6:27 AM
I have some logs if it's can help :
usb-storage 1-2:1.0: USB Mass Storage device detected
scsi host4: scsi_eh_4: sleeping
scsi host4: usb-storage 1-2:1.0
scsi 4:0:0:0: Direct-Access SD 0.01 PQ: 0 ANSI: 2
sd 4:0:0:0: Attached scsi generic sg2 type 0
sd 4:0:0:0: [sdb] 61849599 512-byte logical blocks: (31.7 GB/29.5 GiB)
usb 1-2: reset high-speed USB device number 50 using ehci-pci
sd 4:0:0:0: [sdb] Write Protect is off
sd 4:0:0:0: [sdb] Mode Sense: 03 00 00 00
sd 4:0:0:0: [sdb] No Caching mode page found
sd 4:0:0:0: [sdb] Assuming drive cache: write through
sd 4:0:0:0: [sdb] tag#0 abort scheduled
sd 4:0:0:0: [sdb] tag#0 aborting command
usb 1-2: reset high-speed USB device number 50 using ehci-pci
sd 4:0:0:0: [sdb] tag#0 finish aborted command
2025-09-04 1:34 AM
I look communication with Wireshark and it's like firmware stop responding et communication restart. I don't understand why.
2025-09-05 7:34 AM
On Wireshark we can see that host (PC) ask to read Len:8 that means 8*512 =4 096 and the firmware answer with a 576 data packet. So host reset the usb because he doesn't like the answer.
My issue was a SD read issue not USB.