MSC + CDC Composite device example (STM32F3 Discovery)

This forum is about you. Feel free to discuss anything is related to embedded and electronics, your awesome projects, your ideas, your announcements, not necessarily related to ChibiOS but to embedded in general. This forum is NOT for support.
geoffrey.brown
Posts: 122
Joined: Thu May 07, 2015 9:47 pm
Has thanked: 3 times
Been thanked: 18 times

MSC + CDC Composite device example (STM32F3 Discovery)

Post by geoffrey.brown »

I've put an example project with a MSC/CDC composite device here:

https://github.com/geoffreymbrown/STM32 ... ry-CDC-MSD

all my testing has been on OS X, but an earlier version did work on Linux. Windows will take some effort by somebody who knows about USB composite devices an INF files. It's all pretty lightly tested, so don't expect production code.

The code is based upon the MSC code in ChibiOS-Contrib, with a small change needed to make it compile without a USB OTG device.


Geoffrey Brown
User avatar
tfAteba
Posts: 551
Joined: Fri Oct 16, 2015 11:03 pm
Has thanked: 91 times
Been thanked: 50 times

Re: MSC + CDC Composite device example (STM32F3 Discovery)

Post by tfAteba »

Hi Geoffrey.brown

Thanks for sharing you project with us. It is an interresting topic that you have here :)

Please can you move this post under User Projects because it is the best place to talk about projects and exchange about it.

Thank you.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: MSC + CDC Composite device example (STM32F3 Discovery)

Post by Giovanni »

He can't move the post, moving.

Giovanni
User avatar
tfAteba
Posts: 551
Joined: Fri Oct 16, 2015 11:03 pm
Has thanked: 91 times
Been thanked: 50 times

Re: MSC + CDC Composite device example (STM32F3 Discovery)

Post by tfAteba »

Thanks Giovanni, sorry Geoffrey.brown
geoffrey.brown
Posts: 122
Joined: Thu May 07, 2015 9:47 pm
Has thanked: 3 times
Been thanked: 18 times

Re: MSC + CDC Composite device example (STM32F3 Discovery)

Post by geoffrey.brown »

There's nothing to apologize for.
Geoffrey
Polux
Posts: 27
Joined: Thu Apr 28, 2016 11:52 am
Been thanked: 7 times

Re: MSC + CDC Composite device example (STM32F3 Discovery)

Post by Polux »

Hi,
Correct me if I am wrong. No .INF file will be needed for Windows, as CDC and MSD are natively supported by the system.
Long time ago, I did this on a LPC1769 and everything was automaticaly detected. But I can't remember if it was with MSD+CDC or 2xCDC.

Angelo
geoffrey.brown
Posts: 122
Joined: Thu May 07, 2015 9:47 pm
Has thanked: 3 times
Been thanked: 18 times

Re: MSC + CDC Composite device example (STM32F3 Discovery)

Post by geoffrey.brown »

You could well be right. I'm not a windows kind of guy and don't have and windows machines to try this on.

Geoffrey
User avatar
kimmoli
Posts: 26
Joined: Sat Oct 01, 2016 8:02 pm
Has thanked: 11 times
Been thanked: 8 times

Re: MSC + CDC Composite device example (STM32F3 Discovery)

Post by kimmoli »

Thanks for the great job here, this was just what i was looking for.

I took the ChibiOS-Contributions HAL_USB_MSD and Geoffreys STM32F3-Discovery-CDC-MSD example from github, tinkered it on top of my other code, and got it finally working on Windows.

I now have a composite device with mass storage and virtual serial port, which works on Windows and on Linux. (These i have to test with)

The ChibiOS-Contributions SCSI library is missing the vital product data inquiry (page 80h unit serial number response) response. Windows tries this three times when attaching device. Seems each fail to read this causes a 20 sec delay, so it takes 1 minute to mount the device. This is now fixed, pull-request soon in github.

This also touches the MSD hal as it initialises SCSI device. Unit serial number inquiry response struct can be passed through msdStart() as argument, just like the scsi_inquiry_response. We could also use always the default one and not allow user to override it. This would not break existing code using msdStart(). (?)

Also, Geoffreys' example had some differences to a working VCP demo, so i tweaked it just a bit to get VCP up on windows.
One was that the IAD block is not needed for the mass storage device, only for the VCP.
Second, i changed USB_EVENT_SUSPEND and USB_EVENT_WAKEUP event handlers as they are in working VCP demo.
I will throw you a pullrequest also if you want.

Windows .inf file for the composite device was after all 'easy'. Take a copy of ST VCP .ing file, and add two rows there, same in both [DeviceList...]
(DEAD/BEEF your VID/PID)

Code: Select all

[DeviceList.***]
%DESCRIPTION%=DriverInstall,USB\VID_0483&PID_5740
%DESCRIPTION%=DriverInstall,USB\VID_DEAD&PID_BEEF&MI_01 ; add this


EDIT: AFAIK the Windows native CDC drivers are crap, and ST provides drivers that is compatible with this solution, and they seem to be reliable(ish).

EDIT: The Contributions PR is here https://github.com/ChibiOS/ChibiOS-Contrib/pull/129
geoffrey.brown
Posts: 122
Joined: Thu May 07, 2015 9:47 pm
Has thanked: 3 times
Been thanked: 18 times

Re: MSC + CDC Composite device example (STM32F3 Discovery)

Post by geoffrey.brown »

That's terrific ! Thanks for taking it to 11 ! If you'll do a pull request on my repo, I'd love to integrate your fixes.

Geoffrey
User avatar
kimmoli
Posts: 26
Joined: Sat Oct 01, 2016 8:02 pm
Has thanked: 11 times
Been thanked: 8 times

Re: MSC + CDC Composite device example (STM32F3 Discovery)

Post by kimmoli »

I need to study this a bit more, the board surprise-reboots a few times per day.
I have most of CH_DBG_* on and no watchdog active, but still it just reboots.
Post Reply