cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F411VE - How to use one USB-A connector to read/write flash USB keys and to send/receive data with a PC

gdivella84
Associate II

Hello everybody,

I'm new to USB development then excuse me if my questions are trivial.

I have a board with the attached electric scheme (only USB section shown).

The application I want to realize must do, with the provided HW, the following:

  • Read/Write data from/to a USB key
  • Send/receive data to/from a PC with a hyperterminal-like app

Reading here and there over the web I learnt that the former needs my MCU to be configured as a USB HOST MSC, and the latter as a USB DEVICE CDC.

First question: as I need to connect to a PC for serial logging, my configuration cannot be USB HOST CDC, but USB DEVICE CDC, correct?

Second question(s): suppose my HW cannot be modified at the moment. Is it possible to switch between HOST MSC / DEVICE CDC just by software routines? If yes, not being able to sense VBUS might be a problem? Should I power off my VBUS every time I switch from HOST to DEVICE ?

Please consider that the machine mounting this board must expose a type-A USB connector for user operations with USB keys. This, if I understood everything well, obliges me not to use the OTG functionalities for my purposes

Thank you very much

0690X000009Z0ixQAC.jpg

1 ACCEPTED SOLUTION

Accepted Solutions

> First question: as I need to connect to a PC for serial logging, my configuration cannot be USB HOST CDC, but USB DEVICE CDC, correct?

Well, not necessarily. You can build a contraption with two CDC devices, cross-connected at the serial side, to connect to CDC hosts together. There are such "cables" around, enabling to connect two PCs, but the devices within require specific drivers (FT232 etc.). But if you want to solve your problem using a nonstandard-but-purchasible A-A cable, then yes, you need to do the host-to-device switch when you want to change role.

You won't be able to do both the MSC host and CDC device at the same time, of course, but you've probably considered this already.

> If yes, not being able to sense VBUS might be a problem? Should I power off my VBUS every time I switch from HOST to DEVICE ?

VBUS sensing is not a necessity in device. You just won't be able to distinguish between states when host suspends the bus and when the host is removed altogether, but that for the vast majority of practical purposes is not a problem (it would be a problem only if you'd need to distinguish, whether you would be able to wake up a suspended host, or wouldn't because it's not there, and e.g. present this information to the user).

You also don't need OTG as such, as - after having solved the issue of switching between device and host through some different mechanism - the remaining features falling under OTG are secondary such as as methods distinghishing which party is the power source.

There is also a question you did not ask but maybe you want to know: whether all this or most of it can be clicked in CubeMX. I don't know, I don't use Cube nor CubeMX.

JW

View solution in original post

7 REPLIES 7

Well, you're not going to go for an official USB certification, so you don't need to use the hardware ID pin (which is normally used to switch role in OTG). It does not do much more than throwing an interrupt which then handles the shutdown of one machine and startup of the other, so you can do the same upon any stimulus of your choice.

JW

Thank you for the answer. Would you be so kind to have a look also to the other questions?

Regards

I have not much experience with USB applications either.

Would a SD card (or similar), instead of the Host MSC device, be an option ?

then thanks for the effort ;)

not at all for the SD

> First question: as I need to connect to a PC for serial logging, my configuration cannot be USB HOST CDC, but USB DEVICE CDC, correct?

Well, not necessarily. You can build a contraption with two CDC devices, cross-connected at the serial side, to connect to CDC hosts together. There are such "cables" around, enabling to connect two PCs, but the devices within require specific drivers (FT232 etc.). But if you want to solve your problem using a nonstandard-but-purchasible A-A cable, then yes, you need to do the host-to-device switch when you want to change role.

You won't be able to do both the MSC host and CDC device at the same time, of course, but you've probably considered this already.

> If yes, not being able to sense VBUS might be a problem? Should I power off my VBUS every time I switch from HOST to DEVICE ?

VBUS sensing is not a necessity in device. You just won't be able to distinguish between states when host suspends the bus and when the host is removed altogether, but that for the vast majority of practical purposes is not a problem (it would be a problem only if you'd need to distinguish, whether you would be able to wake up a suspended host, or wouldn't because it's not there, and e.g. present this information to the user).

You also don't need OTG as such, as - after having solved the issue of switching between device and host through some different mechanism - the remaining features falling under OTG are secondary such as as methods distinghishing which party is the power source.

There is also a question you did not ask but maybe you want to know: whether all this or most of it can be clicked in CubeMX. I don't know, I don't use Cube nor CubeMX.

JW

thank you very much for the exhaustive answer.

Just a little thing left: when in device mode i must not provide VBUS to the connector, is it?

Normally device does not provide VBUS.

In true OTG, the two parties may negotiate who will be the power source, but that's probably not your case.

JW