Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

esp32s3: Implement sdioio #8498

Closed
RetiredWizard opened this issue Oct 21, 2023 · 11 comments · Fixed by #9641
Closed

esp32s3: Implement sdioio #8498

RetiredWizard opened this issue Oct 21, 2023 · 11 comments · Fixed by #9641

Comments

@RetiredWizard
Copy link

I'm going to steal Jeff's train of thought from #5179 but for the esp32s3 chip.

The Makerfabs MaTouch TFT 7" board has an SD card slot wired up for 1bit SDIO and using the link Jeff referenced and example code from the esp-idf, I will take a stab at implementing sdioio in the esp32s3 port but this is definitely a reach for me and I don't expect any usable results soon, so if someone likes this idea and thinks they can throw it together easily, please feel free to speak up and take it over 😁.

@tannewt tannewt added this to the 9.x.x milestone Oct 23, 2023
@dhalbert dhalbert modified the milestones: 9.x.x, Long term Apr 5, 2024
@jacobcrigby
Copy link

Just as a notice, I'm starting to implement this myself. I'll use this issue to keep everyone up to date with my progress.

@jacobcrigby
Copy link

Just finished up a first draft you can see at https://github.com/jacobcrigby/circuitpython/tree/espressif-sdioio

Still to-do:

  • Test a lot, on different boards
  • No sdioio.reset()
  • Init failed on soft reset - check and fix

@RetiredWizard
Copy link
Author

I can't wait to start testing this, unfortunately I'm on the road for the next few days and I'm not sure I'll be able to figure out how to build your repo locally so I'll probably have to wait until Monday.... I will bring the MaTouch with me just in case I have more time than I expect or you get a PR posted so the artifacts are available. Thanks for the work on this!!!

By the way, if you do post a PR to Adafruit this weekend, it would make my day if you could enable the CIRCUITPY_SDIOIO flag on the "makerfabs_tft7" port 😁

@RetiredWizard
Copy link
Author

RetiredWizard commented Jul 8, 2024

@jacobcrigby I finally had some time to build the branch from your repo, however when I added the CIRCUITPY_SDIOIO=1 line to the mpconfigboard.mk of the board I was going to test on, the build complained because of a missing ESP-IDF file.

[422/959] Building CXX object esp-idf/nvs_flash/C...les/__idf_nvs_flash.dir/src/nvs_partition.cpp.objcommon-hal/sdioio/SDCard.c:11:10: fatal error: sdmmc_cmd.h: No such file or directory 11 | #include "sdmmc_cmd.h" | ^~~~~~~~~~~~~

Is there another update to the CP environment to get that file included in the submodule fetch or did you manually copy the file to your local repository?

DOH, after looking again, the file sdmmc_cmd.h file is in my local idf folder, it must a path searching issue....

@RetiredWizard
Copy link
Author

I was able to build by replacing the include with

#include "ports/espressif/esp-idf/components/sdmmc/include/sdmmc_cmd.h"

I assume this isn't the correct way to link to the file but at least I should be able to start testing 😁

@RetiredWizard
Copy link
Author

I have some more testing to do but once I figured out the data pins needed to be passed as a list, I was able to mount an SD card using 1-pin SDIO. 😁

@RetiredWizard
Copy link
Author

I've done a fair amount of testing on the makerfabs TFT7" ESP32-S3 board using 1-bit SDIO and it seems to work fine. I don't know if I have an ESP board with a 4-pin SDIO SD card but I think I may have a breakout that supports SDIO so if it's needed I can try and set that up for testing as well.

The only things I've noticed so far is that CircuitPython doesn't like it at all if you demount the sd card storage.umount(path), deinit the sdio.SDCard object and then attempt to use the storage.VfsFat objected created earlier. I tried the same thing on a board with an SPI based SD card and it did the same thing though (crashes into safe mode - I'll open a new issue on that)

I also noticed that if you allocate the SDIO pins (and don't deinit the SDCard object) they are not reset by a ctrl-D, CP throws a Failed to initialize SDMMC host: 103 error when attempting to mount an SD card until the board is power cycled completely. If you unmount/deinit the objects there's no problem re-mounting as many times as you like. I suspect this is a board level issue with never-reset logic and not really related to the new sdioio module.

@jacobcrigby
Copy link

Thank you so much for doing all of this extra testing! I ended up busy, then went on vacation over the holiday, so I wasn't able to do any extra work on this one.
I just got a few SD breakout boards in the mail, so I'm going to try out a few other ESP32 and ESP32-S3 boards I have with them to see if 4-bit works too.

@dhalbert
Copy link
Collaborator

dhalbert commented Jul 9, 2024

Note the updates in #9418 about deinit for sdcardio. @RetiredWizard noted that the code mentioned here probably needs similar changes.

@RetiredWizard
Copy link
Author

I dug out my SD card breakout and did some 4-wire testing and it seems to work fine as well. Not surprisingly the 4-wire connections had the same deinit and ctrl-D resetting issue but the deinit is probably pretty easily solved by lifting the changes that Dan referenced. If I have some time, I'll take a look at the board never-reset logic and see if I can make any headway on the ctrl-D not cleaning up the SDIO pins.

There was one additional issue related to the deinit problem that I noticed this time. When the sdioio module throws a Failed to initialize SDMMC host message it doesn't release (deinit) the SDIO_CLK (and presumably the SDIO_CMD) pin. So subsequent calls throw a "Pin in use" message. I have sometimes been able to get a stubborn SD card to mount by ejecting and re-inserting it, however if the pins are not released after a failure then more drastic (board reset) measures are required.

On a more of a curious front, when I initialized the sdioio.SDCard object with only 1 data line, I didn't notice a speed difference. I copied a 50K file from the SD card and in both cases it took about 15-16 seconds. I did leave the other three data lines connected since when the were left floating, the card wouldn't mount.

@RetiredWizard
Copy link
Author

@jacobcrigby It will take some digging and I don't know how long it will take to update your code for the deinit issue Dan mentioned, but if you're lost to other projects, I could pick this up and try and get a PR published.

Let me know 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants