SD card not ready when the first command is issued with an Artemis MCU

Hi there,

I need SD card functionality using Mbed OS on my Artemis Thing Plus board. That board comes without an SD slot, so i use [this breakout board.

I discovered a possible SPI related bug that prevented any writes to the SD card and made a [PR on github to fix it (review is pending).

Using the above PR and [this code i recently discovered something that really puzzles me and can not find a solution:

If i program my Artemis Thing Plus while the SD card is inserted into the slot everything is fine.

However if i physically remove and then reinsert the SD card into the slot, then the first time the code tries to send a command, it will fail and timeout after 10 seconds (the default SD timeout duration in Mbed). Actually the first command is sent on line 894 within the _go_idle_state() in SDBlockDevice.cpp. Any subsequent commands will succeed without timing out until i physically remove the card again. For debugging it is worth to set SD_DBG and SD_CMD_TRACE to 1 within SDBlockDevice.cpp.

What puzzles me is that using the same SD example code, the same wiring, SD-slot and SD-card on the MAX32630FTHR board i can not reproduce the above issue. With that board even the very first command is succesful no matter if i reinsert the SD card or not. The only relevant thing i found is a comment within Mbed core’s SDBlockDevice.cpp file around line 888. It seems that the MAX32630FTHR applies some trick to overcome this issue, but i am not an expert and could not find that trick…which also prevents me implementing that trick for the Artemis boards.

Can you guys please take a look? I mean this issue is for sure independent from the one i addressed with the mentioned PR and would be a nice addition to Artemis’ SD functionality with Mbed OS.](mbed-os-snippet-SDBlockDevice/main.cpp at v6.3 · ARMmbed/mbed-os-snippet-SDBlockDevice · GitHub)](Update spi_api.c by idea--list · Pull Request #39 · sparkfun/mbed-os-ambiq-apollo3 · GitHub)](Pololu - Breakout Board for microSD Card)