AnsweredAssumed Answered

stm mass storage usb does not recognize.

Question asked by Study Yahoo on Nov 25, 2017

Hi mass storage is being implemented.

Nucleo-F207G is being tested.

en.stm32cubef2 \ STM32Cube_FW_F2_V1.7.0 \ Projects \ STM32F207ZG-Nucleo \ Applications \ FatFs \ FatFs_USBDisk
The sample is usb-detectable without any problem, and the txt file can be written well.

If you design code with cube as below, you can not detect usb.

 

 

 

 

 

If you create a project with cube, you have to change heap / stack size.

 

Appli_State value should be recognized as 1, even if you connect usb stick, it is still 0;

 

I need to solve the problem, but I do not have enough time.

Below is main.c / usb_host.c source.

Have a great weekend!

 

 

main.c 
---------------
void FileReadWrite(void)
{
  FRESULT res;                                          
  uint32_t byteswritten;                     
  uint8_t wtext[] = "This is STM32 working with FatFs";                                    
  //printf("in MSC_Application ...usbh path %s \r\n",USBH_Path);
  if(f_mount(&USBDISKFatFs, (TCHAR const*)USBHPath, 0) != FR_OK) 
  {
//printf("f_mount fail ...\r\n"); Error_Handler();
}/* FatFs Initialization Error */
  
else
  //printf("mount ok...\r\n");
   if(f_open(&MyFile, "STM32.TXT", FA_CREATE_ALWAYS | FA_WRITE) != FR_OK)
{
  //printf("f_open  fail \r\n");Error_Handler(); 
    }
    else
{
   //printf("f_write ...\r\n");
   res = f_write(&MyFile, wtext, sizeof(wtext), (void *)&byteswritten); 
   if((byteswritten == 0) || (res != FR_OK)) 
 
 Error_Handler(); 
 
   else 
{
f_close(&MyFile);  
      printf("success....\r\n");
}
}
}
}
while (1)
  {
  /* USER CODE END WHILE */
    MX_USB_HOST_Process();
  /* USER CODE BEGIN 3 */     if(Appli_state==APPLICATION_START)
     {
       FileReadWrite();
       Appli_state = APPLICATION_IDLE;
       }
       else if(Appli_state==APPLICATION_IDLE)
       {
     }
  }
usb_host.c 
----------------
void MX_USB_HOST_Init(void)
{
  USBH_Init(&hUsbHostFS, USBH_UserProcess, HOST_FS);
  USBH_RegisterClass(&hUsbHostFS, USBH_MSC_CLASS);
  USBH_Start(&hUsbHostFS);
}
static void USBH_UserProcess  (USBH_HandleTypeDef *phost, uint8_t id)
{
  switch(id)
  {
  case HOST_USER_SELECT_CONFIGURATION:
  break;
   
  case HOST_USER_DISCONNECTION:
  Appli_state = APPLICATION_IDLE;
  f_mount(NULL, (TCHAR const*)"", 0);  
  break;
   
  case HOST_USER_CLASS_ACTIVE:
  Appli_state = APPLICATION_START;
  break;
  case HOST_USER_CONNECTION:
  break;
  default:
  break;
  }
  /* USER CODE END 2 */
}

Outcomes