Skip to content
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

TTGOV2 SD card support #1190

Closed
choopk opened this issue Mar 7, 2018 · 28 comments
Closed

TTGOV2 SD card support #1190

choopk opened this issue Mar 7, 2018 · 28 comments

Comments

@choopk
Copy link

choopk commented Mar 7, 2018

Has anyone manage to get the SD card library working with this (https://github.com/LilyGO/TTGO-LORA32-V2.0) board. Or is there any other library that you guys can recommend.

@choopk choopk changed the title TTGOV2 TTGOV2 SD card support Mar 7, 2018
@JamesGKent
Copy link

looking at the pinout for that board:
https://github.com/LilyGO/TTGO-LORA32-V2.0

and comparing to an example sketch:
https://github.com/espressif/arduino-esp32/blob/master/libraries/SD_MMC/examples/SDMMC_Test/SDMMC_Test.ino

it looks like you need to use the SD_MMC library, give that a try?

@choopk
Copy link
Author

choopk commented Mar 9, 2018

Nope does not work

@JamesGKent
Copy link

when you say doesn't work, what does happen? there is more than one way that sketch might "not work"
we would need to know more about what you are using and what it does. what type of SD card are you using? SDHC? SDXC? how is it formatted etc?

@choopk
Copy link
Author

choopk commented Mar 9, 2018

It failed to mount. Im using a micro sd. SDHC formatted to fat32

@JamesGKent
Copy link

are you able to turn on extra logging?
the SD_MMC library doe have log messages in it to help us work out why it failed if you can turn them on.

@choopk
Copy link
Author

choopk commented Mar 9, 2018

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
flash read err, 1000
ets_main.c 371
ets Jun 8 2016 00:22:57

rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 188777542, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:956
load:0x40078000,len:0
load:0x40078000,len:13076
entry 0x40078a58
E (69) sdmmc_req: handle_idle_state_events unhandled: 00000004 00000000
E (70) sdmmc_cmd: sdmmc_card_init: send_op_cond (1) returned 0x107
Card Mount Failed

@JamesGKent
Copy link

i was looking more for error messages like this one:
"Failed to mount filesystem. If you want the card to be formatted, set format_if_mount_failed = true."
or this one:
"Failed to initialize the card (%d). Make sure SD card lines have pull-up resistors in place."

those error messages seem to come from the ESP IDF, and not in the arduino libraries.

@choopk
Copy link
Author

choopk commented Mar 9, 2018

I have not turn on extra logging. How am i suppose to enable it?

@JamesGKent
Copy link

it looks like that menu option is only available on the "ESP Dev Module" board option, but that board can be configured to match the options of other varients.
untitled

but if you set the flash mode, size and frequency to match your board, set the logging to a higher level such as debug or verbose and then recompile/upload and post the new output.

@choopk
Copy link
Author

choopk commented Mar 9, 2018

Failed to initialize the card (263). Make sure SD card lines have pull-up resistors in place.
Card Mount Failed

@JamesGKent
Copy link

JamesGKent commented Mar 9, 2018

sorry, not sure i can help you any further.
according to schematics there are already 10k pullups fitted to all the SD lines.

I don't know if 10k is the correct value though.

only thing i can suggest trying would be commenting out this line to try running at a slower speed?

@choopk
Copy link
Author

choopk commented Mar 9, 2018

Did that still giving the same error message. Thanks for the help though

@JamesGKent
Copy link

what about if you change it to a much lower speed?
eg SDMMC_FREQ_PROBING (400 instead of 20000 or 40000)

@JamesGKent
Copy link

alternatively try changing your begin call to:
begin("/sdcard", true);

@choopk
Copy link
Author

choopk commented Mar 9, 2018

still getting the same error.

@JamesGKent
Copy link

what about using the normal SD lib, but set up the SPI before passing it in. so this example

with the setup changed from:

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

to:

void setup(){
    Serial.begin(115200);
    SPI.begin(14, 2, 15);
    if(!SD.begin(13)){
        Serial.println("Card Mount Failed");
        return;
    }

@choopk
Copy link
Author

choopk commented Mar 9, 2018

@JamesGKent yup it worked flawlessly!! Thanks :D!

@choopk choopk closed this as completed Mar 9, 2018
@JamesGKent
Copy link

wow, that was a total shot in the dark...
btw just to clarify from my reading here SD cards can be used in 3 modes, one of which is SPI and the other two are SD specific. on AVRs the SPI mode is normally used because there is hardware built in for it, so it is faster that software emulating either of the other two modes. on the ESP it looks like we have the MMC hardware to use the other two modes natively.
I believe those other two modes (particularly the 4 bit mode) should be faster than SPI, however for you it seems that this didn't work.
when using the SD_MMC lib the 4 bit is the default unless the board definition says only 1 bit mode is available, so the default didn't work, my suggestion of using begin("/sdcard", true); should have activated 1 bit mode, which also didn't work. so my last suggestion using the normal SD lib is using SPI, but configuring the pins of the SPI interface onto the pins normally used by MMC.

@choopk
Copy link
Author

choopk commented Mar 9, 2018 via email

@beegee-tokyo
Copy link
Contributor

@JamesGKent I shared your finding in the Wiki. Thank you.

@JamesGKent
Copy link

@beegee-tokyo would it not be worth trying to add some explanation as to what the setup is doing?
personally i still think it would be worth trying to investigate why the MMC library doesn't work, but as i don't have one of these boards i am not able to do so.

@beegee-tokyo
Copy link
Contributor

@JamesGKent You are right, will add some more info to it. Don't have such a board either, so I cannot test anything.

@cyberman54
Copy link
Contributor

If i insert a FAT formatted SD card in the card reader slot of my TTGOv2 board, and restart it, it seems trying to boot from SD card:

rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
flash read err, 1000
ets_main.c 371
ets Jun  8 2016 00:22:57

Any hint how to avoid this and boot from internal flash?

@ricardo-samaniego
Copy link

For the record: this exact solution works also for the LilyGO ESP32 TTGO T4 V1.1 board.

You can see this board and the pins used for SD card connection here: https://github.com/LilyGO/ESP32-TTGO-T4

@nailsonlinux
Copy link

@JamesGKent Thanks a lot!

@mhaberler
Copy link

Have a look at https://github.com/espressif/esp-idf/tree/master/examples/storage/sd_card#note-about-gpio12

After having similar problems I followed the espefuse.py set_flash_voltage 3.3V suggestion and all problems went away.

I think this is a irreversible operation.

@kaminetzky
Copy link

@JamesGKent thank you very much! I'm now able to use an SD card on a TTGO LoRa32 V2.1 board. Cheers!

@jshank
Copy link

jshank commented Jun 2, 2020

If anyone else runs into this, the problem is that the pins_arduino.h header file has the wrong SPI pins for the TTGOV2 board (it has the V1 pins). You can either manually update your pins_arduion.h file or follow @JamesGKent recommendation in #1190 (comment) and manually initialize the SPI library with the correct pins. By default, the SD library will automatically call the SPI library with the pins (incorrectly) defined by the boards header file.

This has been reported in platformio/platform-espressif32#344

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants