~aleteoryx/muditaos

433322b582957fbfc5888c11b303fa816f28a8f9 — Dawid Wojtas 2 years ago f79313e
[BH-1671] Reinit eMMC driver

Reinit eMMC driver if write/read transmission
failed.
2 files changed, 73 insertions(+), 14 deletions(-)

M harmony_changelog.md
M module-bsp/board/rt1051/bsp/eMMC/fsl_mmc.c
M harmony_changelog.md => harmony_changelog.md +2 -4
@@ 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

M module-bsp/board/rt1051/bsp/eMMC/fsl_mmc.c => module-bsp/board/rt1051/bsp/eMMC/fsl_mmc.c +71 -10
@@ 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);