Arduino SD_MMC example vs IDF SDMMC example (one works, one doesn't)

JeffWilliams
Posts: 17
Joined: Thu Mar 09, 2017 2:06 am

Arduino SD_MMC example vs IDF SDMMC example (one works, one doesn't)

Postby JeffWilliams » Sat Feb 10, 2018 3:56 pm

Hello,

I am trying to add some SD Card capabilities to a project and recently tried the example that comes with the IDF (update to date MASTER IDF). No matter what I did I couldn't get it to work.

Code: Select all

I (0) cpu_start: Starting scheduler on APP CPU.
I (259) example: Initializing SD card
I (259) example: Using SDMMC peripheral
I (259) gpio: GPIO[13]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
E (349) sdmmc_cmd: sdmmc_read_sectors_dma: sdmmc_send_cmd returned 0x109
E (349) diskio_sdmmc: sdmmc_read_blocks failed (265)
W (349) vfs_fat_sdmmc: failed to mount card (13)
E (349) example: Failed to mount filesystem. If you want the card to be formatted, set format_if_mount_failed = true.
I have pull-ups (they are on my SDCard breakout), I checked their resistance and configuration. Nothing seemed to help. I even adjusted the code to not use the ESP32 board pull-ups.

After my experience with my I2C BNO055 where the IDF i2c scanner fails to see it but an Arduino I2C Scanner code works fine I thought I would try the Arduino SD_MMC example. No change to board config, all I did was compile and flash.

The Arduino example works perfect. Which makes me think there is nothing wrong with the hardware side and I am missing something on the SW side. But I would expect the IDF example would be correct software wise. Not sure I want to dig through all the Arduino code to find the difference. Therefore I have adjusted my project to use Arduino as a component (since WIRE and SD_MMC work for some of my modules) though I am still interested that the IDF SD card example (basically the reference implementation) fails. I would actually prefer to just use the IDF without additional Arduino component if possible.

Jeff

JeffWilliams
Posts: 17
Joined: Thu Mar 09, 2017 2:06 am

Re: Arduino SD_MMC example vs IDF SDMMC example (one works, one doesn't)

Postby JeffWilliams » Sat Feb 10, 2018 10:04 pm

Seems I got the IDF version of the code working. How? I changed the card brand and type. My initial tests were with a SanDisk Ultra 32GB card. It formated using Windows SD Formater utility and ran under Windows, Android phone etc fine. I could create files using Arduino.

I had thought maybe it was the card so did swap it with another but all my cards are the same SanDisk Ultra items.

While was out today got a lower class Kingston 16GB and IDF code worked first time.

Jeff

JeffWilliams
Posts: 17
Joined: Thu Mar 09, 2017 2:06 am

Re: Arduino SD_MMC example vs IDF SDMMC example (one works, one doesn't)

Postby JeffWilliams » Mon Feb 19, 2018 3:42 am

Here I am replying to my own post again. So even the new card I got to work for 1 set of tests is no longer working. I have moved to just using the IDF unit test app to test. I have 3 SD Cards and 2 different SDCard slots connected.

Probe for 4-bit and 1-bit work fine and get card details correctly:

Code: Select all

 Running can probe SD (4-bit)...
I (80747) gpio: GPIO[13]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
Name: SD16G
Type: SDHC/SDXC
Speed: default speed
Size: 14916MB
CSD: ver=1, sector_size=512, capacity=30547968 read_bl_len=9
SCR: sd_spec=2, bus_width=5
C:/dev/esp-idf/components/sdmmc/test/test_sd.c:39:can probe SD (4-bit):PASS
Test ran in 92ms
Maybe 1 out of 20 tries the"can write and read back blocks" [sd][test_env=UT_T1_SDMODE][ignore] unit test works and passed. Sometimes it fails right away, sometimes it fails after a few blocks.

Code: Select all

Running can write and read back blocks...
I (232516) gpio: GPIO[13]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
Name: SD16G
Type: SDHC/SDXC
Speed: high speed
Size: 14916MB
CSD: ver=1, sector_size=512, capacity=30547968 read_bl_len=9
SCR: sd_spec=2, bus_width=5
  sector  | count | align | size(kB)  | wr_time(ms) | wr_speed(MB/s)  |  rd_time(ms)  | rd_speed(MB/s)
        0 |    1  |   4   |     0.5   |     3.07    |       0.16      |      0.85     |      0.58
        0 |    4  |   4   |     2.0   |     9.70    |       0.20      |      0.95     |      2.07
        1 |   16  |   4   |     8.0  E (232716) sdmmc_cmd: sdmmc_read_sectors_dma: sdmmc_send_cmd returned 0x107
C:/dev/esp-idf/components/sdmmc/test/test_sd.c:141:can write and read back blocks:FAIL: Expected 0x00000000 Was 0x00000107
MALLOC_CAP_8BIT critical leak: Before 295944 bytes free, After 286664 bytes free (delta 9280)
MALLOC_CAP_32BIT critical leak: Before 386872 bytes free, After 377592 bytes free (delta 9280)

Test ran in 242ms

-----------------------
1 Tests 1 Failures 0 Ignored 
FAIL
Sometimes it's a 0x107 fail result as above. Other times it's a 0x109:

Code: Select all

E (4824) sdmmc_cmd: sdmmc_card_init: send_scr (2) returned 0x109
Anyone have the SD Card functionality working reliably? Have any pointers?

Thanks, Jeff

bastian.h.jaeger
Posts: 5
Joined: Mon Jun 15, 2020 12:07 pm

Re: Arduino SD_MMC example vs IDF SDMMC example (one works, one doesn't)

Postby bastian.h.jaeger » Tue Nov 24, 2020 10:37 am

Hi Jeff,

I hope you still read this, even though the post is 2 years old.

I was happy reading the topic of this post, as I am facing the same issue. Arduino SDMMC example works perfect with 1 and 4 wires. But the esp-idf eample (lastes master branch from 2 days) fails with 4 wire. The one wire way

Code: Select all

slot_config.width = 1;
works.

Did you solve this somehow?

Who is online

Users browsing this forum: No registered users and 113 guests