2016-10-20 09:05 AM
Hi.
I'm using the STM32F769I-DISCO board. I'm trying to manage the SD card in FAT FS. I've merged a new project created in CubeMX and the 'FatFs_uSD' example from STM32F769I_EVAL example. In Cube I've changed: - MiddleWares -> FATFS -> SD Card - Peripherals -> SDMMC2 -> Mode -> SD 4 bits Wide bus In the main.c I've added:/* USER CODE BEGIN PV */
/* Private variables ---------------------------------------------------------*/
extern char SD_Path[4];
/* USER CODE END PV */
(...)
/* USER CODE BEGIN 2 */
FRESULT res; /* FatFs function common result code */
uint32_t byteswritten, bytesread; /* File write/read counts */
uint8_t wtext[] = ''This is STM32 working with FatFs''; /* File write buffer */
uint8_t rtext[100]; /* File read buffer */
FATFS SDFatFs; /* File system object for SD disk logical drive */
FIL MyFile; /* File object */
/*##-1- Link the SD disk I/O driver ########################################*/
res = 0; // FATFS_LinkDriver(&SD_Driver, SD_Path); // It's done in FS init
if (res == 0) {
/*##-2- Register the file system object to the FatFs module ##############*/
res = f_mount(&SDFatFs, (TCHAR const*) SD_Path, 0);
if (res != FR_OK) {
/* FatFs Initialization Error */
//BSP_LED_On(LED_RED);
Error_Handler();
} else {
/*##-3- Create a FAT file system (format) on the logical drive #########*/
res = f_mkfs((TCHAR const*) SD_Path, 0, 0);
if (res != FR_OK) {
//BSP_LED_On(LED_RED);
Error_Handler();
} else {
/*##-4- Create and Open a new text file object with write access #####*/
res = f_open(&MyFile, ''STMTXT'', FA_CREATE_ALWAYS | FA_WRITE);
if (res != FR_OK) {
/* 'STMTXT' file Open for write Error */
//BSP_LED_On(LED_RED);
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)) {
/* 'STMTXT' file Write or EOF Error */
//BSP_LED_On(LED_RED);
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, ''STMTXT'', FA_READ) != FR_OK) {
/* 'STMTXT' file Open for read Error */
//BSP_LED_On(LED_RED);
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)) /* EOF or Error */
{
/* 'STMTXT' file Read or EOF Error */
//BSP_LED_On(LED_RED);
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 */
//BSP_LED_On(LED_RED);
Error_Handler();
} else {
/* Success of the demo: no error occurrence */
//BSP_LED_On(LED_GREEN);
}
}
}
}
}
}
}
}
/*##-11- Unlink the SD disk I/O driver ####################################*/
FATFS_UnLinkDriver(SD_Path);
/* USER CODE END 2 */
But the HAL_SD_ReadBlocks returns SD_RX_OVERRUN. I allways run in debug.
Where's the problem?
Thanks.
#fatfs #sd #stm32f769i-disco
2016-10-20 10:54 AM
The pasted code is completely irrelevant in the failure being described, you will want to look into the SDIO layer, how the pins, card, irq, dma, etc are getting initialized, and how the transfer is initiated and handled.
2016-10-21 12:25 AM
Hi clive1.
I attach all the project. The initialization code is the code generated by STM32CubeMx. I've selected the STM32F769I-DISCO board and just changed the options I've posted. (The STM32CubeMx project file is also included). Thanks. ________________ Attachments : USBD_FAT_over_SD.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I10K&d=%2Fa%2F0X0000000bgs%2FWrwvUthbndjQRrChSVdBfQuj7mImSCkS9U9dm06VxhI&asPdf=false2017-12-05 09:27 AM
Hi,
I'm stragleing with the same board and fatfs with SD sample.
Did you make it work?
Thanks