espressif / arduino-esp32

Arduino core for the ESP32
GNU Lesser General Public License v2.1
13.42k stars 7.37k forks source link

SD lib w/ card 'flakey'? #272

Closed ladyada closed 7 years ago

ladyada commented 7 years ago

heya im using known good hardware, with pullups on the SD CS line, no level shifters, PCB traces not jumpers - but getting 'flakiness' on init/mount

[E][sd_diskio.cpp:99] sdSelectCard(): timeout
[E][sd_diskio.cpp:708] sdcard_mount(): f_mount failed 0x(3)
Card Mount Failed

oddly, it works maybe 10% of the time. once it starts working, it 'keeps' working until a full power reset. if it doesn't work, sometimes hitting software reset helps, but usually not. this is with the SPI library - tried changing SPI speed in SD.begin() without any noticable changes. still investigating ... but making a note here in case others can reproduce

fyi, grabbing the non-optimized SD library works great with no hiccups - https://github.com/adafruit/arduino-esp32/tree/d602169ebcd126c309009e87c1e455f2c892d08f (yeah sorry it got smooshed in the upstream merge so please download the zip from that point to get the library files)

me-no-dev commented 7 years ago

Hm that is rather strange. I had gazillion of issues with SD_MMC and pullups but none with SD. I just connected the 4 data lines directly to SPI and that was it (I use SD->MicroSD with some wires soldered directly on the pads). Which pins are you using?

ladyada commented 7 years ago

static const uint8_t MOSI = 18; static const uint8_t MISO = 19; static const uint8_t SCK = 5;

and cs on any pin really, but im using

define SD_CS 33

other than the SD card, all other SPI devices ive tested are working perfectly - TFT display, LoRa and RFM radio modules, VS1053

me-no-dev commented 7 years ago

Done :)

ladyada commented 7 years ago

looks good - would you like me to re-test?

me-no-dev commented 7 years ago

Sure :) Confirmation is always good, but I was able to reproduce the issue and after the fix, was not able to anymore, regardless of what I did :) I wonder how it was working while I was developing the library? BTW I tested with your pin configuration

void mountSdCard(){
    SPI.begin(5,19,18);
    if(!SD.begin(33)){
        Serial.println("Card Mount Failed");
        return;
    }
}
ladyada commented 7 years ago

hiya - ok so for one of my feather setups, with cardcs on IO 27, it now works every time. on another feather, with cs on IO 14 it still doesnt work :/

Initializing SD card...[E][sd_diskio.cpp:99] sdSelectCard(): timeout [W][sd_diskio.cpp:452] ff_sd_initialize(): GO_IDLE_STATE failed [E][sd_diskio.cpp:724] sdcard_mount(): f_mount failed 0x(3) failed!

me-no-dev commented 7 years ago

maybe on io14 there is another issue? I mean, if SPI is properly configured, and you use pins below 34, the lib itself does not care which pin you have selected. It calls digitalWrite to control SS

ladyada commented 7 years ago

yeah unknown. ill investigate more later... :)

NickWaterton commented 7 years ago

Interesting, I am having the same problem. Using the TFT feather wing (CS 14), the SD card works about 50% of the time, using the music maker featherwing, I can't get the same SD card to work at all (also CS 14).

SPI works fine with graphics and music etc, it's just the SD card that is unreliable. If I wasn't having a similar problem (but not as bad) with the TFT featherwing, I'd suspect a bad reader on the music maker.

When I have a chance I'll try it with an M0 or a WICED, see if they work with the music maker.

badcf00d commented 7 years ago

I'm using the same pins as ladyada, coming from the adalogger featherwing, and I can't get the card to mount at all using:

#include <SD.h>
#include <SPI.h>

void setup() {
  Serial.begin(115200);
  SPI.begin(5, 19, 18);
  if (!SD.begin(33)) {
    Serial.println("Card Mount Failed");
  }
}

SD card works in an M0 datalogger, but no luck with the ESP32 :/

ladyada commented 7 years ago

@me-no-dev hmm do you mind if we send you some hardware that you can test with? the SD card works if we use our ported 'arduino-SD-library' but not with the SD library ya'll included. so I think its some init thing?

me-no-dev commented 7 years ago

@ladyada yes please! let's get this fixed :) How are we going to arrange this?

me-no-dev commented 7 years ago

done :)

ladyada commented 7 years ago

k email addr deleted, we'll reply

dstoiko commented 7 years ago

[E][sd_diskio.cpp:724] sdcard_mount(): f_mount failed 0x(3) @me-no-dev thanks for this lib! Having the same issue here... Thought it was an issue with pull-up resistors at first but it doesn't seem to be. Any updates on this?

me-no-dev commented 7 years ago

Things just showed up :) will solder the boards tonight and prep everything

dstoiko commented 7 years ago

That sounds exciting

ladyada commented 7 years ago

yay - we have a full kit of cousre, and can try replicating any branches/fixes

dstoiko commented 7 years ago

So do we know where this issue comes from? What can I do to further test?

me-no-dev commented 7 years ago

OK I need more info on the failing cards because here is my first result at this (Feather selected as board) Maybe there are particular steps to follow?: fullsizerender 21 screen shot 2017-07-07 at 1 36 37 am screen shot 2017-07-07 at 1 36 50 am

ladyada commented 7 years ago

can you try a few times? also try plugging the esp32 into the tft feather and drawing a BMP from SD? that's the only thing i can say we tried and had difficulty with :)

NickWaterton commented 7 years ago

I found with the tft feather, it works about 50% of the time.

I was using the music maker feather also, and it works 0% of the time with that (same pins).

I haven tried the data logger feather at all.

Nick Waterton P.Eng Sent from my iPhone

On Jul 6, 2017, at 8:15 PM, ladyada notifications@github.com<mailto:notifications@github.com> wrote:

can you try a few times? also try plugging the esp32 into the tft feather and drawing a BMP from SD? that's the only thing i can say we tried and had difficulty with :)

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/espressif/arduino-esp32/issues/272#issuecomment-313553163, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ALCUZxuQ_GO000hKaWuJXnqJDjV9h4vlks5sLXiYgaJpZM4MhlJK.

Unsubscribe from GE's commercial electronic messages: http://sc.ge.com/*casl-unsubscribe Désabonner des messages électroniques commerciaux de GE: http://sc.ge.com/*lcap-desabonnement

bbx10 commented 7 years ago

@NickWaterton Are you referring to the SD card slot on the music maker wing? The VS1053 part works fine using the ESP32-Radio project.

me-no-dev commented 7 years ago

Hit a wall with the TFT Wing :) looking into it :) @bbx10 yes, SD is the issue

me-no-dev commented 7 years ago

@ladyada I seem to get intermittent issues wit the touch on the TFT as well. Like it will not start every once in a while. Have you notice this?

me-no-dev commented 7 years ago

please try the latest commit :)

me-no-dev commented 7 years ago

And here is a JPEG read from the SD card :) fullsizerender 22

bbx10 commented 7 years ago

@me-no-dev Works fine with SD card slot on Feather Adalogger (CS=33) and Music Maker (CS=14).

dstoiko commented 7 years ago

@me-no-dev @ladyada Our config is custom, nothing to do with Feather. We have an ESP32-DevKitC with a WROOM-32, mounted on our PCB, and we've tried several different µSD/SD modules, all with the same intermittent mounting error:

As a side note, when using an SPI-based LED matrix module (MAX7219) on the bus, trying to use the SD module crashes the ESP32. We had to remove the SD from our configuration which is pretty debilitating at the moment.

Any ideas where the solution might be?

@ladyada you said your port of the Adafruit SD library for Arduino boards worked 100%. I haven't seen that port anywhere, just the Arduino version. Do you have it on one of your repos?

me-no-dev commented 7 years ago

@dstoiko did you try the latest commit? It's not a fix just for this board.

me-no-dev commented 7 years ago

@dstoiko also I do not see you mention which pins you are using for SPI

NickWaterton commented 7 years ago

Yes, the VS1053 works just fine. The SD card slot does not. I didn’t build the ESP32-Radio project, I’m streaming Bluetooth audio and playing it via the music maker. I noticed that the SD card slot doesn’t work though, so I tried it on a tft feather I have, and it works about 50% of the time.

I’m not using the sd card slot in my project, but I tried to get it to work (for testing) and couldn’t.

Nick Waterton P.Eng. National Support Leader - Nuclear Medicine, PET and RP GE Healthcare

M+1 416 859 8545 F +1 905 248 3089 E nick.waterton@med.ge.commailto:nick.waterton@med.ge.com

2300 Meadowvale Boulevard Mississauga, ON L5N 5P9 Canada

GE imagination at work

From: bbx10 [mailto:notifications@github.com] Sent: July-06-17 10:14 PM To: espressif/arduino-esp32 arduino-esp32@noreply.github.com Cc: Waterton, Nick (GE Healthcare) Nick.Waterton@med.ge.com; Mention mention@noreply.github.com Subject: EXT: Re: [espressif/arduino-esp32] SD lib w/ card 'flakey'? (#272)

@NickWatertonhttps://github.com/nickwaterton Are you referring to the SD card slot on the music maker wing? The VS1053 part works fine using the ESP32-Radiohttps://github.com/Edzelf/ESP32-Radio project.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/espressif/arduino-esp32/issues/272#issuecomment-313568665, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ALCUZwKnKGDB3NyiMQoukQd5gzT8SGGIks5sLZRUgaJpZM4MhlJK.

Unsubscribe from GE's commercial electronic messages: http://sc.ge.com/*casl-unsubscribe Désabonner des messages électroniques commerciaux de GE: http://sc.ge.com/*lcap-desabonnement

dstoiko commented 7 years ago

@me-no-dev will try asap. We are using these pins: MOSI -> 23 MISO -> 19 SCK -> 18 CS -> 5

me-no-dev commented 7 years ago

@dstoiko pins look good! You and @NickWaterton should have success if using the latest code.

ladyada commented 7 years ago

hiya! @dstoiko yah the default SD library worked for us, see it in https://github.com/adafruit/arduino-esp32/tree/d602169ebcd126c309009e87c1e455f2c892d08f @me-no-dev not sure about the touch screen, it does share SPI pins and also the touch chip is annoying in that it changes modes based on SPI floating voltages on bootup. ill take a look again soon!

me-no-dev commented 7 years ago

@ladyada it's possible that it was caused by the sd card stuff ;) have not seen if happen since SD is working.

ladyada commented 7 years ago

awesome :) you also have some fun hardware to try other stuff!

me-no-dev commented 7 years ago

@ladyada yeah! thanks for that! So far I have tried all but the servo shield and is working as expected :)

In our WROVER_KIT fork of the ILI driver, I have implemented direct drawing of bmp and jpeg files and buffers. Maybe you will like to add this for the ESP32 platform to your ILI driver as well?

ladyada commented 7 years ago

oh yah that would be awesome. if you can submit a PR and just make sure it still compiles for arduino. jpg decoding would be great and would probably work on other M4/high speed platforms!

me-no-dev commented 7 years ago

There are two ways to do this. ESP32 has the decoder in ROM, but the code footprint is also small. So either compile it only for ESP32 and use the functions in ROM, or also include the source for other compatible platforms. And I agree ;) definitely not an AVR territory :)

Edzelf commented 7 years ago

SD is working now correctly.

NickWaterton commented 7 years ago

Just wanted to say the SD card is working correctly on the Musicmaker feather now also.

dstoiko commented 7 years ago

Working more reliably now, mounting consistently all the time. I still get an error when running the SDCard test code : [W][sd_diskio.cpp:137] sdCommand(): no token received... Any ideas?

Also, in this example the functions that open files dont close() them. Is that normal behavior? I thought you needed to close the file after writing to it at least.

Full serial monitor output:

SD Card Type: SDHC
SD Card Size: 15193MB
Listing directory: /
  FILE: /mode.txt  SIZE: 2
  FILE: /profile.txt  SIZE: 2
  FILE: /._profile.txt  SIZE: 4096
  FILE: /165166M.CSV  SIZE: 33
  FILE: /165166T.CSV  SIZE: 43
  DIR : /.Spotlight-V100
  DIR : /.fseventsd
  FILE: /165166C.CSV  SIZE: 16
  FILE: /165166A.CSV  SIZE: 13
  DIR : /.Trashes
  DIR : /.TemporaryItems
  DIR : /mydir
  FILE: /test.txt  SIZE: 0
  FILE: /foo.txt  SIZE: 13
Creating Dir: /mydir
Dir created
Listing directory: /
  FILE: /mode.txt  SIZE: 2
  FILE: /profile.txt  SIZE: 2
  FILE: /._profile.txt  SIZE: 4096
  FILE: /165166M.CSV  SIZE: 33
  FILE: /165166T.CSV  SIZE: 43
  DIR : /.Spotlight-V100
  DIR : /.fseventsd
  FILE: /165166C.CSV  SIZE: 16
  FILE: /165166A.CSV  SIZE: 13
  DIR : /.Trashes
  DIR : /.TemporaryItems
  DIR : /mydir
  FILE: /test.txt  SIZE: 0
  FILE: /foo.txt  SIZE: 13
Removing Dir: /mydir
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
rmdir failed
Listing directory: /
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
Writing file: /hello.txt
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[E][vfs_api.cpp:265] VFSFileImpl(): fopen(/sd/hello.txt) failed
Write failed
Appending to file: /hello.txt
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[E][vfs_api.cpp:265] VFSFileImpl(): fopen(/sd/hello.txt) failed
Append failed
Reading file: /hello.txt
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[E][vfs_api.cpp:64] open(): /sd/hello.txt does not exist
Failed to open file for reading
Deleting file: /foo.txt
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[E][vfs_api.cpp:135] remove(): /foo.txt does not exists or is directory
Delete failed
Renaming file /hello.txt to /foo.txt
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[E][vfs_api.cpp:96] rename(): /hello.txt does not exists
Rename failed
Reading file: /foo.txt
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[E][vfs_api.cpp:64] open(): /sd/foo.txt does not exist
Failed to open file for reading
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[E][vfs_api.cpp:64] open(): /sd/test.txt does not exist
Failed to open file for reading
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[W][sd_diskio.cpp:137] sdCommand(): no token received
[E][vfs_api.cpp:265] VFSFileImpl(): fopen(/sd/test.txt) failed
1048576 bytes written for 0 ms
me-no-dev commented 7 years ago

Yes you need to close the file if you open it

dstoiko commented 7 years ago

@me-no-dev I was saying that because in the arduino-esp32 SD test example, file.close() is not used in the file manipulation functions readFile, writeFile and appendFile.

me-no-dev commented 7 years ago

@dstoiko must be error on my end :(

dstoiko commented 7 years ago

@me-no-dev made a tiny PR for that

me-no-dev commented 7 years ago

thank you @dstoiko merged :)

capedra commented 7 years ago

Wow, five months have been passed and the SD card problem persists now on MH-ET Live ESP32 Minikit.

me-no-dev commented 7 years ago

@capedra wow... that could be so many things... what is "MH-ET Live ESP32 Minikit" anyway? And how come I can mount all of my cards on all of my dev boards?