Author Topic: How to flip between cdc and msd in a composite device  (Read 13780 times)

Teejay

  • Member
  • ***
  • Posts: 3
How to flip between cdc and msd in a composite device
« on: May 21, 2014, 10:00:12 am »
I have a small bootloader with the cdc-msd composite device implementation, I want to be able to use the cdc and msd device separately, for example I want a keypress to enable the msd only and another keypress to enable the cdc only!

I have tried using the request sense keys to delay start the msd ( let windows know msd is not ready yet), but windows sends a bus rest to the device and the cdc stops working as well, could you please kindly point me as to how I can use the cdc and msd individually in a composite device, or a way to delay the starting of msd till I need it.


Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: How to flip between cdc and msd in a composite device
« Reply #1 on: May 21, 2014, 10:12:49 am »
The device could have two configurations, one for CDC and one for MSD. You would need to provide a low-level driver that switches between the configurations.

If all you want is to use CDC on startup, then switch to MSD, you could provide a driver with firmware support that emulates detach and reattach as MSD. 

Or emulate MSD with ejectable media, see:

http://janaxelson.com/forum/index.php?topic=1351.0


Teejay

  • Member
  • ***
  • Posts: 3
Re: How to flip between cdc and msd in a composite device
« Reply #2 on: May 21, 2014, 10:33:10 am »
Hello Jan

Thankyou very much for the prompt reply but I cannot figure out what changes I need to make to make the device appear as cdc or msd instead of the composite device. I have tried compiling it as a cdc device by not initializing the msd relevant bits, but it stops the usb com port from working as well.

regards

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: How to flip between cdc and msd in a composite device
« Reply #3 on: May 21, 2014, 10:39:37 am »
Give it two configuration descriptors, each with the interface(s) for one of the functions. You will need to provide a low-level host driver to switch configurations.

Barry Twycross

  • Frequent Contributor
  • ****
  • Posts: 263
Re: How to flip between cdc and msd in a composite device
« Reply #4 on: May 21, 2014, 02:52:52 pm »
We do it by having different modes in the device. If the button on the device is being pressed when the device is plugged in, it appears as mass storage (only). If the button on the device isn't pressed, it appears as CDC (only). The devices have different PIDs so Windows doesn't get confused. The device has to detach and reboot to get into the other mode.

Having the MSD give a status of not ready shouldn't cause Windows to reset your device. It doesn't with ours. What exact status are you returning? Are you sure you're getting the right message to Windows and there's not some other error causing Windows to reset you? Do you have an analyser to check this for real?

An alternate method is to be a fake removable media device. You set the RMB bit in the inquiry, and you report a status of not ready/no media, you should be able to do that forever, until you decide you want the media to appear.

Teejay

  • Member
  • ***
  • Posts: 3
Re: How to flip between cdc and msd in a composite device
« Reply #5 on: May 23, 2014, 09:43:11 am »
Barry
Thank you very much for your email I went back and checked! I was indeed missing some NOT_READY responses to windows. It is working fine now. Again thank you very much.

Jan

Thank you very much for your reply and also for writing the wonderful book on USB mass storage, It has helped me immensely!

for anyone else in a similar situation I was able to hold off the msd by sending SENSE = NOT_READY; ASC = 0x3a and ASQ = NO_SENSE in response to Reqest sense command; Inquiry command, Test unit ready command, read capacity command and read formar capacity command. Also command failed response to TUR , read capacity and read format capacity!

To get it back i was able to send unit attention back to windows by sending sense = UNIT_ATTENTION, ASC = 0x28 in response to the request sense command!

Thank you very much again and I hope you have a nice weekend!

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: How to flip between cdc and msd in a composite device
« Reply #6 on: May 27, 2014, 10:01:37 am »
Glad you got it working! Thanks for reporting what you did to get it working.