cancel
Showing results for 
Search instead for 
Did you mean: 

How can I temporalily detach/reattach the MSC only portion of a Composite USB MSC + HID Device from the device itself?

anonymous.8
Senior II
Posted on August 17, 2017 at 21:49

I have a USB Composite MSC + HID device running on an STM32F746NG (DISCO board) and using an SD card as the local storage. The device also has a local FAT file system accessing the same SD card. I want to be able to do file acesses using the local FATFS (Elm-Chan), but to do so I need to temporalily detach or disconnect the MSC only portion of the composite device while still leaving the HID part intact since that is the control channel from a PC application.

I have tried various means of disabling and re-enabling the MSC part when I do local disk I/O from the FATFs, but without fail, the USB MSC part then gets screwed up when I go to reaccess the same SD card from the PC side MSC. Windows tells me either the device is not there or that files are corrupted.

It is clear that while Windows thinks the USB MSC device is still attached, anything I do using the local FATFS, will mess up the USB MSC part so I need to somehow remove it (from within the device itself) and then reconnect it after I have finished with the local file access. I can't just turn off the USB I/F altogethrr because I still need the HID part of the composite device to continue running.

Can anyone suggest how I can do that?

Thanks.

4 REPLIES 4
Posted on August 17, 2017 at 22:09

Have the MSC throw 'Unit Not Ready', 'No Medium Present' or 'Medium Changed' type sense codes. ie in the same fashion as a USB card reader with no cards in, or other USBSTOR type device that can eject, or load/unload removable media.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on August 18, 2017 at 17:16

Clive, thanks for that. That works and it was easy. In the usbd_storage.c file I simply force the STORAGE_IsReady() function to return -1 instead of 0 when I want the MSC device to go away. It takes a second or two for it to disappear from Windows Explorer on the P.C. and several seconds for it to reappear when I allow the STORAGE_IsRead() function to return its normal value of 0.

Thanks for the hint.

feuerwolf
Senior
Posted on September 21, 2017 at 17:00

Hi,

i am working on a similar device, which logs GPS data on a SD Card. On my PCB the GPS USB Port and the STM32L073 USB can be connected via a USB HUB IC together to the PC. When connecting my Data Logger to the PC, MSC & GPS are available and accessible. This part works fine.

I also can eject the MSC by pushing a button while GPS is still connected.

What not works is remount the MSC – Windows  connection after the next button push.

Basically I want to switch mode Mount and Eject  every time I push the button without unplug the cable.

Until now I had a different approach as David who started this Discussion. I start the USB on a interrupt driven event with:

void

MX_USB_DEVICE_Init_aw(void)

{

  /*

Init

Device Library,Add Supported Class and Start the library*/

  USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS);

  USBD_RegisterClass(&hUsbDeviceFS, &USBD_MSC);

  USBD_MSC_RegisterStorage(&hUsbDeviceFS, &USBD_Storage_Interface_fops_FS);

  USBD_Start(&hUsbDeviceFS);

}

 

After all work is done with MSC do eject the MSC.

Ejecting the MSC as in USB Documentation UM1734 (DocID025934) page 24/25 proposed I call:

 

void

MX_USB_DEVICE_deInit_aw(void)

{

  //USBD_MSC_DeInit(&hUsbDeviceFS, 0);

  USBD_DeInit(&hUsbDeviceFS);

 // USBD_Stop(&hUsbDeviceFS);

}

Restarting the USB on the next event (which does not work) I would call:

void

MX_USB_DEVICE_reset_aw(void)

{

 USBD_LL_Reset(&hUsbDeviceFS);

}

And again:

void

MX_USB_DEVICE_Init_aw(void)

{

  /*

Init

Device Library,Add Supported Class and Start the library*/

  USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS);

  USBD_RegisterClass(&hUsbDeviceFS, &USBD_MSC);

  USBD_MSC_RegisterStorage(&hUsbDeviceFS, &USBD_Storage_Interface_fops_FS);

  USBD_Start(&hUsbDeviceFS);

}

So restarting doesn’t work. Can someone tell me, if my approach is somehow correct? I think I just miss to reset some USB registers, or . I got this working on a PIC32 but since I am very new to STM32 and its HAL I would appreciate any help. Thank you in advance

by the way, how to mark Code?

Posted on September 21, 2017 at 17:15

>>

by the way, how to mark Code?

 

Unfortunately it puts your post into moderation, so might be hours to clear that with every edit.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..