@@ 50,15 50,13 @@
#### General:
* Fixed displayed device name when connected to Windows
+* Minor firmware fixes/optimizations.
+* Reinitialization of eMMC driver after failure
#### UI/UX:
* Added missing translations in French.
-#### General:
-
-* Minor firmware fixes/optimizations.
-
## [1.8.2 2023-04-03]
### Added
@@ 35,6 35,8 @@
#include <string.h>
#include "fsl_mmc.h"
+#include <log/log.hpp>
+
/*******************************************************************************
* Definitons
******************************************************************************/
@@ 2146,11 2148,14 @@ status_t MMC_ReadBlocks(mmc_card_t *card, uint8_t *buffer, uint32_t startBlock,
assert(buffer);
assert(blockCount);
+ const uint8_t maxAttempts = 5;
uint32_t blockCountOneTime; /* The block count can be erased in one time sending READ_BLOCKS command. */
uint32_t blockDone; /* The blocks has been read. */
uint32_t blockLeft; /* Left blocks to be read. */
uint8_t *nextBuffer;
bool dataAddrAlign = true;
+ bool errorOccured = false;
+ bool isWriteOk = false;
blockLeft = blockCount;
blockDone = 0U;
@@ 2177,11 2182,37 @@ status_t MMC_ReadBlocks(mmc_card_t *card, uint8_t *buffer, uint32_t startBlock,
}
}
- if (kStatus_Success != MMC_Read(card,
- dataAddrAlign ? nextBuffer : (uint8_t *)g_sdmmc,
- (startBlock + blockDone),
- FSL_SDMMC_DEFAULT_BLOCK_SIZE,
- blockCountOneTime)) {
+ for (uint8_t i = 0; i < maxAttempts; i++)
+ {
+ if (errorOccured)
+ {
+ if (MMC_Init(card) == kStatus_Success)
+ {
+ LOG_ERROR("MMC reinit OK\n");
+ errorOccured = false;
+ }
+ else
+ {
+ LOG_ERROR("MMC reinit error\n");
+ continue;
+ }
+ }
+
+ if (kStatus_Success != MMC_Read(card, dataAddrAlign ? nextBuffer : (uint8_t *)g_sdmmc, (startBlock + blockDone),
+ FSL_SDMMC_DEFAULT_BLOCK_SIZE, blockCountOneTime))
+ {
+ LOG_ERROR("MMC_Read transfer failed\n");
+ errorOccured = true;
+ }
+ else
+ {
+ isWriteOk = true;
+ break;
+ }
+ }
+
+ if (!isWriteOk)
+ {
return kStatus_SDMMC_TransferFailed;
}
@@ 2201,11 2232,14 @@ status_t MMC_WriteBlocks(mmc_card_t *card, const uint8_t *buffer, uint32_t start
assert(buffer);
assert(blockCount);
+ const uint8_t maxAttempts = 5;
uint32_t blockCountOneTime;
uint32_t blockLeft;
uint32_t blockDone;
const uint8_t *nextBuffer;
bool dataAddrAlign = true;
+ bool errorOccured = false;
+ bool isWriteOk = false;
blockLeft = blockCount;
blockDone = 0U;
@@ 2233,14 2267,41 @@ status_t MMC_WriteBlocks(mmc_card_t *card, const uint8_t *buffer, uint32_t start
}
}
- if (kStatus_Success != MMC_Write(card,
- dataAddrAlign ? nextBuffer : (uint8_t *)g_sdmmc,
- (startBlock + blockDone),
- FSL_SDMMC_DEFAULT_BLOCK_SIZE,
- blockCountOneTime)) {
+ for (uint8_t i = 0; i < maxAttempts; i++)
+ {
+ if (errorOccured)
+ {
+ if (MMC_Init(card) == kStatus_Success)
+ {
+ LOG_ERROR("MMC reinit OK\n");
+ errorOccured = false;
+ }
+ else
+ {
+ LOG_ERROR("MMC reinit error\n");
+ continue;
+ }
+ }
+
+ if (kStatus_Success != MMC_Write(card, dataAddrAlign ? nextBuffer : (uint8_t *)g_sdmmc,
+ (startBlock + blockDone), FSL_SDMMC_DEFAULT_BLOCK_SIZE, blockCountOneTime))
+ {
+ LOG_ERROR("MMC_Write transfer failed\n");
+ errorOccured = true;
+ }
+ else
+ {
+ isWriteOk = true;
+ break;
+ }
+ }
+
+ if (!isWriteOk)
+ {
return kStatus_SDMMC_TransferFailed;
}
+
blockDone += blockCountOneTime;
if (!card->noInteralAlign) {
memset(g_sdmmc, 0U, FSL_SDMMC_DEFAULT_BLOCK_SIZE);