Question
stm32 fatfs sdio
Posted on August 18, 2016 at 15:44
Hi
I am trying to use fatfs with my 8gb microsd card on my own stm32f429 board. I use 1-bit sdio configuration and i use the cubemx fatfs example Project for eval board. if(FATFS_LinkDriver(&SD_Driver, SDPath) == 0) { /*♯♯-2- Register the file system object to the FatFs module ♯♯♯♯♯♯♯♯♯♯♯♯♯♯*/ if(f_mount(&SDFatFs, (TCHAR const*)SDPath, 0) != FR_OK) { /* FatFs Initialization Error */ //Error_Handler(); } else { if(f_mkfs((TCHAR const*)SDPath, 0, 0) != FR_OK) { /* FatFs Format Error */ //Error_Handler(); } else { /*♯♯-4- Create and Open a new text file object with write access ♯♯♯♯♯*/ if(f_open(&MyFile, ''STM32.TXT'', FA_CREATE_ALWAYS | FA_WRITE) != FR_OK) { /* 'STM32.TXT' file Open for write Error */ //Error_Handler(); } else { /*♯♯-5- Write data to the text file ♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯*/ res = f_write(&MyFile, wtext, sizeof(wtext), (void *)&byteswritten); if((byteswritten == 0) || (res != FR_OK)) { /* 'STM32.TXT' file Write or EOF Error */ //Error_Handler(); } else { /*♯♯-6- Close the open text file ♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯*/ f_close(&MyFile); /*♯♯-7- Open the text file object with read access ♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯*/ if(f_open(&MyFile, ''STM32.TXT'', FA_READ) != FR_OK) { /* 'STM32.TXT' file Open for read Error */ //Error_Handler(); } else { /*♯♯-8- Read data from the text file ♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯*/ res = f_read(&MyFile, rtext, sizeof(rtext), (UINT*)&bytesread); if((bytesread == 0) || (res != FR_OK)) { /* 'STM32.TXT' file Read or EOF Error */ //Error_Handler(); } else { /*♯♯-9- Close the open text file ♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯*/ f_close(&MyFile); /*♯♯-10- Compare read data with the expected data ♯♯♯♯♯♯♯♯♯♯♯♯*/ if((bytesread != byteswritten)) { /* Read data is different from the expected data */ //Error_Handler(); } else { /* Success of the demo: no error occurrence */ //BSP_LED_On(LED1); } } } } } } } } FATFS_UnLinkDriver(SDPath); When debugging, it returns from '' if(f_open(&MyFile, ''STM32.TXT'', FA_CREATE_ALWAYS | FA_WRITE) != FR_OK)'' to error handler, so it can not open the file. What may the problem be? Any advise... #no-hablo-hal