AnsweredAssumed Answered

STM32F2xx HAL USB HOST

Question asked by forestan.massimo on Aug 14, 2016
Latest reply on Jan 9, 2017 by ngo duong
Hi Everyone,
I'm trying to do a simple read or write into a usb pendrive (TOSHIBA 4Gb ) using a custom board with a STM32F207VGT6 mcu on it...
I developed the firmware with STMCubeMX, by using USB_OTG_FS as HOST_ONLY, with Mass Storage Host Class and FATFs...
Here's a part of the code that I used...


/* Includes ------------------------------------------------------------------*/
#include "stm32f2xx_hal.h"
#include "fatfs.h"
#include "rtc.h"
#include "tim.h"
#include "usart.h"
#include "usb_host.h"
#include "gpio.h"
#include "ff_gen_drv.h"
#include "usbh_diskio.h"


/* USER CODE BEGIN Includes */


/* USER CODE END Includes */


/* Private variables ---------------------------------------------------------*/


/* USER CODE BEGIN PV */
/* Private variables ---------------------------------------------------------*/


/* USER CODE END PV */


/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
void Error_Handler(void);
void MX_USB_HOST_Process(void);

/* USER CODE BEGIN PFP */
/* Private function prototypes -----------------------------------------------*/

/* USER CODE END PFP */

/* USER CODE BEGIN 0 */

/* USER CODE END 0 */
     FIL USB_Fil;
     FATFS USB_Fs;
     
     
int main(void)
{


  /* USER CODE BEGIN 1 */


  /* USER CODE END 1 */


  /* MCU Configuration----------------------------------------------------------*/


  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();


  /* Configure the system clock */
  SystemClock_Config();


  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_RTC_Init();
  MX_TIM4_Init();
  MX_USART2_UART_Init();
  MX_USART3_UART_Init();
  MX_FATFS_Init();
  MX_USB_HOST_Init();
     


     uint8_t usb_write =1;
     uint32_t wbytes; /* File write counts */
     uint8_t wtext[] = "text to write logical disk"; /* File write buffer */


  /* USER CODE BEGIN 2 */


  /* USER CODE END 2 */


  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
  // USER CODE END WHILE 
    MX_USB_HOST_Process();


          if((FATFS_LinkDriver(&USBH_Driver,USBH_Path))&&usb_write)
          {
               if(f_mount(&USB_Fs, USBH_Path,0) == FR_OK)
               {
                    if(f_open(&USB_Fil, "0:/STM32.txt", FA_CREATE_ALWAYS | FA_WRITE ) == FR_OK)
                    {
                         GPIOD->BSRR = GPIO_PIN_13;
                         usb_write=0;          //write once
                         if(f_write(&USB_Fil,wtext, sizeof(wtext), (void *)&wbytes) == FR_OK)
                         {
                              f_close(&USB_Fil);
                         }
                    }
               }
          }
          FATFS_UnLinkDriver(USBH_Path);
     }
     /* USER CODE END 3 */
}

Everytime the result of "f_open" funcion is FR_NOT_READY... Why? What I missed? I followed the "STM32Cube USB host library" but the result when i called "f_open" was the same...
Thanks to everyone who spend some time for my real big mistake.

Outcomes