espressif / arduino-esp32

Arduino core for the ESP32
GNU Lesser General Public License v2.1
13.43k stars 7.37k forks source link

SD card issues with ESP32S3 in SDMMC mode #7373

Closed mtk11 closed 1 year ago

mtk11 commented 1 year ago

Board

Custom ESP32S3 board

Device Description

Custom board

Hardware Configuration

SDMMC_CMD 35 SDMMC_CLK 36 SDMMC_D0 37 SDMMC_D1 38 SDMMC_D2 39 SDMMC_D3 40

Version

v2.0.5

IDE Name

Arduino

Operating System

Windows 7

Flash frequency

80 MHz

PSRAM enabled

no

Upload speed

921600

Description

Errors appear.ed

Sketch

https://github.com/espressif/arduino-esp32/blob/master/libraries/SD_MMC/examples/SDMMC_Test/SDMMC_Test.ino

Pin config: SD_MMC.setPins(36, 35, 37, 38, 39, 40);

Debug Message

..... 
E (1237) sdmmc_req: sdmmc_host_wait_for_event returned 0x107
E (1237) diskio_sdmmc: Check status failed (0x107)
E (2238) sdmmc_req: sdmmc_host_wait_for_event returned 0x107
E (2238) diskio_sdmmc: Check status failed (0x107)
Writing file: /hello.txt
File written
Appending to file: /hello.txt
Message appended
Reading file: /hello.txt
Read from file: Hello World!
Deleting file: /foo.txt
File deleted
Renaming file /hello.txt to /foo.txt
File renamed
Reading file: /foo.txt
Read from file: Hello World!
1048576 bytes read for 198 ms
E (3491) sdmmc_req: handle_idle_state_events unhandled: 00000042 00000000
1048576 bytes written for 1413 ms
Total space: 1881MB
Used space: 21MB

With ESP3D 3.0 (https://github.com/luc-github/ESP3D/tree/3.0), getting the following:

E (61131) sdmmc_req: sdmmc_host_wait_for_event returned 0x107
E (61131) diskio_sdmmc: Check status failed (0x107)
E (62132) sdmmc_req: sdmmc_host_wait_for_event returned 0x107
E (62132) diskio_sdmmc: Check status failed (0x107)
E (78447) sdmmc_req: sdmmc_host_wait_for_event returned 0x107
E (78447) diskio_sdmmc: Check status failed (0x107)
E (80560) sdmmc_req: sdmmc_host_wait_for_event returned 0x107
E (80560) diskio_sdmmc: Check status failed (0x107)
E (81561) sdmmc_req: sdmmc_host_wait_for_event returned 0x107
E (81561) diskio_sdmmc: Check status failed (0x107)
E (82562) sdmmc_req: sdmmc_host_wait_for_event returned 0x107
E (82562) diskio_sdmmc: Check status failed (0x107)
E (82564) sdmmc_cmd: sdmmc_read_sectors_dma: sdmmc_send_cmd returned 0x109
E (82568) diskio_sdmmc: sdmmc_read_blocks failed (265)
E (82574) sdmmc_req: handle_idle_state_events unhandled: 00000008 00000002
E (83697) sdmmc_req: sdmmc_host_wait_for_event returned 0x107
E (83697) diskio_sdmmc: Check status failed (0x107)
E (84698) sdmmc_req: sdmmc_host_wait_for_event returned 0x107
E (84698) diskio_sdmmc: Check status failed (0x107)

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

me-no-dev commented 1 year ago

depending on the chip/module model, pins 35 to 37 might be in use by OPI flash/psram. Any chip/module that ends on R8 will be using OPI PSRAM and have those pins reserved.

mtk11 commented 1 year ago

@me-no-dev , The module does not have ext SPI RAM was N8R2, after changing it to N8 had no issues, except the slow speed.. Esp-idf’s SD Card example (SDMMC) works fine. Recently esp-idf had some updates - sdmmc/sdspi: allow custom setup of SD card frequency ? Do you intend to include them soon ?

me-no-dev commented 1 year ago

That fix will be part of ESP32 Arduino 3.0.0: https://github.com/espressif/arduino-esp32/issues/6225#issuecomment-1264289718

timknapen commented 1 year ago

Could this be related to [SDMMC] ESP32-S3-N8R8 fails to start a microSD card in SDMMC_FREQ_HIGHSPEED mode (IDFGH-6901)?

It looks like @igrr has a patch there, but I don't know if it's already included in Arduino-esp32

P-R-O-C-H-Y commented 1 year ago

@timknapen Can you please fix the link to the related issue? Thanks

timknapen commented 1 year ago

I'm sorry about that I don't know how that happened. Link should work now.

P-R-O-C-H-Y commented 1 year ago

@mtk11 @timknapen I was able to test SD_MMC on ESP32-S3-EYE board, which has SD_MMC 1-bit mode only available. When used default frequency (40 MHz), I was sometimes seeing errors:

E (4613) sdmmc_req: sdmmc_host_wait_for_event returned 0x107
E (4613) diskio_sdmmc: sdmmc_read_blocks failed (263)

When changed frequency to 20 MHz, all errors were gone. Can you try that? I have used the example sketch SD_MMC->SDMMC_Test with following changes:

#define SDMMC_CLK   39
#define SDMMC_CMD   38
#define SDMMC_D0    40  

void setup(){
    Serial.begin(115200);
    delay(2000);
    SD_MMC.setPins(39, 38, 40);
    if(!SD_MMC.begin("/sdcard", true, false, 20000, 5)){
        Serial.println("Card Mount Failed");
        return;
    }
   // the rest of setup() as in example
}
timknapen commented 1 year ago

Hi @P-R-O-C-H-Y , I only have a custom PCB with an ESP32-S3-WROOM-1 (N4R8) and I'm using 4 data lines, all short traces with 10K pull-ups. I've never had any issues using 20MHz. Everything works perfectly fine (but slowly) at 20Mhz. Only at 40MHz I start getting problems. Just like the ESP-IDF issue I referred to above.

mtk11 commented 1 year ago

@P-R-O-C-H-Y , ESP32-S3-EYE board uses ESP32-S3-WROOM-1-N8R8 (8MB PSRAM). I had experienced issue with N8R2 (2MB PSRAM) version and I replaced the module with N8 (no PSRAM) version. After the replacement I haven’t experienced the presented issues with the default config. ESP3D 3.0 also works fine, however the file upload speed via WiFi is still slow around 110-120 kB/s.

P-R-O-C-H-Y commented 1 year ago

@timknapen @mtk11 There is an investigation by ESP-IDF team. We can just wait, once the fix is released. I will inform you about any updates about this issue.

timknapen commented 1 year ago

@P-R-O-C-H-Y thank you! looking forward to have this solved! Side note: Is it possible for me to clone the Arduino-esp project and recompile the ESP-IDF in it myself? (to for example test the patch myself) I have looked but can't find documentation on how to do this.

P-R-O-C-H-Y commented 1 year ago

@timknapen You are welcome! Answer for the side note: Yes it is possible. You can use the esp32-arduino-lib-builder. Links to docs and repo.

HelloDB commented 1 year ago

该修复将成为 ESP32 Arduino 3.0.0 的一部分:#6225(评论)

Hello, when is the 3.0.0 release expected? If it takes too long, is it possible to pre-release a small fix for SDMMC speed issues.

VojtechBartoska commented 1 year ago

Hello @HelloDB, we don't have exact date for 3.0.0 as we recently started on it. This is on hold for 3.0.0 milestone.

0x0fe commented 1 year ago

Hello,is there a way to see the patch? there is some problems with sd_mmc driver, and switching to 20MHz (in 1-bit mode) does not solve them (write block error). Also on PIO it is particularly not working well. And finally i notice something concerning, allocating a large working buffer in PSRAM (64K) affects the sd_mmc driver, to the point it cannot intilize in many cases (dma errors).

P-R-O-C-H-Y commented 1 year ago

@timknapen @mtk11 Can you try to retest the issue with 40 MHz with the latest version 2.0.11 please? Thanks

timknapen commented 1 year ago

I just tested on two different PCBs with esp32-s3. 40.000 is still buggy. But I don't think I'm running latest 2.0.11... When I compile it says PACKAGES: - framework-arduinoespressif32 @ 3.20009.0 (2.0.9) And when I edit platformio.ini to include

platform = https://github.com/platformio/platform-espressif32.git   
framework = arduino   
platform_packages = framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32#master   

as documented here: https://docs.espressif.com/projects/arduino-esp32/en/latest/installing.html#how-to-update-to-the-latest-code

I get PACKAGES: - framework-arduinoespressif32 @ 2.0.6+sha.099b432

I'm confused. Both 2.0.9 and 2.0.6+sha... give me read errors like these at 40.000

E (499) sdmmc_cmd: sdmmc_read_sectors_dma: sdmmc_send_cmd returned 0x109   
E (500) diskio_sdmmc: sdmmc_read_blocks failed (265)   
E (500) sdmmc_req: handle_idle_state_events unhandled: 00000000 00000002   
P-R-O-C-H-Y commented 1 year ago

@timknapen Thanks for trying, but it needs to be the latest version based on ESP-IDF 4.4.5. I am not familiar with PlatformIO so I'm not able to help you with updating it. @Jason2866 Can you please help how to use the latest 2.0.11 version? Thank you

Jason2866 commented 1 year ago

Try this

platform = https://github.com/platformio/platform-espressif32.git
platform_packages = framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git
timknapen commented 1 year ago

@P-R-O-C-H-Y Thanks for the hint! I assumed platformio would automatically be able to grab the latest version of the arduino-esp32 package from Github, but that does not seem to be the case..

@Jason2866 Thank you for the suggestion but I still get the same results with platformio: (using your suggestion or my previous settings)

PLATFORM: Espressif 32 (6.3.2+sha.f1fdbc5)
HARDWARE: ESP32S3 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, esp-builtin, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES: 
- framework-arduinoespressif32 @ 2.0.6+sha.099b432 
- tool-esptoolpy @ 1.40501.0 (4.5.1) 
- toolchain-riscv32-esp @ 8.4.0+2021r2-patch5 
- toolchain-xtensa-esp32s3 @ 8.4.0+2021r2-patch5

This looks like it's using version 2.0.6 ( I don't know what the sha.099b432 means) It doesn't look like esp IDF version is mentioned during compile.

When I just compile with my 'normal' settings, it uses 2.0.9!

// normal settings:
platform = espressif32 
framework = arduino

gives this:

PLATFORM: Espressif 32 (6.3.2)
HARDWARE: ESP32S3 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, esp-builtin, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES: 
 - framework-arduinoespressif32 @ 3.20009.0 (2.0.9) 
 - tool-esptoolpy @ 1.40501.0 (4.5.1) 
 - toolchain-riscv32-esp @ 8.4.0+2021r2-patch5 
 - toolchain-xtensa-esp32s3 @ 8.4.0+2021r2-patch5
mikaeltulldahl commented 1 year ago

@timknapen Here's how I specify specific version of framework-arduinoespressif32:

platform = espressif32
platform_packages = framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#2.0.11
board = esp32-s3-devkitc-1
framework = arduino

gives this:

CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32-s3-devkitc-1.html
PLATFORM: Espressif 32 (6.3.2) > Espressif ESP32-S3-DevKitC-1-N8 (8 MB QD, No PSRAM)
HARDWARE: ESP32S3 240MHz, 320KB RAM, 8MB Flash
DEBUG: Current (esp-builtin) On-board (esp-builtin) External (cmsis-dap, esp-bridge, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES: 
 - framework-arduinoespressif32 @ 2.0.11+sha.ae9dae4 
 - tool-esptoolpy @ 1.40501.0 (4.5.1) 
 - tool-openocd-esp32 @ 2.1100.20220706 (11.0) 
 - toolchain-riscv32-esp @ 8.4.0+2021r2-patch5 
 - toolchain-xtensa-esp32s3 @ 8.4.0+2021r2-patch5

It picks the correct tag (2.0.11) and commit (ae9dae4)

P-R-O-C-H-Y commented 1 year ago

Thanks @mikaeltulldahl. @timknapen can you give it another try please?

timknapen commented 1 year ago

Thank you @mikaeltulldahl !! That does indeed get me to compile with 2.0.11 output:

PLATFORM: Espressif 32 (6.3.2+sha.f1fdbc5)
HARDWARE: ESP32S3 240MHz, 320KB RAM, 4MB Flash
PACKAGES: 
 - framework-arduinoespressif32 @ 2.0.11+sha.ae9dae4 
 - tool-esptoolpy @ 1.40501.0 (4.5.1) 
 - toolchain-riscv32-esp @ 8.4.0+2021r2-patch5 
 - toolchain-xtensa-esp32s3 @ 8.4.0+2021r2-patch5

Looks good! Testing on my hardware right now!

timknapen commented 1 year ago

Thank you @P-R-O-C-H-Y , @mikaeltulldahl and @Jason2866 Just tested with one of my ESP32-S3-WROOM-1 (N4R8) based prototypes and I can confirm 2.0.11 works much better at 40Mhz. I have another board here that I can test later too. I have done a bunch of file reads and listing of files from microSD and haven't seen one error so far! This looks very promising!

One weird thing: the read speed is barely faster than at 40Mhz compared to 20Mhz. Does anyone see this too? I'll have to investigate further.

P-R-O-C-H-Y commented 1 year ago

@timknapen Thank you very much for testing. Good to hear that the errors are gone now, so this fix was included in ESP-IDF 4.4.5. and the other which is related to lower speeds than 20 MHz is included in ESP-IDF-5.1 release so will be included in 3.0 version or Arduino ESP32 (already tested on esp-idf-v5.1-libs branch).

So I assume we can close this issue as solved.

About the speed I am not that much sure, why the speed is jus barely faster than at 20 MHz. If you find out anything interesting about the speeds, feel free to comment there or if you find something that needs to be fixed, please open a new PR :)

nhphuc699 commented 8 months ago

Hi @timknapen , I tried in 1bit mode it worked with 40mhz config. but when use 4bit mode, it only worked with 20mhz config and 40mhz not worked. do you have same issuse? Thank You

timknapen commented 7 months ago

Hi @timknapen , I tried in 1bit mode it worked with 40mhz config. but when use 4bit mode, it only worked with 20mhz config and 40mhz not worked. do you have same issuse? Thank You

No I don't have any issues at the moment with 4bit mode at 40mhz. By now I've tested this with at least 3 completely different hardware designs. All work without problems.