SDCARD removal and insert detect only partly works

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SDCARD removal and insert detect only partly works

Jump to solution
654 Views
olav
Contributor II
I am working on a SDCARD implementation and have based this on the lpcxpresso55S69_sdcard_fatfs_freertos demo code.

 

The demo code formats the SDCARD when it is inserted and writes some files to the card. I did a small modification to the program basically removing the f_mkfs() call.

 

The modified code works, but the SDCARD_DetectCallBack() function is only called once, either at power up (if the card was inserted before power was applied), or when the card is inserted. The callback function is not called when the card is removed, or if it is reinserted. This worked fine when running the unmodified demo code, but of cause the demo code called f_mkfs() every time the card was reinserted.
 
It seems like the call to f_mkfs() does something with the SD_CARD_DETETECTn interrupt signal, but I have not succeeded in finding what.

 

Any ideas about what is missing from the code to make the function SDCARD_DetectCallBack() be called when card is removed, or inserted the second time, without calling the f_mkfs() function?


Tags (2)
0 Kudos
Reply
1 Solution
541 Views
lucas3
Contributor I

Hello @olav,

I've had a similar problem some weeks ago. 

Here is the call stack (bottom to top) of the problem (simplified code):

sdmmc/sd/fsl_sd.c : status_t SD_Init(sd_card_t *card)
{
if (!card->isHostReady)
SD_HostInit(card);
else
SD_HostDoReset(card);

...//Not important code
}

[our code] : DSTATUS sd_disk_initialize(BYTE pdrv)
{
if(sd is init)
SD_CardDeinit() 

SD_Init()
...
}

[our code] : DSTATUS disk_initialize (BYTE pdrv)
{
sd_disk_initialize(pdrv);
}

fatfs/source/ff.c : ... f_mkfs(...)

At the first call to SD_Init, it goes to SD_HostInit(), wich call SDMMCHOST_CardDetectInit() that enable cardDetect interrupts.

If you call again this function, this go to SD_HostDoReset(), redirecting to 

sdmmc/host/non_blocking/fsl_sdmmc_host.c : SDMMCHOST_Reset()
{
     ...
    SDIF_DisableInterrupt(host->hostController.base, kSDIF_AllInterruptStatus); //This disable all host interrupts, including CardDetect interrupt
    ...
}

 Card detect interrupt is never re-activated later...

 

We fixed this problem by changing the line to :

 SDIF_DisableInterrupt(host->hostController.base, kSDIF_AllInterruptStatus & ~kSDIF_CardDetect); //Disable all interrupts except card detect

 

I hope your problem is related

View solution in original post

4 Replies
542 Views
lucas3
Contributor I

Hello @olav,

I've had a similar problem some weeks ago. 

Here is the call stack (bottom to top) of the problem (simplified code):

sdmmc/sd/fsl_sd.c : status_t SD_Init(sd_card_t *card)
{
if (!card->isHostReady)
SD_HostInit(card);
else
SD_HostDoReset(card);

...//Not important code
}

[our code] : DSTATUS sd_disk_initialize(BYTE pdrv)
{
if(sd is init)
SD_CardDeinit() 

SD_Init()
...
}

[our code] : DSTATUS disk_initialize (BYTE pdrv)
{
sd_disk_initialize(pdrv);
}

fatfs/source/ff.c : ... f_mkfs(...)

At the first call to SD_Init, it goes to SD_HostInit(), wich call SDMMCHOST_CardDetectInit() that enable cardDetect interrupts.

If you call again this function, this go to SD_HostDoReset(), redirecting to 

sdmmc/host/non_blocking/fsl_sdmmc_host.c : SDMMCHOST_Reset()
{
     ...
    SDIF_DisableInterrupt(host->hostController.base, kSDIF_AllInterruptStatus); //This disable all host interrupts, including CardDetect interrupt
    ...
}

 Card detect interrupt is never re-activated later...

 

We fixed this problem by changing the line to :

 SDIF_DisableInterrupt(host->hostController.base, kSDIF_AllInterruptStatus & ~kSDIF_CardDetect); //Disable all interrupts except card detect

 

I hope your problem is related

508 Views
olav
Contributor II

Thank you @lucas3

This fixed the problem. Hope someone at NXP pics this up, because it is obviously a bug in the SDK.

Olav

 

608 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello @olav 

Could you please tell why do you want to remove  f_mkfs()?

 

BR

Alice

0 Kudos
Reply
603 Views
olav
Contributor II

Hi Alice

The f_mkfs() function formats the SDCARD, in other words all data will be lost every time I call  f_mkfs() (at card insert, or power up), and that's not useful at all

BR

Olav

0 Kudos
Reply