More SDCARD issues
Posted: 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:
This is with git master branch of ESP-IDF, and standard ESP IDF SDCARD example.
Any ideas?
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.
Any ideas?