AnsweredAssumed Answered

FR_DISK_ERR when reach f_open on STM32F4Discovery USB MSC + FATFS

Question asked by tama.bunta on Sep 3, 2016
Latest reply on Sep 8, 2016 by FTITI.Walid
I have a trouble when I reach the f_open command, it always return FR_DISK_ERR.

Here is my code which generated fromSTM32CubeMX :
01.#include "stm32f4xx_hal.h"
02.#include "fatfs.h"
03.#include "usb_host.h"
04. 
05./* USER CODE BEGIN Includes */
06.#include "stdio.h"
07./* USER CODE END Includes */
08. 
09./* Private variables ---------------------------------------------------------*/
10. 
11./* USER CODE BEGIN PV */
12./* Private variables ---------------------------------------------------------*/
13.FATFS fs;
14.FIL MyFile;
15.FRESULT fres;
16. 
17.extern ApplicationTypeDef Appli_state;
18. 
19.char path[100];
20./* USER CODE END PV */
21. 
22./* Private function prototypes -----------------------------------------------*/
23.void SystemClock_Config(void);
24.void Error_Handler(void);
25.static void MX_GPIO_Init(void);
26.void MX_USB_HOST_Process(void);
27. 
28./* USER CODE BEGIN PFP */
29./* Private function prototypes -----------------------------------------------*/
30. 
31./* USER CODE END PFP */
32. 
33./* USER CODE BEGIN 0 */
34. 
35./* USER CODE END 0 */
36. 
37.int main(void)
38.{
39. 
40.  /* USER CODE BEGIN 1 */
41. 
42.  /* USER CODE END 1 */
43. 
44.  /* MCU Configuration----------------------------------------------------------*/
45. 
46.  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
47.  HAL_Init();
48. 
49.  /* Configure the system clock */
50.  SystemClock_Config();
51. 
52.  /* Initialize all configured peripherals */
53.  MX_GPIO_Init();
54.  MX_FATFS_Init();
55.  MX_USB_HOST_Init();
56. 
57.  /* USER CODE BEGIN 2 */
58.  MX_USB_HOST_Process();
59.  if(retUSBH != 0){
60.    Error_Handler();
61.  }
62.  if(fres = f_mount(&fs, (TCHAR const*) USBH_Path, 0) != FR_OK)
63.  {
64.    Error_Handler();
65.  }
66.  if(f_open(&MyFile, "STM32.TXT", FA_CREATE_ALWAYS | FA_WRITE) != FR_OK)
67.  {
68.    Error_Handler();
69.  }
70.  /* USER CODE END 2 */
71. 
72.  /* Infinite loop */
73.  /* USER CODE BEGIN WHILE */
74.  while (1)
75.  {
76.  /* USER CODE END WHILE */
77.    MX_USB_HOST_Process();
78. 
79.  /* USER CODE BEGIN 3 */
80.     
81.  }
82.  /* USER CODE END 3 */
83. 
84.}

It always get stuck at f_open, so it looping in Error_Handler(). Can someone help me ?

Thank you very much

Outcomes