@@ -234,10 +234,12 @@ SD_Error SD_WaitReadOperation(void);
234
234
SD_Error SD_WaitWriteOperation (void );
235
235
236
236
// undo the STM32F1-specific defines
237
+ #ifndef SD_OVERRIDE
237
238
#undef SD_DMA_MODE
238
239
#undef SD_INTERRUPT_MODE
239
240
#undef SD_POLLING_MODE
240
241
#define SD_DMA_MODE 1
242
+ #endif
241
243
242
244
SD_Error SD_SetDeviceMode (uint32_t Mode ) {
243
245
NOT_USED (Mode ); // ignored, it's now build-time
@@ -417,6 +419,8 @@ SDCardState SD_GetState(void);
417
419
#define SD_HALFFIFO ((uint32_t)0x00000008)
418
420
#define SD_HALFFIFOBYTES ((uint32_t)0x00000020)
419
421
422
+ #define SD_WAIT_CYCLES ((uint32_t)1000000) // how long to wait at most if polling
423
+
420
424
/**
421
425
* @brief Command Class Supported
422
426
*/
@@ -1363,7 +1367,7 @@ SD_Error SD_ReadBlock(uint32_t ReadAddr, uint32_t *readbuff, uint16_t BlockSize)
1363
1367
errorstatus = SD_START_BIT_ERR ;
1364
1368
return (errorstatus );
1365
1369
}
1366
- count = SD_DATATIMEOUT ;
1370
+ count = SD_WAIT_CYCLES ;
1367
1371
while ((SDIO_GetFlagStatus (SDIO_FLAG_RXDAVL ) != RESET ) && (count > 0 ))
1368
1372
{
1369
1373
* tempbuff = SDIO_ReadData ();
@@ -1539,16 +1543,17 @@ SD_Error SD_WaitReadOperation(void)
1539
1543
SD_Error errorstatus = SD_OK ;
1540
1544
uint32_t timeout ;
1541
1545
1542
- timeout = SD_DATATIMEOUT ;
1543
-
1546
+ #ifndef SD_POLLING_MODE
1547
+ timeout = SD_WAIT_CYCLES ;
1544
1548
while ((DMAEndOfTransfer == 0x00 ) && (TransferEnd == 0 ) && (TransferError == SD_OK ) && (timeout > 0 ))
1545
1549
{
1546
1550
timeout -- ;
1547
1551
}
1552
+ #endif
1548
1553
1549
1554
DMAEndOfTransfer = 0x00 ;
1550
1555
1551
- timeout = SD_DATATIMEOUT ;
1556
+ timeout = SD_WAIT_CYCLES ;
1552
1557
1553
1558
while (((SDIO -> STA & SDIO_FLAG_RXACT )) && (timeout > 0 ))
1554
1559
{
@@ -1929,7 +1934,7 @@ SD_Error SD_WaitWriteOperation(void)
1929
1934
SD_Error errorstatus = SD_OK ;
1930
1935
uint32_t timeout ;
1931
1936
1932
- timeout = SD_DATATIMEOUT ;
1937
+ timeout = SD_WAIT_CYCLES ;
1933
1938
1934
1939
while ((DMAEndOfTransfer == 0x00 ) && (TransferEnd == 0 ) && (TransferError == SD_OK ) && (timeout > 0 ))
1935
1940
{
@@ -1938,7 +1943,7 @@ SD_Error SD_WaitWriteOperation(void)
1938
1943
1939
1944
DMAEndOfTransfer = 0x00 ;
1940
1945
1941
- timeout = SD_DATATIMEOUT ;
1946
+ timeout = SD_WAIT_CYCLES ;
1942
1947
1943
1948
while (((SDIO -> STA & SDIO_FLAG_TXACT )) && (timeout > 0 ))
1944
1949
{
@@ -2096,7 +2101,7 @@ SD_Error SD_Erase(uint32_t startaddr, uint32_t endaddr)
2096
2101
2097
2102
/*!< Wait till the card is in programming state */
2098
2103
errorstatus = IsCardProgramming (& cardstate );
2099
- delay = SD_DATATIMEOUT ;
2104
+ delay = SD_WAIT_CYCLES ;
2100
2105
while ((delay > 0 ) && (errorstatus == SD_OK ) && ((SD_CARD_PROGRAMMING == cardstate ) || (SD_CARD_RECEIVING == cardstate )))
2101
2106
{
2102
2107
errorstatus = IsCardProgramming (& cardstate );
@@ -2246,7 +2251,7 @@ SD_Error SD_SendSDStatus(uint32_t *psdstatus)
2246
2251
return (errorstatus );
2247
2252
}
2248
2253
2249
- count = SD_DATATIMEOUT ;
2254
+ count = SD_WAIT_CYCLES ;
2250
2255
while ((SDIO_GetFlagStatus (SDIO_FLAG_RXDAVL ) != RESET ) && (count > 0 ))
2251
2256
{
2252
2257
* psdstatus = SDIO_ReadData ();
0 commit comments