Can not re-initialize the SD card after error

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();
}

Does this happen if you power down the daisy, and/or push the reset button after the failure? Or does it only happen when an unsuccessful mount happens first, and then you retry at runtime?

If it’s only the second case, I think I’ve run into this a few times. I’ll have to go back over a few projects and see if I resolved it or not.


Also, in the future you can surround your code in three backtick characters ( ` ) to format it for easier reading in the post. You can also select a language for syntax highlighting

For example:

printf("Hello, World!");

It’s the second case. If you find something in your archive that gonna help me tremendously.
Thanks for the formatting and the hint!