cancel
Showing results for 
Search instead for 
Did you mean: 

USB Host "ALL Classes"

SDall.11
Associate III

Hello everyone, I'm a bit confused about using USB.
I need to use the USB port both to create a CDC connection with a PC and to read/write data from USB flash drives.
Initially, I wanted to create a project that could handle both HOST and DEVICE modes, but I see that I would have to generate two separate projects and then manually copy some libraries.
I also tried the USB Dual Role configuration, but I don't understand its purpose as it doesn't generate anything related to USB.
Then, I saw that I can create a configuration like USB HOST  with mode HOST SUPPORTING ALL CLASSES so I’m asking if with this mode I can do both things, and if you could point me to any examples of how to do this.

I thank you in advance.

1 ACCEPTED SOLUTION

Accepted Solutions

Solved!!!
The problem was the DEVICE deinitialization.
Without this, all works fine.

Thanks.

View solution in original post

4 REPLIES 4
FBL
ST Employee

Hi @SDall.11 

 

First, you need to make sure that your hardware support USB OTG which includes ID pin and switch between host and device role. Which STM32 product are you using?

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hi FBL, I use STM32F412VET6

 

Hello everyone,
I finally created one project exclusively for DEVICE and one exclusively for HOST, then merged them together.
I've made some progress since I'm able to switch from HOST mode to DEVICE mode, but I can't go the other way because when I try, I end up in the Error_Handler.
The software starts in HOST mode, and I've done some tests that show I can write to a USB flash drive.
When I switch to DEVICE mode, everything works fine, and I can connect to the PC via VCP.
The problem arises when I switch back to HOST mode, resulting in the aforementioned error.
Here's the function I call to switch from HOST to DEVICE:
 
if (Appli_state != APPLICATION_DISCONNECT && Appli_state != APPLICATION_IDLE)
{
USBH_LL_Disconnect(&hUsbHostFS);
USBH_Stop(&hUsbHostFS);
}
 
if (hUsbHostFS.pActiveClass != NULL)
{
hUsbHostFS.pActiveClass->DeInit(&hUsbHostFS);
}
 
USBH_LL_DriverVBUS(&hUsbHostFS, FALSE);
MX_USB_DEVICE_Init();
 
 
and here's the function I call for the reverse transition:
 
USBD_Stop(&hUsbDeviceFS);
USBD_DeInit(&hUsbDeviceFS);
MX_USB_HOST_Init();
MX_FATFS_Init();
 
I can't seem to figure out where the issue might be.
Any suggestions?
Thanks.

Solved!!!
The problem was the DEVICE deinitialization.
Without this, all works fine.

Thanks.