AnsweredAssumed Answered

STM32 USB OTG MSC

Question asked by cattin.bernard on Apr 19, 2016
Latest reply on Jul 29, 2016 by Clive One
Hi,

I'm using an STm32F107 and I trie to configure the USB interface as host to access to an key.

This is the initialization code :
MX_USB_HOST_Init();
MX_FATFS_Init();

with :
void MX_USB_HOST_Init(void)
{
  /* Init Host Library,Add Supported Class and Start the library*/
  USBH_Init(&hUsbHostFS, USBH_UserProcess, HOST_FS);
 
  USBH_RegisterClass(&hUsbHostFS, USBH_MSC_CLASS);
 
  USBH_Start(&hUsbHostFS);
}
and :

void MX_FATFS_Init(void)
{
  /*## FatFS: Link the USBH driver ###########################*/
  retUSBH = FATFS_LinkDriver(&USBH_Driver, USBH_Path);
 
  /* USER CODE BEGIN Init */
  /* additional user code for init */
  if (retUSBH == 0)
  {
      HAL_GPIO_WritePin(GPIOD, LED1_Pin, GPIO_PIN_SET);//Succes
  }
  else
  {
      HAL_GPIO_WritePin(GPIOD, LED3_Pin, GPIO_PIN_SET);//Error
  }
  /* USER CODE END Init */
}

After execute, the led1 is on.

A try to access to 
/* Register the file system object to the FatFs module */
if (f_mount(&USBH_fatfs, "", 0) != FR_OK)
{
      /* ERROR : Cannot Initialize FatFs. */
      ...
}
This call to function "f_mount()" always returns FR_OK
but after :
while (1)
 {
 /* USER CODE END WHILE */
   MX_USB_HOST_Process();
 
 /* USER CODE BEGIN 3 */
 
   HAL_Delay(500);
 
   res = f_open(&MyFile, "0:USBHost.txt", FA_CREATE_ALWAYS | FA_WRITE);
   if (res != FR_OK)
   {
       // Error
       // ...
   }
       ...
}
Here, the function "f_open()" never returns FR_OK.

Is there someone who can give me some explanation of this behaviour ?
Thank you very much.
Bernard.



Outcomes