How to detect SD card by DAT3 in bare metal code using MCXN947?

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

How to detect SD card by DAT3 in bare metal code using MCXN947?

158件の閲覧回数
TomC818
Contributor III

I have done some digging and I see that the driver fsl_sdmmc_host implemented a method included the use of an OSA adapter in order to detect the sd card. In fact all sdmmc driver include the use of OSA in some extend whether used non-blocking or not.

I understand that detection through CD pin is the preferred solution, but due to hardware design DAT3 card detection need to be used in our case.

So, I want to ask if there is a way to do data3 detection in bare metal?

In fsl_sdmmc_host.c

uint32_t SDMMCHOST_CardDetectStatus(sdmmchost_t *host)
{
    sd_detect_card_t *sdCD = (sd_detect_card_t *)(host->cd);
    uint32_t insertStatus  = kSD_Removed;

    if (sdCD->type == kSD_DetectCardByHostDATA3)
    {
        if (sdCD->dat3PullFunc != NULL)
        {
            sdCD->dat3PullFunc(kSD_DAT3PullDown);
            SDMMC_OSADelay(SDMMCHOST_DATA3_DETECT_CARD_DELAY);
        }
        USDHC_CardDetectByData3(host->hostController.base, true);
        /* Added 1ms delay after host enabled the DAT3 function to avoid CPU missing synchronization with host */
        SDMMC_OSADelay(SDMMCHOST_DATA3_DETECT_CARD_DELAY);
    }
    else
    {
        USDHC_CardDetectByData3(host->hostController.base, false);
    }

    if ((USDHC_GetPresentStatusFlags(host->hostController.base) & (uint32_t)kUSDHC_CardInsertedFlag) != 0U)
    {
        insertStatus = kSD_Inserted;

        if (sdCD->type == kSD_DetectCardByHostDATA3)
        {
            if (sdCD->dat3PullFunc != NULL)
            {
                sdCD->dat3PullFunc(kSD_DAT3PullUp);
            }
            /* disable the DAT3 card detec function */
            USDHC_CardDetectByData3(host->hostController.base, false);
        }
    }

    return insertStatus;
}
0 件の賞賛
返信
1 返信

94件の閲覧回数
Harry_Zhang
NXP Employee
NXP Employee

Hi @TomC818 

Yes, you can implement DAT3 card detection in bare metal on the NXP MCXN947, even without an RTOS or the OSA layer. The key is to replicate the logic used in the SDK's fsl_sdmmc_host.c but replace the OSA-dependent parts with your own delay and GPIO control functions.

BR

Harry

0 件の賞賛
返信