|
|
@@ -892,7 +892,7 @@ HAL_SD_ErrorTypedef HAL_SD_ReadBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pRead
|
|
|
SDIO_IT_STBITERR));
|
|
|
|
|
|
/* Enable SDIO DMA transfer */
|
|
|
- __HAL_SD_SDIO_DMA_ENABLE();
|
|
|
+ // MM disabled, as this fails on fast cards. __HAL_SD_SDIO_DMA_ENABLE();
|
|
|
|
|
|
/* Configure DMA user callbacks */
|
|
|
hsd->hdmarx->XferCpltCallback = SD_DMA_RxCplt;
|
|
|
@@ -901,26 +901,29 @@ HAL_SD_ErrorTypedef HAL_SD_ReadBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pRead
|
|
|
/* Enable the DMA Stream */
|
|
|
HAL_DMA_Start_IT(hsd->hdmarx, (uint32_t)&hsd->Instance->FIFO, (uint32_t)pReadBuffer, (uint32_t)(BlockSize * NumberOfBlocks)/4);
|
|
|
|
|
|
+ sdio_cmdinitstructure.Response = SDIO_RESPONSE_SHORT;
|
|
|
+ sdio_cmdinitstructure.WaitForInterrupt = SDIO_WAIT_NO;
|
|
|
+ sdio_cmdinitstructure.CPSM = SDIO_CPSM_ENABLE;
|
|
|
+
|
|
|
if (hsd->CardType == HIGH_CAPACITY_SD_CARD)
|
|
|
{
|
|
|
BlockSize = 512;
|
|
|
ReadAddr /= 512;
|
|
|
- }
|
|
|
+ } else {
|
|
|
|
|
|
- /* Set Block Size for Card */
|
|
|
- sdio_cmdinitstructure.Argument = (uint32_t)BlockSize;
|
|
|
- sdio_cmdinitstructure.CmdIndex = SD_CMD_SET_BLOCKLEN;
|
|
|
- sdio_cmdinitstructure.Response = SDIO_RESPONSE_SHORT;
|
|
|
- sdio_cmdinitstructure.WaitForInterrupt = SDIO_WAIT_NO;
|
|
|
- sdio_cmdinitstructure.CPSM = SDIO_CPSM_ENABLE;
|
|
|
- SDIO_SendCommand(hsd->Instance, &sdio_cmdinitstructure);
|
|
|
+ /* Set Block Size for Card */
|
|
|
+ sdio_cmdinitstructure.Argument = (uint32_t)BlockSize;
|
|
|
+ sdio_cmdinitstructure.CmdIndex = SD_CMD_SET_BLOCKLEN;
|
|
|
+
|
|
|
+ SDIO_SendCommand(hsd->Instance, &sdio_cmdinitstructure);
|
|
|
|
|
|
- /* Check for error conditions */
|
|
|
- errorstate = SD_CmdResp1Error(hsd, SD_CMD_SET_BLOCKLEN);
|
|
|
+ /* Check for error conditions */
|
|
|
+ errorstate = SD_CmdResp1Error(hsd, SD_CMD_SET_BLOCKLEN);
|
|
|
|
|
|
- if (errorstate != SD_OK)
|
|
|
- {
|
|
|
- return errorstate;
|
|
|
+ if (errorstate != SD_OK)
|
|
|
+ {
|
|
|
+ return errorstate;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/* Configure the SD DPSM (Data Path State Machine) */
|
|
|
@@ -930,6 +933,11 @@ HAL_SD_ErrorTypedef HAL_SD_ReadBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pRead
|
|
|
sdio_datainitstructure.TransferDir = SDIO_TRANSFER_DIR_TO_SDIO;
|
|
|
sdio_datainitstructure.TransferMode = SDIO_TRANSFER_MODE_BLOCK;
|
|
|
sdio_datainitstructure.DPSM = SDIO_DPSM_ENABLE;
|
|
|
+
|
|
|
+ // We cannot enable DMA too early on UHS-I class 3 SD cards, or else the
|
|
|
+ // data is just discarded before the dpsm is started.
|
|
|
+ __HAL_SD_SDIO_DMA_ENABLE();
|
|
|
+
|
|
|
SDIO_DataConfig(hsd->Instance, &sdio_datainitstructure);
|
|
|
|
|
|
/* Check number of blocks command */
|
|
|
@@ -1016,28 +1024,30 @@ HAL_SD_ErrorTypedef HAL_SD_WriteBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pWri
|
|
|
HAL_DMA_Start_IT(hsd->hdmatx, (uint32_t)pWriteBuffer, (uint32_t)&hsd->Instance->FIFO, (uint32_t)(BlockSize * NumberOfBlocks)/4);
|
|
|
|
|
|
/* Enable SDIO DMA transfer */
|
|
|
- __HAL_SD_SDIO_DMA_ENABLE();
|
|
|
+ // MM disabled, as this fails on fast cards. __HAL_SD_SDIO_DMA_ENABLE();
|
|
|
+
|
|
|
+ sdio_cmdinitstructure.Response = SDIO_RESPONSE_SHORT;
|
|
|
+ sdio_cmdinitstructure.WaitForInterrupt = SDIO_WAIT_NO;
|
|
|
+ sdio_cmdinitstructure.CPSM = SDIO_CPSM_ENABLE;
|
|
|
|
|
|
if (hsd->CardType == HIGH_CAPACITY_SD_CARD)
|
|
|
{
|
|
|
BlockSize = 512;
|
|
|
WriteAddr /= 512;
|
|
|
- }
|
|
|
+ } else {
|
|
|
+ /* Set Block Size for Card */
|
|
|
+ sdio_cmdinitstructure.Argument = (uint32_t)BlockSize;
|
|
|
+ sdio_cmdinitstructure.CmdIndex = SD_CMD_SET_BLOCKLEN;
|
|
|
|
|
|
- /* Set Block Size for Card */
|
|
|
- sdio_cmdinitstructure.Argument = (uint32_t)BlockSize;
|
|
|
- sdio_cmdinitstructure.CmdIndex = SD_CMD_SET_BLOCKLEN;
|
|
|
- sdio_cmdinitstructure.Response = SDIO_RESPONSE_SHORT;
|
|
|
- sdio_cmdinitstructure.WaitForInterrupt = SDIO_WAIT_NO;
|
|
|
- sdio_cmdinitstructure.CPSM = SDIO_CPSM_ENABLE;
|
|
|
- SDIO_SendCommand(hsd->Instance, &sdio_cmdinitstructure);
|
|
|
+ SDIO_SendCommand(hsd->Instance, &sdio_cmdinitstructure);
|
|
|
|
|
|
- /* Check for error conditions */
|
|
|
- errorstate = SD_CmdResp1Error(hsd, SD_CMD_SET_BLOCKLEN);
|
|
|
+ /* Check for error conditions */
|
|
|
+ errorstate = SD_CmdResp1Error(hsd, SD_CMD_SET_BLOCKLEN);
|
|
|
|
|
|
- if (errorstate != SD_OK)
|
|
|
- {
|
|
|
- return errorstate;
|
|
|
+ if (errorstate != SD_OK)
|
|
|
+ {
|
|
|
+ return errorstate;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/* Check number of blocks command */
|
|
|
@@ -1049,7 +1059,6 @@ HAL_SD_ErrorTypedef HAL_SD_WriteBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pWri
|
|
|
else
|
|
|
{
|
|
|
/* MM: Prepare for write */
|
|
|
- /* Set Block Size for Card */
|
|
|
sdio_cmdinitstructure.Argument = (uint32_t)(hsd->RCA << 16);
|
|
|
sdio_cmdinitstructure.CmdIndex = SD_CMD_APP_CMD;
|
|
|
SDIO_SendCommand(hsd->Instance, &sdio_cmdinitstructure);
|
|
|
@@ -1072,10 +1081,11 @@ HAL_SD_ErrorTypedef HAL_SD_WriteBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pWri
|
|
|
/* Send CMD25 WRITE_MULT_BLOCK with argument data address */
|
|
|
sdio_cmdinitstructure.CmdIndex = SD_CMD_WRITE_MULT_BLOCK;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
sdio_cmdinitstructure.Argument = (uint32_t)WriteAddr;
|
|
|
SDIO_SendCommand(hsd->Instance, &sdio_cmdinitstructure);
|
|
|
|
|
|
+
|
|
|
/* Check for error conditions */
|
|
|
if(NumberOfBlocks > 1)
|
|
|
{
|
|
|
@@ -1098,6 +1108,11 @@ HAL_SD_ErrorTypedef HAL_SD_WriteBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pWri
|
|
|
sdio_datainitstructure.TransferDir = SDIO_TRANSFER_DIR_TO_CARD;
|
|
|
sdio_datainitstructure.TransferMode = SDIO_TRANSFER_MODE_BLOCK;
|
|
|
sdio_datainitstructure.DPSM = SDIO_DPSM_ENABLE;
|
|
|
+
|
|
|
+ // We cannot enable DMA too early on UHS-I class 3 SD cards, or else the
|
|
|
+ // data is just discarded before the dpsm is started.
|
|
|
+ __HAL_SD_SDIO_DMA_ENABLE();
|
|
|
+
|
|
|
SDIO_DataConfig(hsd->Instance, &sdio_datainitstructure);
|
|
|
|
|
|
hsd->SdTransferErr = errorstate;
|