I've got such a task.
I need to make a double mode working USB0 port.
p.1) If I connect it to the PC windows see a internal flash disk (about 64kB size) - usb device mode.
A working example of it I've already made by modifying the usbd msc example with fat fs lib.
p.2) If I connect it by OTG cable to the Flash Drive(any) I need to automatically copy some file into internal flash disk
(mentioned in p. 1) - usb host mode.
A working example of it I've already made by using a usblib host msc example, also with fat fs.
But now I wanna join this two examples.
And there 're such a questions.
- How can I identify pc/flash mode automatically to switch between usb dev/host modes?
Does it real to make it such way? Maybe somebody has the same and there is some realization of this?
- How can I make two filesystems by Fat FS using two different disk access types(internal flash or external USB flash)?
All my best.
What you are trying to do is very much possible. I have done it with Mass storage host & custom device(connected to PC) on the same port.
By default you need to initialize USB in device mode, so when host(PC) is connected communication is done easily. But when another device(USB pen drive) is connected ID pin goes low & then initialize USB host so as to enumerate & communicate with connected device.
For Switching modes you need:-
1) switch for pull downs on D+ & D- lines(15k pull down)
2) switch for pull up on D+(1.5k) for full speed.
3) switch for VBUS(so that when device is connected +5v supply is provided).
4) ID pin connected to GPIO using 100k pull up.(to detect when device is connected).
Have you reviewed the Dual Hi-Speed USB Host/Device Solution examples?
Here is the link to the demo source code and documentation:
Hope it helps!
Technical Support Engineer