SD Card example not working

drances
Posts: 6
Joined: Wed Sep 27, 2017 4:32 pm

SD Card example not working

Postby drances » Wed Sep 27, 2017 5:05 pm

Hardware - https://www.olimex.com/Products/IoT/ESP32-WROVER-KIT/
esp-idf commit: a3a4a20

Using the sd_card example provided, I tried to get the board to read a SanDisk 2GB microSD card. I want to be able to use 4-line mode but have not had any success. I started with an ESP32 breakout and my own wiring to an sd card adapter, and had the same results. I went for the WROVER-KIT since I figured the official Espressif device would definitely have it wired up properly, but still no luck. What should I look for in terms of a direction to get 4-line mode working?

1-bit mode results
I (269) example: Initializing SD card
I (3269) example: Using SDMMC peripheral
E (3309) sdmmc_req: handle_idle_state_events unhandled: 00000004 00000000
E (3309) sdmmc_cmd: sdmmc_card_init: send_op_cond (1) returned 0x107
E (3309) example: Failed to initialize the card (263). Make sure SD card lines have pull-up resistors in place.


4-bit mode results
I (269) example: Initializing SD card
I (3269) example: Using SDMMC peripheral
E (3309) sdmmc_req: handle_idle_state_events unhandled: 00000004 00000000
E (3309) sdmmc_cmd: sdmmc_card_init: send_op_cond (1) returned 0x107
E (3309) example: Failed to initialize the card (263). Make sure SD card lines have pull-up resistors in place.


SPI mode results
I (270) example: Initializing SD card
I (3270) example: Using SPI peripheral
I (3270) gpio: GPIO[13]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulld
own: 0| Intr:0
Name: SU02G
Type: SDSC
Speed: default speed
Size: 1886MB
CSD: ver=0, sector_size=512, capacity=3862528 read_bl_len=10
SCR: sd_spec=2, bus_width=5
I (3440) example: Opening file
I (3460) example: File written
I (3460) example: Renaming file
I (3460) example: Reading file
I (3470) example: Read from file: 'Hello SU02G!'
I (3470) example: Card unmounted

ESP_igrr
Posts: 859
Joined: Tue Dec 01, 2015 8:37 am

Re: SD Card example not working

Postby ESP_igrr » Wed Sep 27, 2017 11:44 pm

SD mode should work on WROVER-KIT v2, if you have a jumper connected between IO2 and SD_IO2. Also check if you have JTAG jumpers disconnected, as JTAG uses some of the SD card pins, and SD card initialization may fail if JTAG probe is connected.

On WROVER-KIT v3 SD card example should work without extra jumpers required.

Can you please also try 1-line mode and see if that works, at least? That would rule out some issue causes.

drances
Posts: 6
Joined: Wed Sep 27, 2017 4:32 pm

Re: SD Card example not working

Postby drances » Thu Sep 28, 2017 3:42 pm

Thank you for the reply. Before I attempted again, I re-installed the toolchain and msys32 in case an error during my initial installation is causing some minor issue. I am also using the master branch for esp-idf, latest commit.

With the WROVER-KIT v3, I tried 1 line mode. I first tried by uncommenting the line

Code: Select all

host.flags = SDMMC_HOST_FLAG_1BIT;

and adding the line nuder slot_config

Code: Select all

sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
slot_config.width = 1;


Same exact output as my attempt at 4-line mode. SPI works just fine.

Could it be an issue with the SD card? I tried using some other cheaper 1GB sd card and the Sandisk 2GB, both FAT and empty (excluding the file written by the SPI_MODE example). From reading on forums and Github, it seems I'm the only one experiencing this issue on this particular board. Any other factors that could affect this problem? Other things I should check for? Any leads or suggestions are helpful, no matter how general. Thanks

drances
Posts: 6
Joined: Wed Sep 27, 2017 4:32 pm

Re: SD Card example not working

Postby drances » Thu Sep 28, 2017 5:34 pm

Thank you for that and to clarify - I am using kit v3. Before proceeding to test with 1-line, I re-installed the msys32 environment and toolchain just as it was written in the docs. I made sure to use the currently updated master branch for esp-idf.

I performed 2 tests, both with minor changes. The first is simply to run in 1-line mode by un-commenting the line

Code: Select all

// To use 1-line SD mode, uncomment the following line:
     host.flags = SDMMC_HOST_FLAG_1BIT;

The second, which was just me making sure that it was only in 1-line mode, was the following:

Code: Select all

// Modify slot_config.gpio_cd and slot_config.gpio_wp if your board has these signals.
    sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
    slot_config.width = 1;

Results are the same as that from 4-line mode. The only mode that works is SPI MODE

It shouldn't be a hardware issue since I am using the kit and everyone else has been successful in using the sd card. Are there any factors in the environment setup procedure that could be playing a role in this? Or something else? Any suggestion can help. Thanks

ESP_igrr
Posts: 859
Joined: Tue Dec 01, 2015 8:37 am

Re: SD Card example not working

Postby ESP_igrr » Thu Sep 28, 2017 11:11 pm

Could you please attach (or give a link to) your .bin file, I will try running it on a wrover-kit here. That would help determine whether this is a software or hardware issue.

drances
Posts: 6
Joined: Wed Sep 27, 2017 4:32 pm

Re: SD Card example not working

Postby drances » Mon Oct 02, 2017 1:58 pm


drances
Posts: 6
Joined: Wed Sep 27, 2017 4:32 pm

Re: SD Card example not working

Postby drances » Thu Oct 12, 2017 3:08 pm

Hi, have you gotten a chance to test it out?

ESP_igrr
Posts: 859
Joined: Tue Dec 01, 2015 8:37 am

Re: SD Card example not working

Postby ESP_igrr » Thu Oct 12, 2017 4:51 pm

I have tried your binary, sorry for not replying about that earlier. Interestingly, on one dev board this binary hangs at "Starting scheduler on PRO CPU" line and never proceeds further.

On another board it has the same behavior as you described! Observing the trace using logic analyzer reveals the issue:
Screen Shot 2017-10-13 at 00.46.35.png
Screen Shot 2017-10-13 at 00.46.35.png (49.68 KiB) Viewed 280 times


The SD card does reply, but it replies on the wrong line (D0 instead of CMD), which means that the card has been initialized in SPI mode instead of SD mode. The card goes into SPI mode after CMD0 in two cases:
1) if it was previously initialized in SPI mode,
2) if D3 line is low when CMD0 is received.
Since the issue happens even when the card has just been plugged in, it means that (2) is the case.

I have added the following lines to the SD card example and now it works fine on this particular board:

Code: Select all

    gpio_pulldown_dis(13);
    gpio_pullup_en(13);


Please try that, it may resolve the issue.

drances
Posts: 6
Joined: Wed Sep 27, 2017 4:32 pm

Re: SD Card example not working

Postby drances » Thu Oct 12, 2017 6:45 pm

It works! Thank you very much for all the help.

Wonder why it is that this problem isn't present in other situations...

Who is online

Users browsing this forum: No registered users and 1 guest