SD_Read bug?
Good day everyone,
I'm not sure if this is a bug or I'm looking at this incorrectly, but It seems to be a bug.
While calling the f_mount function there is a point where SD_read is called.
DRESULT SD_read(BYTE lun, BYTE *buff, DWORD sector, UINT count)
{ DRESULT res = RES_ERROR; ReadStatus = 0; uint32_t timeout; if (ENABLE_SD_DMA_CACHE_MAINTENANCE == 1) uint32_t alignedAddr; endifif(BSP_SD_ReadBlocks_DMA((uint32_t*)buff,
(uint32_t) (sector), count) == MSD_OK) { /* Wait that the reading process is completed or a timeout occurs */ timeout = HAL_GetTick(); while((ReadStatus == 0) && ((HAL_GetTick() - timeout) < SD_TIMEOUT)) { } /* incase of a timeout return error */ if (ReadStatus == 0) { res = RES_ERROR; } else { ReadStatus = 0; timeout = HAL_GetTick();while((HAL_GetTick() - timeout) < SD_TIMEOUT)
{ if (BSP_SD_GetCardState() == SD_TRANSFER_OK) { res = RES_OK; if (ENABLE_SD_DMA_CACHE_MAINTENANCE == 1) /* the SCB_InvalidateDCache_by_Addr() requires a 32-Bit aligned address, adjust the address and the D-Cache size to invalidate accordingly. */ alignedAddr = (uint32_t)buff & ~3; SCB_InvalidateDCache_by_Addr((uint32_t*)alignedAddr, count*BLOCKSIZE + ((uint32_t)buff - alignedAddr)); endif break; } } } }return res;
}After this call my code enters
f(BSP_SD_ReadBlocks_DMA((uint32_t*)buff,(uint32_t) (sector),count) == MSD_OK)
and passes it successfully, after which it gets stuck in the while loop.
while((ReadStatus == 0) && ((HAL_GetTick() - timeout) < SD_TIMEOUT))
{ }After this the problem occurs and that is:
if (ReadStatus == 0)
{ res = RES_ERROR; }the function always gets stuck here no matter what. So i went and looked at all the calls for ReadStatus in my project and this popped up:
From here it seems there's one callback that will ensure the SD_Read passes and thats BSP_SD_ReadCpltCallback. Although this is never called anywhere in the project and therefore SD_Read always fails. Therefore it always remain 0 and the LL read function fails. This is cube generated.
Is this a mistake from my side or CubeMX??
I'm using the latest cube(V 4.0 and the latest Hal(1.8.0) for the stm32F7
f_mount-sdcard sdcard cubemx-project stm32f7-hal stm32f7