SDIO Interface

MickJagger
Posts: 8
Joined: Sat Nov 19, 2016 12:19 am

SDIO Interface

Postby MickJagger » Tue Jan 03, 2017 12:54 am

@i_grr has posted a photo with esp module and SD Cards. Any information SD Card handling (non spi mode)?

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

Re: SDIO Interface

Postby ESP_igrr » Tue Jan 03, 2017 3:29 am

Documentation has been written but needs some editing; SD card driver is complete and should land into master soon.

User avatar
rudi ;-)
Posts: 1698
Joined: Fri Nov 13, 2015 3:25 pm

Re: SDIO Interface

Postby rudi ;-) » Mon Jan 09, 2017 10:02 am

ESP_igrr wrote:.. should land into master soon.
well done! :mrgreen:

best wishes
rudi ;-)
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

sintech
Posts: 27
Joined: Wed Dec 14, 2016 2:54 pm

Re: SDIO Interface

Postby sintech » Mon Jan 09, 2017 9:04 pm

Just tried SDIO example, it works like a charm in 1BIT mode when using pins from SLOT_1: 2,14,15.

Code: Select all

rst:0x1 (POWERON_RESET),boot:0x1b (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:0x3fff0008,len:8
load:0x3fff0010,len:3384
load:0x40078000,len:7524
load:0x40080000,len:260
entry 0x40080034
I (43) boot: Espressif ESP32 2nd stage bootloader v. V0.1
I (44) boot: compile time 23:04:21
I (75) boot: Enabling RNG early entropy source...
I (76) boot: SPI Speed      : 40MHz
I (76) boot: SPI Mode       : DIO
I (87) boot: SPI Flash Size : 4MB
I (100) boot: Partition Table:
I (111) boot: ## Label            Usage          Type ST Offset   Length
I (134) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (157) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (180) boot:  2 factory          factory app      00 00 00010000 00100000
I (204) boot: End of partition table
I (217) boot: Disabling RNG early entropy source...
I (234) boot: Loading app partition at offset 00010000
I (658) boot: segment 0: paddr=0x00010018 vaddr=0x00000000 size=0x0ffe8 ( 65512)
I (659) boot: segment 1: paddr=0x00020008 vaddr=0x3f400010 size=0x067ec ( 26604) map
I (675) boot: segment 2: paddr=0x000267fc vaddr=0x3ffb0000 size=0x01b6c (  7020) load
I (704) boot: segment 3: paddr=0x00028370 vaddr=0x40080000 size=0x00400 (  1024) load
I (728) boot: segment 4: paddr=0x00028778 vaddr=0x40080400 size=0x13078 ( 77944) load
I (790) boot: segment 5: paddr=0x0003b7f8 vaddr=0x400c0000 size=0x00000 (     0) load
I (791) boot: segment 6: paddr=0x0003b800 vaddr=0x00000000 size=0x04808 ( 18440)
I (811) boot: segment 7: paddr=0x00040010 vaddr=0x400d0018 size=0x1cb48 (117576) map
I (837) boot: segment 8: paddr=0x0005cb60 vaddr=0x50000000 size=0x00008 (     8) load
I (865) heap_alloc_caps: Initializing. RAM available for dynamic allocation:
I (887) heap_alloc_caps: At 3FFB4AA0 len 0002B560 (173 KiB): DRAM
I (908) heap_alloc_caps: At 3FFE8000 len 00018000 (96 KiB): D/IRAM
I (929) heap_alloc_caps: At 40093478 len 0000CB88 (50 KiB): IRAM
I (950) cpu_start: Pro cpu up.
I (961) cpu_start: Single core mode
I (974) cpu_start: Pro cpu start user code
I (1207) phy: phy_version: 258, Nov 29 2016, 15:51:07, 0, 0
I (1356) cpu_start: Starting scheduler on PRO CPU.
I (1360) example: Initializing SD card
Name: SDC
Type: SDSC
Speed: default speed
Size: 244MB
CSD: ver=0, sector_size=512, capacity=499712 read_bl_len=9
SCR: sd_spec=0, bus_width=5
I (1380) example: Opening file
I (1400) example: File written
I (1410) example: Renaming file
I (1420) example: Reading file
I (1420) example: Read from file: 'Hello SDC  !'
I (1420) example: Card unmounted

But if I switch to a more convenient SLOT_0 pins using "host.slot= SDMMC_HOST_SLOT_0;" it leads to a crash (even if SD Card is not connected to ESP32):

Code: Select all

rst:0x3 (SW_RESET),boot:0x13 (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:0x3fff0008,len:8
load:0x3fff0010,len:3384
load:0x40078000,len:7524
load:0x40080000,len:260
entry 0x40080034
I (257) boot: Espressif ESP32 2nd stage bootloader v. V0.1
I (257) boot: compile time 23:04:21
I (289) boot: Enabling RNG early entropy source...
I (290) boot: SPI Speed      : 40MHz
I (290) boot: SPI Mode       : DIO
I (303) boot: SPI Flash Size : 4MB
I (315) boot: Partition Table:
I (327) boot: ## Label            Usage          Type ST Offset   Length
I (349) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (373) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (396) boot:  2 factory          factory app      00 00 00010000 00100000
I (419) boot: End of partition table
I (432) boot: Disabling RNG early entropy source...
I (449) boot: Loading app partition at offset 00010000
I (874) boot: segment 0: paddr=0x00010018 vaddr=0x00000000 size=0x0ffe8 ( 65512)
I (874) boot: segment 1: paddr=0x00020008 vaddr=0x3f400010 size=0x067ec ( 26604) map
I (890) boot: segment 2: paddr=0x000267fc vaddr=0x3ffb0000 size=0x01b6c (  7020) load
I (919) boot: segment 3: paddr=0x00028370 vaddr=0x40080000 size=0x00400 (  1024) load
I (943) boot: segment 4: paddr=0x00028778 vaddr=0x40080400 size=0x13078 ( 77944) load
I (1006) boot: segment 5: paddr=0x0003b7f8 vaddr=0x400c0000 size=0x00000 (     0) load
I (1007) boot: segment 6: paddr=0x0003b800 vaddr=0x00000000 size=0x04808 ( 18440)
I (1027) boot: segment 7: paddr=0x00040010 vaddr=0x400d0018 size=0x1cb48 (117576) map
I (1054) boot: segment 8: paddr=0x0005cb60 vaddr=0x50000000 size=0x00008 (     8) load
I (1081) heap_alloc_caps: Initializing. RAM available for dynamic allocation:
I (1104) heap_alloc_caps: At 3FFB4AA0 len 0002B560 (173 KiB): DRAM
I (1125) heap_alloc_caps: At 3FFE8000 len 00018000 (96 KiB): D/IRAM
I (1146) heap_alloc_caps: At 40093478 len 0000CB88 (50 KiB): IRAM
I (1167) cpu_start: Pro cpu up.
I (1179) cpu_start: Single core mode
I (1192) cpu_start: Pro cpu start user code
I (1429) phy: phy_version: 258, Nov 29 2016, 15:51:07, 0, 0
I (2466) cpu_start: Starting scheduler on PRO CPU.
I (2470) example: Initializing SD card
Guru Meditation Error of type IllegalInstruction occurred on core  0. Exception was unhandled.
Register dump:
PC      : 0x400e7902  PS      : 0x00060230  A0      : 0x800e8728  A1      : 0x3ffb6810
A2      : 0x00000000  A3      : 0x3f4054bc  A4      : 0xffffffff  A5      : 0xffffffff
A6      : 0xffffffff  A7      : 0x3ffb6b60  A8      : 0x3ff49060  A9      : 0x00000c00
A10     : 0x800e1727  A11     : 0xffff8fff  A12     : 0x00000200  A13     : 0xffffffff
A14     : 0x00003f00  A15     : 0x00000002  SAR     : 0x00000014  EXCCAUSE: 0x00000000
EXCVADDR: 0x00000000  LBEG    : 0x4000c2e0  LEND    : 0x4000c2f6  LCOUNT  : 0x00000000

Backtrace: 0x400e7902:0x3ffb6810 0x400e8728:0x3ffb6830 0x400e682f:0x3ffb6870 0x400d09c9:0x3ffb6950

Rebooting...
ets Jun  8 2016 00:22:57
Framework is updated to the latest trunk.

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

Re: SDIO Interface

Postby WiFive » Tue Jan 10, 2017 1:04 am

slot0 = HS1 so possible conflict with spi flash. It was mentioned first version of the driver wouldn't work on hs1 in parallel with spi flash.

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

Re: SDIO Interface

Postby ESP_igrr » Tue Jan 10, 2017 6:15 am

Indeed, WiFive is correct. If you have an SPI flash chip connected to the standard pins, there will be a conflict between SDIO master and SPI0 peripheral. If you want to use SDIO master on HS0 slot, you need to move SPI flash chip to a different set of pins (this is possible by programming Efuses).

sintech
Posts: 27
Joined: Wed Dec 14, 2016 2:54 pm

Re: SDIO Interface

Postby sintech » Tue Jan 10, 2017 7:44 am

WiFive and ESP_igrr thanks for clarification. It was mine lack of attention to details. Schematics of ESP-WROOM-32 module (which I have) set thing straight.

Looking forward for SPI support in SDMMC driver because:
a. Currently we can't use JTAG and SD at the same time on HS2_* signals (if I understand correctly)
b. It allow us to use the same SPI pins as for module internal flash + 1 pin for CS.

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: SDIO Interface

Postby ESP_Sprite » Wed Jan 11, 2017 1:34 am

For A, it should actually be possible to move JTAG pins to other GPIOs after app startup; JTAG pins are in the GPIO mux like most other peripheral signals.

novalight
Posts: 40
Joined: Tue Apr 19, 2016 1:13 pm

Re: SDIO Interface

Postby novalight » Thu Jan 12, 2017 1:51 pm

I've tested the code example and for me it only worked in 1-Line-Mode (on the breadboard with Nano32-Board).
I omitted IO_2 and IO_12 Pullups and activated them in software.

For the 1-Wire code I get:

Code: Select all

I (1649) example: Initializing pull-ups
I (1649) cpu_start: Starting scheduler on APP CPU.
I (2649) example: Initializing SD host
I (2649) example: Initializing SD slot
I (2649) example: Try mount sd card
Name: 00000
Type: SDHC/SDXC
Speed: default speed
Size: 15279MB
CSD: ver=1, sector_size=512, capacity=31291392 read_bl_len=9
SCR: sd_spec=2, bus_width=5
I (2669) example: Opening file
I (2709) example: File written
I (2739) example: Renaming file
I (2739) example: Reading file
I (2739) example: Read from file: 'Hello 00000!'
I (2739) example: Card unmounted
In 4-Wire mode:

Code: Select all

I (2487) example: Initializing pull-ups
I (2487) cpu_start: Starting scheduler on APP CPU.
I (3487) example: Initializing SD host
I (3487) example: Initializing SD slot
I (3487) example: Try mount sd card
E (3507) sdmmc_cmd: sdmmc_read_sectors: sdmmc_send_cmd returned 0x109
E (3507) ff_diskio: sdmmc_read_blocks failed (265)
W (3507) vfs_fat_sdmmc: failed to mount card (1)
E (3517) example: Failed to mount filesystem. If you want the card to be formatted, set format_if_mount_failed = true.
I've added slight modifications to the code (just a few logs and the pullup init stuff):

Code: Select all

void app_main(void)
{
    ESP_LOGI(TAG, "Initializing pull-ups");
    vTaskDelay(1000 / portTICK_PERIOD_MS);

    ESP_ERROR_CHECK(gpio_pulldown_dis(GPIO_NUM_2));
    ESP_ERROR_CHECK(gpio_pullup_en(GPIO_NUM_2));

    ESP_ERROR_CHECK(gpio_pulldown_dis(GPIO_NUM_12));
    ESP_ERROR_CHECK(gpio_pullup_en(GPIO_NUM_12));

    ESP_LOGI(TAG, "Initializing SD host");


    
    sdmmc_host_t host = SDMMC_HOST_DEFAULT();

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

    // This initializes the slot without card detect (CD) and write protect (WP) signals.
    // Modify slot_config.gpio_cd and slot_config.gpio_wp if your board has these signals.
    ESP_LOGI(TAG, "Initializing SD slot");
    sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();

    // Options for mounting the filesystem.
    // If format_if_mount_failed is set to true, SD card will be partitioned and formatted
    // in case when mounting fails.
    esp_vfs_fat_sdmmc_mount_config_t mount_config = {
        .format_if_mount_failed = false,
        .max_files = 5
    };

    // Use settings defined above to initialize SD card and mount FAT filesystem.
    // Note: esp_vfs_fat_sdmmc_mount is an all-in-one convenience function.
    // Please check its source code and implement error recovery when developing
    // production applications.
    sdmmc_card_t* card;
    ESP_LOGI(TAG, "Try mount sd card");
    esp_err_t ret = esp_vfs_fat_sdmmc_mount("/sdcard", &host, &slot_config, &mount_config, &card);
    if (ret != ESP_OK) {
        if (ret == ESP_FAIL) {
            ESP_LOGE(TAG, "Failed to mount filesystem. If you want the card to be formatted, set format_if_mount_failed = true.");
        } else {
            ESP_LOGE(TAG, "Failed to initialize the card (%d). Make sure SD card lines have pull-up resistors in place.", ret);
        }
        return;
    }
(no changed code after that)

Does somebody have a clue what could have happened here? Or experienced the same thing?
On guess could be signalling issues on the breadboard, but I don't believe that's the case here since it worked in 1-Wire-Mode.

Espagnole
Posts: 10
Joined: Mon Dec 19, 2016 10:18 am

Re: SDIO Interface

Postby Espagnole » Thu Jan 12, 2017 2:52 pm

Mine doesnt start:
sdmmc_cmd: sdmmc_card_init: send_scr returned 0x109
sd_card: Failed to initialize the card (265). Make sure SD card lines have pull-up resistors in place.

I have no idea what do more. Connections are OK, resistors are also connected (even if not needed)
IO13 - SD_DATA3, IO2 - SD_DATA0, IO4 - SD_DATA1, IO2 - SD_DATA2 each pulled up by 47kOhm
IO15 - SD_CMD pulled up by 10kOhm, IO14 - SD_CLK

EDIT: When SD Card inserted, flashing impossible:
[...]
Configuring flash size...
A fatal error occurred: Timed out waiting for packet content
make: *** [flash] Error 2
And starts like:
rst:0x1 (POWERON_RESET),boot:0x33 (SPI_FAST_FLASH_BOOT)
flash read err, 1000
Falling back to built-in command interpreter.
OK
>ets Jun 8 2016 00:22:57

rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
flash read err, 1000
Falling back to built-in command interpreter.
OK
>ets Jun 8 2016 00:22:57

rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0x00
Only SD Card that I test this is 2GB SanDisk (China):
sd_card: csd
sd_card: csd_ver : 0
sd_card: mmc_ver : 0
sd_card: capacity : 3970048
sd_card: sector_size : 512
sd_card: cid
sd_card: manufacturer identification number mfg_id : 3
sd_card: oem_id : 21316
sd_card: name : SD02G

Who is online

Users browsing this forum: Majestic-12 [Bot] and 89 guests