|
@@ -21,7 +21,7 @@
|
21
|
21
|
*
|
22
|
22
|
*/
|
23
|
23
|
|
24
|
|
-#if defined(__STM32F1__) && (defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY))
|
|
24
|
+#if defined(ARDUINO_ARCH_STM32F1) && (defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY))
|
25
|
25
|
|
26
|
26
|
#include "HAL_sdio_STM32F1.h"
|
27
|
27
|
|
|
@@ -76,7 +76,7 @@ bool SDIO_Init(void) {
|
76
|
76
|
return true;
|
77
|
77
|
}
|
78
|
78
|
|
79
|
|
-bool SDIO_ReadBlock(uint32_t blockAddress, uint8_t *data) {
|
|
79
|
+bool SDIO_ReadBlock_DMA(uint32_t blockAddress, uint8_t *data) {
|
80
|
80
|
if (SDIO_GetCardState() != SDIO_CARD_TRANSFER) return false;
|
81
|
81
|
if (blockAddress >= SdCard.LogBlockNbr) return false;
|
82
|
82
|
if ((0x03 & (uint32_t)data)) return false; // misaligned data
|
|
@@ -100,6 +100,12 @@ bool SDIO_ReadBlock(uint32_t blockAddress, uint8_t *data) {
|
100
|
100
|
|
101
|
101
|
dma_disable(SDIO_DMA_DEV, SDIO_DMA_CHANNEL);
|
102
|
102
|
|
|
103
|
+ if (SDIO->STA & SDIO_STA_RXDAVL) {
|
|
104
|
+ while (SDIO->STA & SDIO_STA_RXDAVL) (void) SDIO->FIFO;
|
|
105
|
+ SDIO_CLEAR_FLAG(SDIO_ICR_CMD_FLAGS | SDIO_ICR_DATA_FLAGS);
|
|
106
|
+ return false;
|
|
107
|
+ }
|
|
108
|
+
|
103
|
109
|
if (SDIO_GET_FLAG(SDIO_STA_TRX_ERROR_FLAGS)) {
|
104
|
110
|
SDIO_CLEAR_FLAG(SDIO_ICR_CMD_FLAGS | SDIO_ICR_DATA_FLAGS);
|
105
|
111
|
return false;
|
|
@@ -108,6 +114,12 @@ bool SDIO_ReadBlock(uint32_t blockAddress, uint8_t *data) {
|
108
|
114
|
return true;
|
109
|
115
|
}
|
110
|
116
|
|
|
117
|
+bool SDIO_ReadBlock(uint32_t blockAddress, uint8_t *data) {
|
|
118
|
+ uint32_t retries = 3;
|
|
119
|
+ while (retries--) if (SDIO_ReadBlock_DMA(blockAddress, data)) return true;
|
|
120
|
+ return false;
|
|
121
|
+}
|
|
122
|
+
|
111
|
123
|
bool SDIO_WriteBlock(uint32_t blockAddress, const uint8_t *data) {
|
112
|
124
|
if (SDIO_GetCardState() != SDIO_CARD_TRANSFER) return false;
|
113
|
125
|
if (blockAddress >= SdCard.LogBlockNbr) return false;
|
|
@@ -264,4 +276,4 @@ bool SDIO_GetCmdResp7(void) {
|
264
|
276
|
return true;
|
265
|
277
|
}
|
266
|
278
|
|
267
|
|
-#endif // __STM32F1__ && (STM32_HIGH_DENSITY || STM32_XL_DENSITY)
|
|
279
|
+#endif // ARDUINO_ARCH_STM32F1 && (STM32_HIGH_DENSITY || STM32_XL_DENSITY)
|