cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F2xx HAL USB HOST

max239955_st
Associate
Posted on August 14, 2016 at 02:53

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 ------------------------------------------------------------------*/

&sharpinclude ''stm32f2xx_hal.h''

&sharpinclude ''fatfs.h''

&sharpinclude ''rtc.h''

&sharpinclude ''tim.h''

&sharpinclude ''usart.h''

&sharpinclude ''usb_host.h''

&sharpinclude ''gpio.h''

&sharpinclude ''ff_gen_drv.h''

&sharpinclude ''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.

#stm32cubemx #stm32f2 #usb #host
3 REPLIES 3
Walid FTITI_O
Senior II
Posted on August 15, 2016 at 16:08

Hi forestan.massimo,

Try to do like the following implementation example:

''

char SDPath[4];

f_mount(&SDFatFs, (TCHAR const*)SDPath, 0)

''

I recommend that you take a look to the ''FatFs_uSD'' example in STM32CubeF2 package at this path: STM32Cube_FW_F2_V1.3.0\Projects\STM322xG_EVAL\Applications\FatFs\FatFs_uSD

-Hannibal-

Posted on January 09, 2017 at 16:42

I have the same problem. I try using ]

f_mount(&SDFatFs, (TCHAR const*)SDPath, 0)

but it's not work

iw2lsi
Associate III

Same problem here using STM32F746-Disco

Giampaolo