AnsweredAssumed Answered

STM32F4 FatFs f_open return FR_DISK_ERR

Question asked by dang_hong.quan on Jun 2, 2015

 I'm using the FatFs library ver R0.10 to access the SD card. Here is my code:

SystemInit();
 USART_Configuration();
 NVIC_Configuration();
 
 /*-------------------------- SD Init ----------------------------- */
   Status=disk_initialize(0);
   printf("    \r\n\r\n01. ----- SD_Init Status:%d\r\n",Status);
 
   if (Status == SD_OK)
   {                                                                                                                                                                              
     printf("          Initialize SD card successfully!\r\n\r\n");
     /*----------------- Read CSD/CID MSD registers ------------------*/
     Status = SD_GetCardInfo(&SDCardInfo);
     printf("02. ----- SD_GetCardInfo Status:%d\r\n",Status);
   }
 
   if (Status == SD_OK)
   {
     printf("          Get SD card infomation successfully!\r\n          Block size:%x, Card type:%x\r\n\r\n",SDCardInfo.CardBlockSize,SDCardInfo.CardType);
     /*----------------- Select Card --------------------------------*/
     Status = SD_SelectDeselect((u32) (SDCardInfo.RCA << 16));
     printf("03. ----- SD_SelectDeselect Status:%d\r\n",Status);
   }
 
   if (Status == SD_OK)
   {
     printf("          Select SD card successfully!\r\n\r\n");
     Status = SD_EnableWideBusOperation(SDIO_BusWide_4b);
     printf("04. ----- SD_EnableWideBusOperation Status:%d\r\n",Status);
   }
 
   /*------------------- Block Erase -------------------------------*/
   if (Status == SD_OK)
   {
     printf("          Enable wide bus operation successfully!\r\n\r\n");
     /* Erase NumberOfBlocks Blocks of WRITE_BL_LEN(512 Bytes) */
     Status = SD_Erase(Operate_Block*BlockSize, (Operate_Block+1)*BlockSize);
     printf("05. ----- SD_Erase Status:%d\r\n",Status);
   }
 
   /* Set Device Transfer Mode to DMA */
   if (Status == SD_OK)
   {
     printf("          Erase block %d successfully!\r\n          All the data is 0x00\r\n\r\n",Operate_Block);
     Status = SD_SetDeviceMode(SD_POLLING_MODE);
     printf("06. ----- SD_SetDeviceMode Status:%d\r\n",Status);
   }
 
   res = f_mount(0,&fs);
 
   res = f_open(&fsrc,"0:/bigdata.txt", FA_CREATE_ALWAYS | FA_WRITE );

f_mount() return FR_OK but f_open() return FR_DISK_ERR. I try to debug f_open() and it call:check_fs(fs, bsect) return 3 -> /* An error occured in the disk I/O layer */How could I solve this problem? 

Outcomes