Trouble with SDCARD - SDMMC_FLAG_RXOVERR
I'm attempting to connect an adafruit SD card reader via SDIO to a Nucleo L476RG.
I'm reading through the source code to do a test of the basic read/write functions.
Initialization and getting card info is successful.
if (HAL_SD_Init(&hsd1)!=HAL_OK){
serprintf("Could not initialize SD card.");
}
if(HAL_SD_GetCardInfo(&hsd1, &SDCardInfo1) != HAL_OK)
{
serprintf("Cardinfo no good.");
Error_Handler();
}
sd_res = HAL_SD_ReadBlocks(&hsd1, Buffer_Block_Rx, WR_ADDR, NUM_BLOCKS, 0xffff);However, the last call to read blocks fails with SDMMC_FLAG_RXOVERR.
I traced the program through several times and I cannot find the breaking point.
But here's what I have discovered.
HAL_SD_ReadBlocks() calls SDMMC_CmdReadMultiBlock()
SDMMC_CmdReadMultiBlock() calls SDMMC_SendCommand()
Inside SDMMC_SendCommand() something causes the overrun.
But the function is fairly simple:
HAL_StatusTypeDef SDMMC_SendCommand(SDMMC_TypeDef *SDMMCx, SDMMC_CmdInitTypeDef *Command)
{
uint32_t tmpreg = 0;
/* Check the parameters */
assert_param(IS_SDMMC_CMD_INDEX(Command->CmdIndex));
assert_param(IS_SDMMC_RESPONSE(Command->Response));
assert_param(IS_SDMMC_WAIT(Command->WaitForInterrupt));
assert_param(IS_SDMMC_CPSM(Command->CPSM));
/* Set the SDMMC Argument value */
SDMMCx->ARG = Command->Argument;
/* Set SDMMC command parameters */
tmpreg |= (uint32_t)(Command->CmdIndex |\
Command->Response |\
Command->WaitForInterrupt |\
Command->CPSM);
/* Write to SDMMC CMD register */
MODIFY_REG(SDMMCx->CMD, CMD_CLEAR_MASK, tmpreg);
return HAL_OK;
}Everything is an assignment.
MODIFY_REG is a macro:
#define MODIFY_REG(REG, CLEARMASK, SETMASK) WRITE_REG((REG), (((READ_REG(REG)) & (~(CLEARMASK))) | (SETMASK)))and WRITE_REG is also macro:
#define MODIFY_REG(REG, CLEARMASK, SETMASK) WRITE_REG((REG), (((READ_REG(REG)) & (~(CLEARMASK))) | (SETMASK)))I'm not sure what else to check. Appreciate any help.
