And again someone who has problems with esp32 and sd cards

Staubgeborener
Posts: 20
Joined: Sat Jul 22, 2017 11:59 am

And again someone who has problems with esp32 and sd cards

Postby Staubgeborener » Mon Jul 31, 2017 9:16 pm

I know, there are a lot of thread about using sd cards with the esp32, but no one of those could help me. Also i found here some circuits, for example from Rudi.
I have this problem since i work with the esp32 and after months its still not working. Not in 1 bit mode and not in 4 bit mode.

First: Here are thee prictures of my setup. The first one is a real picture to show my actual wiring. Second one is what i think i have done. And the last one is not a beauty, but shows nearly exactly my actual circuit.
I use this board.

Lets get started: When i try to flash the SD card and FAT filesystem example i'll get
A fatal error occurred: Failed to connect to ESP32: Timed out waiting for packet header
By unplugging VCC from my breadboard (for example at line 23, so pull ups and also sd card has no voltage) i'll get
E (1934) sdmmc_cmd: sdmmc_card_init: send_op_cond (1) returned 0x107
E (1934) example: Failed to initialize the card (263). Make sure SD card lines have pull-up resistors in place.
By unplugging IO12 or the pull up resistor befor IO12 (respectivly DAT2) the internal blue led of my esp32 is glowing. Error message is
A fatal error occurred: Failed to connect to ESP32: Timed out waiting for packet header

I think my circuit is wrong or it has something to do with GPIO12. Don't know if i should just do

Code: Select all

gpio_pullup_en(GPIO_NUM_12); 
but i don't know what kind of board this exactly is:
For boards which don't use the internal regulator (VDD_SDIO) to power the flash, GPIO12 can be pulled high.
For boards which use 1.8V flash chip, GPIO12 needs to be pulled high at reset. This is fully compatible with SD card operation.
On boards which use the internal regulator and a 3.3V flash chip, GPIO12 must be low at reset. This is incompatible with SD card operation.

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: And again someone who has problems with esp32 and sd cards

Postby WiFive » Mon Jul 31, 2017 10:36 pm

On boards which use the internal regulator and a 3.3V flash chip, GPIO12 must be low at reset. This is incompatible with SD card operation.
This applies to boards using wroom-32 module like yours.

If you solder your own breakout adapter many things can go wrong.

Doit onboard led may interfere with SD signals.

User avatar
loboris
Posts: 514
Joined: Wed Dec 21, 2016 7:40 pm

Re: And again someone who has problems with esp32 and sd cards

Postby loboris » Mon Jul 31, 2017 11:09 pm

The problem with such a setup occurs only when when flashing with sd card attached.
Simply remove your sd card from socket, flash ESP32 (I recommend to configure to stay in bootloader after flash). Insert your sd card, run make monitor (it will reset esp32) and sd card should be detected.
I've used sd card on various esp32 boards in all modes (1-line, 4-line, SPI) for months.
The only "problem" I've ever had was that some SDHC/SDXC cannot operate in 1-line mode (but they do operate in 4-line and SPI modes).

Use ESP-WROVER-KIT schematics as reference for connecting sd card, it works without any problems (ESD protection diodes are not realy necessary, you can go without them).

Staubgeborener
Posts: 20
Joined: Sat Jul 22, 2017 11:59 am

Re: And again someone who has problems with esp32 and sd cards

Postby Staubgeborener » Mon Jul 31, 2017 11:30 pm

loboris wrote:The problem with such a setup occurs only when when flashing with sd card attached.
Simply remove your sd card from socket, flash ESP32 (I recommend to configure to stay in bootloader after flash). Insert your sd card, run make monitor (it will reset esp32) and sd card should be detected.
I've used sd card on various esp32 boards in all modes (1-line, 4-line, SPI) for months.
The only "problem" I've ever had was that some SDHC/SDXC cannot operate in 1-line mode (but they do operate in 4-line and SPI modes).

Use ESP-WROVER-KIT schematics as reference for connecting sd card, it works without any problems (ESD protection diodes are not realy necessary, you can go without them).
Ok, i tried this. Just remove the sd card, flashed the ESP32, now my serial monitor show me the "failure at initialization sd card" (still ok), i put back my sd card adapter and now i use 'make monitor' and all i get is this message i a permament loop:
rst:0x10 (RTCWDT_RTC_RESET),boot:0x37 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0x00
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff3029,len:1077942344
ets Jun 8 2016 00:22:57
even with 'gpio_pullup_en(GPIO_NUM_12);' in my code.
WiFive wrote:
On boards which use the internal regulator and a 3.3V flash chip, GPIO12 must be low at reset. This is incompatible with SD card operation.
This applies to boards using wroom-32 module like yours.

If you solder your own breakout adapter many things can go wrong.

Doit onboard led may interfere with SD signals.
I tried 'gpio_pullup_en(GPIO_NUM_12);' (see above), still no success. Now i want to try

Code: Select all

components/esptool_py/esptool/espefuse.py set_flash_voltage 3.3V
(respectively 'python espefuse.py --port COM3 set_flash_voltage 3.3V') but nothing happened:

Code: Select all

$ python espefuse.py --port COM3 set_flash_voltage 3.3V
espefuse.py v2.1-beta1
Connecting........_
thats it, with a blinking _

Maybe because it's v2.1? If so: Can someone link me an older version of espefuse.py?


The SD card adapter shouldn't be the problem. I tried the SD Card example in Arduino IDE successfully with this adapter.

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: And again someone who has problems with esp32 and sd cards

Postby WiFive » Tue Aug 01, 2017 2:47 am

So what has worked for you in arduino? Was it spi mode, 1-bit sdio, 4-bit sdio? The fact that spi mode works does not show that all the pins on the adapter are OK or that the onboard led is not interfering.

Staubgeborener
Posts: 20
Joined: Sat Jul 22, 2017 11:59 am

Re: And again someone who has problems with esp32 and sd cards

Postby Staubgeborener » Tue Aug 01, 2017 6:20 am

WiFive wrote:So what has worked for you in arduino? Was it spi mode, 1-bit sdio, 4-bit sdio? The fact that spi mode works does not show that all the pins on the adapter are OK or that the onboard led is not interfering.
This worked. This is my third solid sd card adapter and i had this problem all the time. I coul solid a fourth adapter, but i don't think this would help. I could also try another esp. But I think the best point is to set the flash voltage to 3.3V.

User avatar
loboris
Posts: 514
Joined: Wed Dec 21, 2016 7:40 pm

Re: And again someone who has problems with esp32 and sd cards

Postby loboris » Tue Aug 01, 2017 7:14 am

You must use espefuse.py set_flash_voltage 3.3V without sdcard inserted, the same as for flashing...
Have you tried the SPI mode? You have to use the latest master branch of esp-idf. You can use the same wiring that worked on arduino, the new SD Card example has all the instruction needed, just set the pins you are using...

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: And again someone who has problems with esp32 and sd cards

Postby WiFive » Tue Aug 01, 2017 8:42 am

loboris wrote:The only "problem" I've ever had was that some SDHC/SDXC cannot operate in 1-line mode (but they do operate in 4-line and SPI modes).
Isn't it a requirement of SD standard? Could be handshake problem?

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

Re: And again someone who has problems with esp32 and sd cards

Postby ESP_igrr » Tue Aug 01, 2017 10:14 am

WiFive wrote:
loboris wrote:The only "problem" I've ever had was that some SDHC/SDXC cannot operate in 1-line mode (but they do operate in 4-line and SPI modes).
Isn't it a requirement of SD standard? Could be handshake problem?
That is super weird indeed, given that the card is intialized in 1-line mode first, and then it is switched into 4-line mode.


Staubgeborener: I think you are having three distinct issues... all but one are mentioned in SD card example readme.

1. You can not get the chip into download mode when using an SD card. This is mentioned in "note about GPIO2" section of readme. The reason for this issue is that GPIO2 acts both as one of SD card pins, and as a bootstrapping pin. To enter flash download mode, this pin must be low. However to be used with an SD card, this pin must have a pullup resistor. You can do either of two things:
a) manually connect GPIO2 to ground before flashing. Once flashing starts, you may disconnect it from ground.
b) bridge GPIO2 and GPIO0. GPIO0 will be pulled low by programming circuit. If you connect GPIO2 to GPIO0, then GPIO2 will also be pulled low by programming circuit, allowing the chip to enter flash download mode.

2. Upon reset, the chip doesn't run the program and boot loops. This is mentioned in "note about GPIO12" section of readme. The reason is that GPIO12 acts as both as one of SD card pins, and a bootstrapping pin. The level of this pin at reset tells ESP32 what supply voltage of the flash chip you want to use (1.8 if high, 3.3 if low). Your module uses 3.3V flash, so this pin must be low at reset. However for SD card to work correctly, you need this pin to be pulled up high. To work around this conflict, follow the suggestion given in the readme: use espefuse.py tool and program the flash voltage efuse of the chip for 3.3V.

3. You get card initialization errors even with all the resistors in place. The fact that you are using a breadboard to connect everything may be the issue here. Consider changing initialization of sdmmc driver as follows:

Code: Select all

    sdmmc_host_t config = SDMMC_HOST_DEFAULT();
    config.max_freq_khz = SDMMC_FREQ_PROBING; // << add this line
This will lower the clock frequency used by SDMMC driver. Default frequency is 20MHz, which may be too high for a circuit wired up on a breadboard.

Staubgeborener
Posts: 20
Joined: Sat Jul 22, 2017 11:59 am

Re: And again someone who has problems with esp32 and sd cards

Postby Staubgeborener » Tue Aug 01, 2017 11:57 am

loboris wrote:You must use espefuse.py set_flash_voltage 3.3V without sdcard inserted, the same as for flashing...
Have you tried the SPI mode? You have to use the latest master branch of esp-idf. You can use the same wiring that worked on arduino, the new SD Card example has all the instruction needed, just set the pins you are using...
I tried to set the flash voltage and also the flashing itself without sd card connected (nothing was connected to the ESP32).
Tried today SPI, its also not working.

When i flash the ESP (without! SD Card) i'll get
E (237) sdmmc_req: handle_idle_state_events unhandled: 00000004 00000000
E (237) sdmmc_cmd: sdmmc_card_init: send_op_cond (1) returned 0x107
E (237) example: Failed to initialize the card (263). Make sure SD card lines have pull-up resistors in place.
when i plug in the sd card adapter and type 'make monitor' i'll get
E (417) sdmmc_cmd: sdmmc_card_init: send_scr returned 0x109
E (417) example: Failed to initialize the card (265). Make sure SD card lines have pull-up resistors in place.
It's the same with 4-bit, 1-bit and SPI. I also soldered a new sd card adapter to test everything, but the issues are still the same.

I can't do ' set_flash_voltage 3.3V', when i type (without! SD Card) ' python components/esptool_py/esptool/espefuse.py --port COM3 set_flash_voltage 3.3V' i'll get
$ python components/esptool_py/esptool/espefuse.py --port COM3 set_flash_voltage 3.3V
espefuse.py v2.1-beta1
Connecting........_____....._
and thats it.

Does have 'set_flash_voltage 3.3V' and 'gpio_pullup_en(GPIO_NUM_12);' the same effect?


ESP_igrr wrote:1. and 3.
I wrote my problem two week ago on github.
negativekelvin wrote:If you can program your board the auto reset circuit is working fine, you don't need to worry about gpio 0 and 2.
So i wired now everything together for 4-line mode. IO2 is connected to GND. I start the flashing and when it begins, i unplugged IO2 from GND and connected IO2 to D0 of the sd card adapter.
Still it's

Code: Select all

E (417) sdmmc_cmd: sdmmc_card_init: send_scr returned 0x109
E (417) example: Failed to initialize the card (265). Make sure SD card lines have pull-up resistors in place.
I added
sdmmc_host_t config = SDMMC_HOST_DEFAULT();
config.max_freq_khz = SDMMC_FREQ_PROBING; // << add this line
to my code. 'sdmmc_host_t config = SDMMC_HOST_DEFAULT();' is also new in my sd card example (newest with SPI support)), so it looks now like this
Image
But i get
warning: variable 'config' set but not used [-Wunused-but-set-variable]
sdmmc_host_t config = SDMMC_HOST_DEFAULT();
But config is just a reference to SDMMC_HOST_DEFAULT(), so 'host.max_freq_khz = SDMMC_FREQ_PROBING;' should also work, or not?

ESP_igrr wrote:2.
See above. I can't do
set_flash_voltage 3.3V
i don't know why, but it stucks here.


Edit: Ok, i wired IO0 to IO2. Now the blue led is glowing. I don't have a IO0 Pin on my board, so i had to do it this way.
Still no set flash voltage, but error message changed:
E (417) sdmmc_cmd: sdmmc_read_sectors: sdmmc_send_cmd returned 0x109
E (417) diskio_sdmmc: sdmmc_read_blocks failed (265)
W (417) vfs_fat_sdmmc: failed to mount card (1)
E (427) example: Failed to mount filesystem. If you want the card to be formatted, set format_if_mount_failed = true.
i set the flag to true, but thats no changing the message.

Tried another micro sd inside the sd card adapter:
E (247) diskio_sdmmc: sdmmc_read_blocks failed (263)
W (247) vfs_fat_sdmmc: failed to mount card (13)
W (247) vfs_fat_sdmmc: partitioning card
W (257) vfs_fat_sdmmc: formatting card
E (257) sdmmc_cmd: sdmmc_write_sectors: sdmmc_send_cmd returned 0x109
E (267) diskio_sdmmc: sdmmc_write_blocks failed (265)
E (267) example: Failed to mount filesystem. If you want the card to be formatted, set format_if_mount_failed = true.
Referencing to this post, 0x109 has something to do with the pull ups.


Next Edit: Okay, somethings happens here. My circuit is still like the one thats necessary for 4-line, but i changed the sd card

Code: Select all

example code to 1 line and add
     host.flags = SDMMC_HOST_FLAG_1BIT;
    host.max_freq_khz = SDMMC_FREQ_PROBING;
Now i'll get
Name: SS08G
Type: SDHC/SDXC
Speed: default speed
Size: 7583MB
CSD: ver=1, sector_size=512, capacity=15529984 read_bl_len=9
SCR: sd_spec=2, bus_width=5
I (287) example: Opening file
I (447) example: File written
I (537) example: Renaming file
I (557) example: Reading file
I (577) example: Read from file: 'Hello SS08G!'
I (577) example: Card unmounted
1-bit seems to work now. Next step, 4 bit. 1 bit even works now without ' host.max_freq_khz = SDMMC_FREQ_PROBING;'




Next and last Edit: Ok. I seriously don't know what i have done. This is my code. Set flash voltage still not works, but 'gpio_pullup_en(GPIO_NUM_12);' seems to work. Also wiring IO0 to IO2 works.
Adding

Code: Select all

    // host.flags = SDMMC_HOST_FLAG_1BIT;
    host.max_freq_khz = SDMMC_FREQ_PROBING;
is the rest of my solution. This works when uncommenting 1-line SD mode and in 4-line SD mode.
Last edited by Staubgeborener on Tue Aug 01, 2017 1:12 pm, edited 1 time in total.

Who is online

Users browsing this forum: Baidu [Spider] and 97 guests