SDIO cleanup

This commit is contained in:
Scott Lahteine 2021-04-16 02:50:45 -05:00
parent 528b9bd872
commit c6c6c56186

View file

@ -85,8 +85,8 @@
#define SDIO_CMD_PIN PD2 #define SDIO_CMD_PIN PD2
SD_HandleTypeDef hsd; // create SDIO structure SD_HandleTypeDef hsd; // create SDIO structure
// F4 support one dma for RX and another for TX. // F4 supports one DMA for RX and another for TX, but Marlin will never
// But Marlin will never do read and write at same time, so we use always one dma for both. // do read and write at same time, so we use the same DMA for both.
DMA_HandleTypeDef hdma_sdio; DMA_HandleTypeDef hdma_sdio;
/* /*
@ -274,7 +274,7 @@
} }
static bool SDIO_ReadWriteBlock_DMA(uint32_t block, const uint8_t *src, uint8_t *dst) { static bool SDIO_ReadWriteBlock_DMA(uint32_t block, const uint8_t *src, uint8_t *dst) {
if(HAL_SD_GetCardState(&hsd) != HAL_SD_CARD_TRANSFER) return false; if (HAL_SD_GetCardState(&hsd) != HAL_SD_CARD_TRANSFER) return false;
TERN_(USE_WATCHDOG, HAL_watchdog_refresh()); TERN_(USE_WATCHDOG, HAL_watchdog_refresh());
@ -296,10 +296,10 @@
return false; return false;
} }
uint32_t timeout = millis() + 500; millis_t timeout = millis() + 500;
// Wait the transfer // Wait the transfer
while (hsd.State != HAL_SD_STATE_READY) { while (hsd.State != HAL_SD_STATE_READY) {
if (millis() > timeout) { if (ELAPSED(millis(), timeout)) {
HAL_DMA_Abort_IT(&hdma_sdio); HAL_DMA_Abort_IT(&hdma_sdio);
HAL_DMA_DeInit(&hdma_sdio); HAL_DMA_DeInit(&hdma_sdio);
return false; return false;
@ -313,8 +313,7 @@
HAL_DMA_DeInit(&hdma_sdio); HAL_DMA_DeInit(&hdma_sdio);
timeout = millis() + 500; timeout = millis() + 500;
while (HAL_SD_GetCardState(&hsd) != HAL_SD_CARD_TRANSFER) while (HAL_SD_GetCardState(&hsd) != HAL_SD_CARD_TRANSFER) if (ELAPSED(millis(), timeout)) return false;
if (millis() > timeout) return false;
return true; return true;
} }