2019-08-27 11:40 PM
Hello, I wonder if in the HAL function below, should line 24 be clearing TIMEOUT flag instead of the end command flag?
(If so, I'll change it... if not, hopefully I'll learn something, why would you clear the timeout there?)
Edit: actually shouldnt it also clear the CRC fail flag, if it gets that? It doesn't seem to.
/**
* @brief Checks for error conditions for R7 response.
* @param hsd: SD handle
* @retval SD Card error state
*/
static uint32_t SDMMC_GetCmdResp7(SDMMC_TypeDef *SDMMCx)
{
/* 8 is the number of required instructions cycles for the below loop statement.
The SDMMC_CMDTIMEOUT is expressed in ms */
register uint32_t count = SDMMC_CMDTIMEOUT * (SystemCoreClock / 8 /1000);
do
{
if (count-- == 0)
{
return SDMMC_ERROR_TIMEOUT;
}
}while(!__SDMMC_GET_FLAG(SDMMCx, SDMMC_FLAG_CCRCFAIL | SDMMC_FLAG_CMDREND | SDMMC_FLAG_CTIMEOUT));
if(__SDMMC_GET_FLAG(SDMMCx, SDMMC_FLAG_CTIMEOUT))
{
/* Card is SD V2.0 compliant */
__SDMMC_CLEAR_FLAG(SDMMCx, SDMMC_FLAG_CMDREND); // SHOULD THIS BE SDMMC_FLAG_CTIMEOUT??
return SDMMC_ERROR_CMD_RSP_TIMEOUT;
}
if(__SDMMC_GET_FLAG(SDMMCx, SDMMC_FLAG_CMDREND))
{
/* Card is SD V2.0 compliant */
__SDMMC_CLEAR_FLAG(SDMMCx, SDMMC_FLAG_CMDREND);
}
return SDMMC_ERROR_NONE;
}