cancel
Showing results for 
Search instead for 
Did you mean: 

USB HOST MODE MSC

Priyank
Associate III

Hi, I am trying to make the MCU the host where a USB can be connected, and the MCU can read/write to the USB. I configured my IOC /CubeMX to use the USB with FATFS. The USB USE OS (RTOS) is automatically enabled.

However, the issue is that once the USB is plugged in, it reaches HOST_USER_CONNECTION then goes straight to HOST_USER_UNRECOVERED_ERROR and keeps looping on this. I've attached the file for file handling where my case statements are. I've tried configuring all the buffers from CubeMX whether it be USB data buffers, max size configuration, USBH process stack size, sector size, etc.  

 

I've also attached the callback I'm using to handle the USB.

 

3 REPLIES 3

Please see How to insert source code for how to post source code - not as a screenshot.

 


@Priyank wrote:

goes straight to HOST_USER_UNRECOVERED_ERROR .


What error is it ?

Priyank
Associate III

Hi, I apologize for the incorrect method previously, I've added the code from the screenshot here according to guidelines. I'm not sure what the error is, but it comes from this list I've attached below in usbh_core.h. I've traced the error back to the original function call and its the USB just instantly erroring out after connection. I have a feeling it is something from the CubeMX configurations or clock speed, however I've tried editing it all, can't trace the issue back.

 

#define HOST_USER_SELECT_CONFIGURATION          0x01U
#define HOST_USER_CLASS_ACTIVE                  0x02U
#define HOST_USER_CLASS_SELECTED                0x03U
#define HOST_USER_CONNECTION                    0x04U
#define HOST_USER_DISCONNECTION                 0x05U
#define HOST_USER_UNRECOVERED_ERROR             0x06U
static void USBH_UserProcess  (USBH_HandleTypeDef *phost, uint8_t id)
{
  /* USER CODE BEGIN CALL_BACK_1 */
  switch(id)
  {
  case HOST_USER_SELECT_CONFIGURATION:
  break;

  case HOST_USER_DISCONNECTION:
  Appli_state = APPLICATION_DISCONNECT;
  Unmount_USB();
  break;

  case HOST_USER_CLASS_ACTIVE:
  Appli_state = APPLICATION_READY;

  Mount_USB();

  Check_USB_Details();   // check space details

  Scan_USB("/");   // scan for files and directories

  Create_Dir("/folder");
  Create_File("/folder/file.txt");
  Write_File("/folder/file.txt", "test data\n");

  break;

  case HOST_USER_CONNECTION:
  Appli_state = APPLICATION_START;
  break;

  default:
  break;
  }
  /* USER CODE END CALL_BACK_1 */
}

 

 

FBL
ST Employee

Hi @Priyank 

You need to diagnose further your issue! At this level your implementation is not clear!

I guess this lab STM32 USB training - 11.2 USB MSC host labs would be helpful.

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.