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?
Solved! Go to Solution.
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!
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:
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:
I am attaching the modified project, which I also changed to use semihosting with a J-Link, linked to RAM.
Hi,
It is strange. You code works fine on my board.
Can you try another card?
Regards,
Jing
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!
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.