AnsweredAssumed Answered

SD_RX_OVERRUN on HAL_SD_ReadBlocks

Question asked by Masriera.Jordi on Oct 20, 2016
Latest reply on Dec 5, 2017 by EGol
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, "STM32.TXT", FA_CREATE_ALWAYS | FA_WRITE);
            if (res != FR_OK) {
                /* 'STM32.TXT' 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)) {
                    /* 'STM32.TXT' 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, "STM32.TXT", FA_READ) != FR_OK) {
                        /* 'STM32.TXT' 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 */
                        {
                            /* 'STM32.TXT' 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.

Outcomes