Skip to main content
Graduate II
September 3, 2025
Solved

Composite USB device MSC + Vendor

  • September 3, 2025
  • 4 replies
  • 588 views

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?

    This topic has been closed for replies.
    Best answer by MA4

    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.

    4 replies

    MA4Author
    Graduate II
    September 3, 2025

    I didn't specify, but it's a Vendor type with two bulk endpoints (1 IN and 1 OUT).

    MA4Author
    Graduate II
    September 3, 2025

    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

    MA4Author
    Graduate II
    September 4, 2025

    I look communication with Wireshark and it's like firmware stop responding et communication restart. I don't understand why.
    Screenshot 2025-09-04 at 10.32.27.png

    MA4AuthorAnswer
    Graduate II
    September 5, 2025

    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.