-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Can't remove/reinsert SD card in SPI mode, esp32 just hangs #3931
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
also different other ESP SD lib functions are still working faulty, e.g. see #3603 |
"Can't remove/reinsert SD card in SPI mode, esp32 just hangs" |
Looking at sd_diskio.cpp, there are many calls to sdWait(), which means that the code can deal with timeouts, which should then allow the higher level SD library to fail gracefully, ie, calls would return false. The log shows 3 "no token received" messages just before hanging. It's possible that it's hanging in an endless loop somewhere after that, instead of just returning a failure. Since this looks more like a bug, rather than an intentional limitation, instead of going on a possible snipe hunt myself, I thought I'd check with the people who wrote, or at least are familiar with this code. That is, not you. And it's possible, I provided a workaround, but it's inefficient and it's just covering what looks like a bug. |
It would not occur to one sane person to remove a memory card from a working microcontroller. |
I don't really see why it's up to you to decide what should and should not get fixed, or at the very least discussed with the devs here. Go do something useful instead of trolling random issues on github. |
OK good luck. |
@josedpedroso I suspect this usecase has not been implemented in the library itself for much the same reason as @rel1ct alludes to, why should the library support removal of the device it is actively using.. there are a lot of overheads to contend with in supporting removal that are not easily solved, one being closing/invalidating open file handles (not all are/can be tracked by the SD class!) I would suggest if you need support for hot swapping of SD cards is to treat it similar to how Windows does.. provide a user option to gracefully shutdown usages and then inform the user to swap. This will involve SD.end() before removal and SD.begin() after a new SD has been inserted. |
If you have a HARDWARE card detect pin, then it is possible to set an interrupt on the pin. If you paid $5 for a cheap SD module, you get what you paid for. |
That makes sense.
I considered doing something like that, though for now, my workaround does the trick, and doesn't require user interaction. But it's possible I'll have to do just that.
The ESP32-cam doesn't have it, it's actually one of the things I checked while troubleshooting this. |
Hardware:
Board: ESP32-cam
Core Installation version: esp32 boards 1.0.4
IDE name: Arduino 1.8.12
Flash Frequency: 80Mhz
PSRAM enabled: no
Upload Speed: 115200
Computer OS: Windows 7 x64
Description:
One part of my current project involves making a web-based file explorer for the SD card in an esp32-cam board. So, I decided to start with the SDWebServer example. It works fine, as long as I don't remove the card while the sketch is running. However, I'd like for that to be possible. Looking at sd_diskio.cpp, I can see that there are timeouts, but for some reason they're not working.
Sketch:
Debug Messages:
At 04:38:03, I loaded a page on my browser. Then, I removed the microsd card and, at 04:38:21, hit refresh on my browser, but there was no response. Some time later, I reinserted the same card, and hit stop and refresh again, but there was no response either.
1st workaround I tried:
Then, on each request, I called init_sd(), and if it returned false, I just had the request fail. However, this doesn't work because the linker can't find sdWait(), and even if it did find it, I really don't know if this would fix the issue.
2nd workaround:
I just do SD.begin() and check SD.cardType() before serving any request, and afterwards, I call SD.end(). This works, but it's kinda ugly, and will probably still fail if I remove the card while it's reading or writing something.
The text was updated successfully, but these errors were encountered: