More SDCARD issues

markwj
Posts: 90
Joined: Tue Mar 08, 2016 5:03 am

More SDCARD issues

Postby markwj » Thu Oct 12, 2017 3:34 pm

I'm struggling with SD card support. It was previously working fine on my board, but now seems unreliable and intermittently not working. Only 1 out of 4 SD CARDs I have works at all, and even that one tends to corrupt data randomly.

To try to diagnose things, I've breadboarded up the Espressif SD card example (https://github.com/espressif/esp-idf/tr ... ge/sd_card). I have an external SPI flash, so using DEVKIT-C, GPIO0 and GPIO2 are connected, and set_flash_voltage 3.3V to avoid GPIO12 issues. 10K pull-ups on all lines.

Sigrok logic analyser shows a CMD0, 10ms delay, another CMD0, 20ms delay, so the first stage init looks good.

Then, I get a repeating sequence of command/responses, each separated by 20ms. These are CMD8 reply R7, CMD55 reply R1, ACMD41 reply R3.

With debug logging on, I get:

Code: Select all

I (426) example: Initializing SD card
I (426) example: Using SDMMC peripheral
D (436) sdmmc_periph: peripheral version 5342270a, hardware config 03c44c83
V (446) intr_alloc: esp_intr_alloc_intrstatus (cpu 0): checking args
V (446) intr_alloc: esp_intr_alloc_intrstatus (cpu 0): Args okay. Resulting flags 0xE
D (456) intr_alloc: Connected src 37 to int 13 (cpu 0)
D (466) sdmmc_periph: slot=1 div=50 freq=400kHz
D (466) sdmmc_periph: slot=1 width=1
D (466) sdmmc_cmd: sdmmc_card_init
V (476) sdmmc_cmd: sending cmd slot=1 op=0 arg=0 flags=20 data=0x0 blklen=0 datalen=0
V (476) sdmmc_req: make_hw_cmd: opcode=0, rexp=0, crc=0
V (486) sdmmc_req: sdmmc_handle_event: evt 00000004 00000000
V (496) sdmmc_req: process_events: state=SENDING_CMD
V (496) sdmmc_req: process_events state=SENDING_CMD next_state=IDLE
V (506) sdmmc_req: process_events state=IDLE next_state=IDLE
V (506) sdmmc_cmd: cmd response 00000000 00000000 00000000 00000000 err=0x0 state=0
V (536) sdmmc_cmd: sending cmd slot=1 op=0 arg=0 flags=20 data=0x0 blklen=0 datalen=0
V (536) sdmmc_req: make_hw_cmd: opcode=0, rexp=0, crc=0
V (536) sdmmc_req: sdmmc_handle_event: evt 00000004 00000000
V (536) sdmmc_req: process_events: state=SENDING_CMD
V (546) sdmmc_req: process_events state=SENDING_CMD next_state=IDLE
V (546) sdmmc_req: process_events state=IDLE next_state=IDLE
V (556) sdmmc_cmd: cmd response 00000000 00000000 00000000 00000000 err=0x0 state=0
V (586) sdmmc_cmd: sending cmd slot=1 op=8 arg=1aa flags=1c30 data=0x0 blklen=0 datalen=0
V (586) sdmmc_req: make_hw_cmd: opcode=8, rexp=1, crc=1
V (586) sdmmc_req: sdmmc_handle_event: evt 00000004 00000000
V (586) sdmmc_req: process_events: state=SENDING_CMD
V (596) sdmmc_req: process_events state=SENDING_CMD next_state=IDLE
V (596) sdmmc_req: process_events state=IDLE next_state=IDLE
V (606) sdmmc_cmd: cmd response 000001aa 00000000 00000000 00000000 err=0x0 state=0
D (616) sdmmc_cmd: SDHC/SDXC card
V (616) sdmmc_cmd: sending cmd slot=1 op=55 arg=0 flags=1c00 data=0x0 blklen=0 datalen=0
V (626) sdmmc_req: make_hw_cmd: opcode=55, rexp=1, crc=1
V (636) sdmmc_req: sdmmc_handle_event: evt 00000004 00000000
V (636) sdmmc_req: process_events: state=SENDING_CMD
V (646) sdmmc_req: process_events state=SENDING_CMD next_state=IDLE
V (646) sdmmc_req: process_events state=IDLE next_state=IDLE
V (656) sdmmc_cmd: cmd response 00000120 00000000 00000000 00000000 err=0x0 state=0
V (666) sdmmc_cmd: sending cmd slot=1 op=41 arg=40ff8000 flags=1030 data=0x0 blklen=0 datalen=0
V (666) sdmmc_req: make_hw_cmd: opcode=41, rexp=1, crc=0
V (676) sdmmc_req: sdmmc_handle_event: evt 00000100 00000000
V (686) sdmmc_req: process_events: state=SENDING_CMD
D (686) sdmmc_req: process_command_response: error 0x107  (status=00000100)
D (696) sdmmc_req: process_command_response: error 0x107  (status=00000100)
V (696) sdmmc_req: process_events state=SENDING_CMD next_state=IDLE
V (706) sdmmc_req: process_events state=IDLE next_state=IDLE
V (716) sdmmc_cmd: cmd response 00000120 00000000 00000000 00000000 err=0x107 state=0
E (716) sdmmc_cmd: sdmmc_card_init: send_op_cond (1) returned 0x107
D (726) vfs_fat_sdmmc: sdmmc_card_init failed 0x(107)
V (736) intr_alloc: esp_intr_free: Disabling int, killing handler
E (736) example: Failed to initialize the card (263). Make sure SD card lines have pull-up resistors in place.
This is with git master branch of ESP-IDF, and standard ESP IDF SDCARD example.

Any ideas?
Attachments
Screen Shot 2017-10-12 at 11.21.56 PM.png
Screen Shot 2017-10-12 at 11.21.56 PM.png (1.12 MiB) Viewed 10207 times

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

Re: More SDCARD issues

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

Could you please show the closeup of the CLK/CMD trace where the last reply from the card happens? Interested to see how the CMD/CLK edges line up.

Another thing you could do for debugging is to toggle some GPIO in sdmmc driver when the timeout happens, e.g. here:
https://github.com/espressif/esp-idf/bl ... ost.c#L387
that would help see how the timeout lines up with the response.
If the timeout happens before response comes, then it means that sdmmc_host_wait_for_event is somehow broken; if the timeout happens after the response comes, it may be that the peripheral is not seeing the incoming data for some reason.

markwj
Posts: 90
Joined: Tue Mar 08, 2016 5:03 am

Re: More SDCARD issues

Postby markwj » Fri Oct 13, 2017 12:24 am

Here is the end of the ACMD41 / beginning of reply, and the full reply:
Screen Shot 2017-10-13 at 8.18.58 AM (2).png
Screen Shot 2017-10-13 at 8.18.58 AM (2).png (110.69 KiB) Viewed 10188 times
Screen Shot 2017-10-13 at 8.19.34 AM (2).png
Screen Shot 2017-10-13 at 8.19.34 AM (2).png (168.19 KiB) Viewed 10188 times

markwj
Posts: 90
Joined: Tue Mar 08, 2016 5:03 am

Re: More SDCARD issues

Postby markwj » Fri Oct 13, 2017 12:40 am

Here also is the reply R1 to the prior CMD55:
Screen Shot 2017-10-13 at 8.22.37 AM (2).png
Screen Shot 2017-10-13 at 8.22.37 AM (2).png (134.59 KiB) Viewed 10188 times
I only have very limited knowledge of the SD protocol. I did put a scope on the CMD and CLK lines, and the traces look clean. This part of the negotiation seems to be at 400Khz clock. The logic analyser (a Saleae style one) seems to be able to detect and decode the data just fine.

Strange thing is that this all seemed to work a few months ago; when we originally did the hardware design and tested it all ok. But, now we have circled back to actually try to use the SD CARD in earnest, it is failing. I can't get it to work with either master or 2.1 branches of IDF. I'm thinking about trying to roll back IDF three months, and seeing if there is any improvement.

My previous message on this forum was for the CMD55 R1 reply, but I think that is not the one you are looking for. Here are is the last reply (R3 for ACMD41):
Screen Shot 2017-10-13 at 8.36.50 AM (2).png
Screen Shot 2017-10-13 at 8.36.50 AM (2).png (149.69 KiB) Viewed 10188 times

markwj
Posts: 90
Joined: Tue Mar 08, 2016 5:03 am

Re: More SDCARD issues

Postby markwj » Fri Oct 13, 2017 12:43 am

And here is a close-up of the R3 reply with OCR register. Is that the expected reply?
(OCR seems to be 00000000 11111111 10000000 00000000)
Screen Shot 2017-10-13 at 8.37.29 AM (2).png
Screen Shot 2017-10-13 at 8.37.29 AM (2).png (136.94 KiB) Viewed 10188 times

markwj
Posts: 90
Joined: Tue Mar 08, 2016 5:03 am

Re: More SDCARD issues

Postby markwj » Wed Oct 18, 2017 5:15 am

I'm very stuck on this. The 0x109 status I am getting back is caused by a checksum status in the IRQ status register. I'm even seeing this on commands without any reply, which implies a transmit checksum issue? The checksums seen on the external logic analyser all look ok.

I've tried breadboarding the example sd card wiring, but get the same issues. I've also tried 4 different SD cards (with either 0x107 or 0x109 coming back in all cases).

The only difference in my setup is that I am using an external 16MB SPI flash, with fuses burned appropriately. I'm going to have to order some devkit modules, to see if that is the cause, as all I have have been modified for external flash already.

Any ideas?

martinr
Posts: 1
Joined: Thu Oct 26, 2017 2:22 pm

Re: More SDCARD issues

Postby martinr » Thu Oct 26, 2017 2:33 pm

Hi,

I've the same issue. When I try to read my SD Card in SPI mode

Code: Select all

V (1127) sdmmc_cmd: sending cmd slot=2 op=51 arg=0 flags=1c50 data=0x3ffb35cc blklen=8 datalen=8 timeout=1000
V (1137) sdspi_host: sdspi_host_start_command: slot=2, CMD51, arg=0x00000000 flags=0x5, data=0x3ffb35cc, data_size=8 crc=0x63
D (1147) sdspi_host: poll_data_token: received 0x01 while waiting for data
E (1157) sdspi_host: data CRC failed, got=0x8af4 expected=0xffff
I (1157) sdspi_host: 00 00 00 68 fe ff ff ff 1d 38 fb 3f 98 5f fb 3f
E (1167) sdspi_host: sdspi_host_start_command: cmd=51 error=0x109
D (1177) sdmmc_cmd: sdmmc_req_run returned 0x109
E (1177) sdmmc_cmd: sdmmc_card_init: send_scr (2) returned 0x109
D (1187) vfs_fat_sdmmc: sdmmc_card_init failed 0x(109)
E (1187) example: Failed to initialize the card (265). Make sure SD card lines have pull-up resistors in place.
When I flash the ESP from the arduino ide, it works with the same wiring from the arduino examples https://github.com/espressif/arduino-es ... braries/SD.

Regards Martin

markwj
Posts: 90
Joined: Tue Mar 08, 2016 5:03 am

Re: More SDCARD issues

Postby markwj » Tue Jan 09, 2018 5:21 am

Resolved for me in ESP IDF 3.0b1 (or later). The issue seems to have been fixed by Espressif within the last month or two.

Who is online

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