Question
FR_DISK_ERR when reach f_open on STM32F4Discovery USB MSC + FATFS
Posted on September 03, 2016 at 12:26
I have a trouble when I reach the f_open command, it always return FR_DISK_ERR.
Here is my code which generated fromSTM32CubeMX :
#include ''stm32f4xx_hal.h''
#include ''fatfs.h''
#include ''usb_host.h''
/* USER CODE BEGIN Includes */
#include ''stdio.h''
/* USER CODE END Includes */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
/* Private variables ---------------------------------------------------------*/
FATFS fs;
FIL MyFile;
FRESULT fres;
extern ApplicationTypeDef Appli_state;
char path[100];
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
void Error_Handler(void);
static void MX_GPIO_Init(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 */
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_FATFS_Init();
MX_USB_HOST_Init();
/* USER CODE BEGIN 2 */
MX_USB_HOST_Process();
if(retUSBH != 0){
Error_Handler();
}
if(fres = f_mount(&fs, (TCHAR const*) USBH_Path, 0) != FR_OK)
{
Error_Handler();
}
if(f_open(&MyFile, ''STMTXT'', FA_CREATE_ALWAYS | FA_WRITE) != FR_OK)
{
Error_Handler();
}
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
MX_USB_HOST_Process();
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
It always get stuck at f_open, so it looping in Error_Handler(). Can someone help me ?
Thank you very much
#f_open