Description
When SD init would call HAL_SD_GetCardStatus , you could see the sd_status only 16 lens.
HAL_StatusTypeDef HAL_SD_GetCardStatus(SD_HandleTypeDef *hsd, HAL_SD_CardStatusTypeDef *pStatus)
{
uint32_t sd_status[16];
uint32_t errorstate;
HAL_StatusTypeDef status = HAL_OK;
errorstate = SD_SendSDStatus(hsd, sd_status);
if (errorstate != HAL_SD_ERROR_NONE)
In SD_SendSDStatus, when noraml read status only use 8 of 16.
static uint32_t SD_SendSDStatus(SD_HandleTypeDef *hsd, uint32_t *pSDstatus)
{
SDMMC_DataInitTypeDef config;
uint32_t errorstate;
uint32_t tickstart = HAL_GetTick();
uint32_t count;
uint32_t *pData = pSDstatus;
.....
/* Get status data */
while (!__HAL_SD_GET_FLAG(hsd, SDMMC_FLAG_RXOVERR | SDMMC_FLAG_DCRCFAIL | SDMMC_FLAG_DTIMEOUT | SDMMC_FLAG_DATAEND))
{
if (__HAL_SD_GET_FLAG(hsd, SDMMC_FLAG_RXFIFOHF))
{
for (count = 0U; count < 8U; count++)
{
*pData = SDMMC_ReadFIFO(hsd->Instance);
pData++;
}
}
if ((HAL_GetTick() - tickstart) >= SDMMC_USERTIMEOUT)
{
return HAL_SD_ERROR_TIMEOUT;
}
}
But it may read more than the left 8 of 16,and i read the H7 reference datasheet , there is no more thing about DPSMACT, why read more FIFO DATA at the end of SD_SendSDStatus?
while ((__HAL_SD_GET_FLAG(hsd, SDMMC_FLAG_DPSMACT)))
{
*pData = SDMMC_ReadFIFO(hsd->Instance);
pData++;
if ((HAL_GetTick() - tickstart) >= SDMMC_USERTIMEOUT)
{
return HAL_SD_ERROR_TIMEOUT;
}
}
/* Clear all the static status flags*/
__HAL_SD_CLEAR_FLAG(hsd, SDMMC_STATIC_DATA_FLAGS);
return HAL_SD_ERROR_NONE;
}
May modify to check left count more safe
count = 0;
while ((__HAL_SD_GET_FLAG(hsd, SDMMC_FLAG_DPSMACT)))
{
if(count >= 7)
{
throw some error;
}
*pData = SDMMC_ReadFIFO(hsd->Instance);
pData++;
count++;
if ((HAL_GetTick() - tickstart) >= SDMMC_USERTIMEOUT)
{
return HAL_SD_ERROR_TIMEOUT;
}
}
/* Clear all the static status flags*/
__HAL_SD_CLEAR_FLAG(hsd, SDMMC_STATIC_DATA_FLAGS);
return HAL_SD_ERROR_NONE;
}
I also check the code about F7, it use RXDAVL, it's not same mean of DPSMACT
while ((__HAL_SD_GET_FLAG(hsd, SDMMC_FLAG_RXDAVL)))
{
*pData = SDMMC_ReadFIFO(hsd->Instance);
pData++;
if((HAL_GetTick() - tickstart) >= SDMMC_SWDATATIMEOUT)
{
return HAL_SD_ERROR_TIMEOUT;
}
}
F7 code also has the problem.
In Fact we met a fault situation that our SD_CK not stable, which may cause DPSMACT set to 1, then when we reinit sd driver, it read the empyt FIFO(no reference says you cant read the empty FIFO ), then go to BusFault, so i check the code, found the problem. Maybe we could check more status avoid the fault? Could you give some advice about it ?
Metadata
Metadata
Assignees
Labels
Type
Projects
Status