cancel
Showing results for 
Search instead for 
Did you mean: 

FR_DISK_ERR when reach f_open on STM32F4Discovery USB MSC + FATFS

ade
Associate II
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
3 REPLIES 3
Posted on September 03, 2016 at 15:33

You'd need to review how the DISKIO layer within FatFs is interfacing with the USB MSC, and understand why the USB side isn't working or passing back errors.

Try some different USB sticks, the low cost ones might have timing issues.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ade
Associate II
Posted on September 04, 2016 at 03:45

I already tried my USB with the repository example and it works well, i already modify the repository example and it works great with my USB. The problem was if i want to add an additional repository, i found some difficulties to add peripheral because my IAR always return Error[Li005] if i build my project. So, I want to build fresh project using Cube.

Any idea ?

Walid FTITI_O
Senior II
Posted on September 08, 2016 at 13:56

Hi Tama.bounta,

Try to do like the following implimentation example

char SDPath[4];
f_mount(&SDFatFs, (TCHAR const*)SDPath, 0)

I recommend that you take a look to the ''FatFs_uSD'' example in

http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32cube-embedded-software/stm32cubef7.html

package at this path: STM32Cube_FW_F7_V1.4.0\Projects\STM32F769I_EVAL\Applications\FatFs\FatFs_uSD

-Hannibal-