|
@ -21,7 +21,7 @@ |
|
|
* |
|
|
* |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
#if defined(__STM32F1__) && (defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY)) |
|
|
#if defined(ARDUINO_ARCH_STM32F1) && (defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY)) |
|
|
|
|
|
|
|
|
#include "HAL_sdio_STM32F1.h" |
|
|
#include "HAL_sdio_STM32F1.h" |
|
|
|
|
|
|
|
@ -76,7 +76,7 @@ bool SDIO_Init(void) { |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool SDIO_ReadBlock(uint32_t blockAddress, uint8_t *data) { |
|
|
bool SDIO_ReadBlock_DMA(uint32_t blockAddress, uint8_t *data) { |
|
|
if (SDIO_GetCardState() != SDIO_CARD_TRANSFER) return false; |
|
|
if (SDIO_GetCardState() != SDIO_CARD_TRANSFER) return false; |
|
|
if (blockAddress >= SdCard.LogBlockNbr) return false; |
|
|
if (blockAddress >= SdCard.LogBlockNbr) return false; |
|
|
if ((0x03 & (uint32_t)data)) return false; // misaligned data
|
|
|
if ((0x03 & (uint32_t)data)) return false; // misaligned data
|
|
@ -100,6 +100,12 @@ bool SDIO_ReadBlock(uint32_t blockAddress, uint8_t *data) { |
|
|
|
|
|
|
|
|
dma_disable(SDIO_DMA_DEV, SDIO_DMA_CHANNEL); |
|
|
dma_disable(SDIO_DMA_DEV, SDIO_DMA_CHANNEL); |
|
|
|
|
|
|
|
|
|
|
|
if (SDIO->STA & SDIO_STA_RXDAVL) { |
|
|
|
|
|
while (SDIO->STA & SDIO_STA_RXDAVL) (void) SDIO->FIFO; |
|
|
|
|
|
SDIO_CLEAR_FLAG(SDIO_ICR_CMD_FLAGS | SDIO_ICR_DATA_FLAGS); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (SDIO_GET_FLAG(SDIO_STA_TRX_ERROR_FLAGS)) { |
|
|
if (SDIO_GET_FLAG(SDIO_STA_TRX_ERROR_FLAGS)) { |
|
|
SDIO_CLEAR_FLAG(SDIO_ICR_CMD_FLAGS | SDIO_ICR_DATA_FLAGS); |
|
|
SDIO_CLEAR_FLAG(SDIO_ICR_CMD_FLAGS | SDIO_ICR_DATA_FLAGS); |
|
|
return false; |
|
|
return false; |
|
@ -108,6 +114,12 @@ bool SDIO_ReadBlock(uint32_t blockAddress, uint8_t *data) { |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool SDIO_ReadBlock(uint32_t blockAddress, uint8_t *data) { |
|
|
|
|
|
uint32_t retries = 3; |
|
|
|
|
|
while (retries--) if (SDIO_ReadBlock_DMA(blockAddress, data)) return true; |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
bool SDIO_WriteBlock(uint32_t blockAddress, const uint8_t *data) { |
|
|
bool SDIO_WriteBlock(uint32_t blockAddress, const uint8_t *data) { |
|
|
if (SDIO_GetCardState() != SDIO_CARD_TRANSFER) return false; |
|
|
if (SDIO_GetCardState() != SDIO_CARD_TRANSFER) return false; |
|
|
if (blockAddress >= SdCard.LogBlockNbr) return false; |
|
|
if (blockAddress >= SdCard.LogBlockNbr) return false; |
|
@ -264,4 +276,4 @@ bool SDIO_GetCmdResp7(void) { |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#endif // __STM32F1__ && (STM32_HIGH_DENSITY || STM32_XL_DENSITY)
|
|
|
#endif // ARDUINO_ARCH_STM32F1 && (STM32_HIGH_DENSITY || STM32_XL_DENSITY)
|
|
|