How to handle SD card eject & reinsert?

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

How to handle SD card eject & reinsert?

Jump to solution
2,168 Views
jackking
Senior Contributor I

I am using the IMXRT1062 and testing the SDK examples for FatFS SDcard.  It seems that when the card is ejected and reinserted, FatFS can no longer read any files.

I have tried unmounting the disk on ejection using f_mount(0, "", 0)

I also tried SD_HostDeinit() on eject and then reinit on insertion, but these don't seem to work.

The SDK example doesn't seem to handle reinsertion at all.

What is the correct way to handle eject/insert of the SDcard while the MCU is running?

0 Kudos
1 Solution
1,963 Views
jackking
Senior Contributor I

OK, I think I found and resolved my issue.  It appears that the SDK is missing some functionality, specifically for managing the Card Detect of a MicroSD card.    I am using a MicroSD card in an adapter.

Please see the following thread for details: https://community.nxp.com/message/1272833?commentID=1272833#comment-1272833

Essentially, I had to add the function to turn off the DAT3 pull-up for card detect.  That is why it was failing on reinsert.

After adding this, the card can be reliably read again after reinsert!

View solution in original post

0 Kudos
5 Replies
1,963 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi Jack,

I made a demo base on the example evkmimxrt1060_fatfs_usdcard. It seems you don't need to do anything after desert.  The files in SD card is created by original fatfs_usdcard project.

Regards,

Jing

0 Kudos
1,963 Views
jackking
Senior Contributor I

My test case is a little different.

I see in your example you did not MKFS and create the files on first insertion, assuming they were created some other time:

 

local_workspace_-_evkmimxrt1060_fatfs_usdcard_source_fatfs_sdcard_c_-_MCUXpresso_IDE.jpg

In my example I create the filesystem and files on first insertion each time and then the reinsert fails.

I have modified your example and tested, here is the output:

local_workspace_-_evkmimxrt1060_fatfs_usdcard_source_fatfs_sdcard_c_-_MCUXpresso_IDE.jpg

I am attaching the modified project, which I also changed to use semihosting with a J-Link, linked to RAM.

0 Kudos
1,963 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi,

It is strange. You code works fine on my board.

pastedImage_1.png

Can you try another card?

Regards,

Jing

0 Kudos
1,964 Views
jackking
Senior Contributor I

OK, I think I found and resolved my issue.  It appears that the SDK is missing some functionality, specifically for managing the Card Detect of a MicroSD card.    I am using a MicroSD card in an adapter.

Please see the following thread for details: https://community.nxp.com/message/1272833?commentID=1272833#comment-1272833

Essentially, I had to add the function to turn off the DAT3 pull-up for card detect.  That is why it was failing on reinsert.

After adding this, the card can be reliably read again after reinsert!

0 Kudos
1,963 Views
jackking
Senior Contributor I

I am still banging my head on this. 

Hopefully someone has dealt with this same issue?  I would assume it is a really common requirement.

0 Kudos