Hi everyone,
here’s what’s happening.
Scenario 1: insert SD card, init handler and mount the card (on user action) - all works perfectly fine.
Scenario 2: Before inserting the SD card try to mount the card (in response to user action), getting an error FR_NOT_READY, which is expected. The problem happens next: after the error I’m inserting the card, reinitialize the handler and trying to mount again, constantly getting FR_NOT_READY.
I’ve tried different speeds, delays, unmounting before initialization etc. Nothing improves the situation. I’d highly appreciate any tip on what I’m missing. Thanks!
Here’s the code to initialize and mount:
// Called on demand
void Card::recognize()
{
SdmmcHandler::Config sd_cfg;
sd_cfg.Defaults();
sd_cfg.speed = SdmmcHandler::Speed::MEDIUM_SLOW;
sd_cfg.width = SdmmcHandler::BusWidth::BITS_1;
\_sd.Init(sd_cfg);
\_fsi.Init(FatFSInterface::Config::MEDIA_SD);
}
// Called 50ms after recognize()
bool Card::mount()
{
auto path = \_fsi.GetSDPath();
if (f_mount(&\_fsi.GetSDFileSystem(), path, 1) != FR_OK) {
return false;
}
\_state = State::mounted;
return true;
}
// Called once user finishes accessing the card and also after mount failure
void Card::unmount()
{
auto path = \_fsi.GetSDPath();
f_mount(NULL, path, 0);
\_fsi.DeInit();
}