Skip to content

SD.begin() crashes the board if called again after failing to mount #613

Closed
@tetious

Description

@tetious

Hardware:

Board: ESP32-DevKitC
Core Installation/update date: 9/6/2017
IDE name: Tested with platformio stage and "stable"

Description:

If the first attempt mounting an SD card via SD.begin() fails for some reason (such as the SPI bus is disconnected), subsequent calls crash the board. I suspect something is either not getting cleaned up or is getting cleaned up incorrectly when the mount fails.

If the card mounts successfully, I can run SD.end() and then SD.begin() as many times as I like without issue.

Sketch:

You can reproduce this by running the sketch below while not having an SD card reader attached.

#include <Arduino.h>
#include <SD.h>

void setup() {  
    Serial.begin(115200);
}

void init_sd() {
    if(!SD.begin()){
        Serial.println("Card Mount Failed");
        return;
    }
}

void loop() {
    Serial.println("First attempt, will fail.");
    init_sd();
    delay(5000);
    Serial.println("Second attempt, will crash the board.");
    init_sd(); // boom
}

Debug Messages:

First attempt, will fail.
[E][sd_diskio.cpp:739] sdcard_mount(): f_mount failed 0x(3)
Card Mount Failed
Second attempt, will crash the board.
/Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/freertos/./queue.c:1792 (vQueueDelete)- assert failed!
abort() was called at PC 0x40084a97 on core 1

Backtrace: 0x40087010:0x3ffccb40 0x4008710f:0x3ffccb60 0x40084a97:0x3ffccb80 0x400fbf21:0x3ffccba0 0x400fa7c2:0x3ffccbc0 0x400f134a:0x3ffccc00 0x400f079d:0x3ffccc30 0x400d0a39:0x3ffccc60 0x400d0a6b:0x3ffccc80 0x400f21d5:0x3ffccca0

Rebooting...
ets Jun  8 2016 00:22:57

Stacktrace:

No extra info seems to show up with debug on, but I've attached a decoded but not particularly helpful stacktrace:

0x00000bac: ?? ??:0
0x400fa7c2: f_mount at ff.c:4443
0x3ffccc80: ?? ??:0

Thanks for all your awesome work and let me know if I can provide any additional information.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions