Vitaliy Chernobay

SS Card read in FATFS bug (stm32f7xx_hal_sd.c)

Discussion created by Vitaliy Chernobay on Sep 27, 2017
Latest reply on Sep 27, 2017 by Clive One

I made project for STM32F746 (LTDC, FMC, SDMMC, FATFS, STemWin + FreeRTOS)

I have problem with reading image file (bmp format) from SD card.

My code

 

int APP_GetData(void * p, const U8 **ppData, unsigned NumBytesReq, U32 Off){
//You must create an pointer on structure
FIL *phFile;
//and then initialize the pointer value is passed to the function APP_GetData
phFile=(FIL*) p;
//And then use this pointer to your function
f_lseek(phFile,Off);
fresult=f_read(phFile,_acBuffer,NumBytesReq,(void*)&bytesread);
*ppData = _acBuffer;
return bytesread;
}

 

void picture_test(void){
for(image_number = 1; image_number <= 38;image_number++){
sprintf(st_2,"image%03d",image_number);
sprintf(file_name, "%s%s",st_2,st_3 );
fresult=f_open(&MyFile,file_name, FA_READ);
GUI_MULTIBUF_BeginEx(0);
GUI_BMP_DrawEx(APP_GetData, &MyFile,0,0); // Draw image
GUI_MULTIBUF_EndEx(0);
f_close(&MyFile);
HAL_Delay(1000);
}
}

 

Code is displays several pictures and stops (HardFault)

Problem solved with correct file stm32f7xx_hal_sd.c

 

from line 637

 

/* Empty FIFO if there is still any data */
while ((__HAL_SD_GET_FLAG(hsd, SDMMC_FLAG_RXDAVL)))
{
*tempbuff = SDMMC_ReadFIFO(hsd->Instance);
// tempbuff++;      >>>>>>>>> //  tempbuff++;       !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!          

if((Timeout == 0U)||((HAL_GetTick()-tickstart) >= Timeout))
{
/* Clear all the static flags */
__HAL_SD_CLEAR_FLAG(hsd, SDMMC_STATIC_FLAGS);
hsd->ErrorCode |= HAL_SD_ERROR_TIMEOUT;
hsd->State= HAL_SD_STATE_READY;
return HAL_ERROR;
}
}

 

When I comment line 

tempbuff++

I have reading from SD card without HardFault.

 

Outcomes