LVGL and SD Card won't share SPI bus

This issue is discussed here


Did you see this issue: espressif/esp-idf#1597 ?

Due to the limited amount of IO pins on ESP32, it is desirable to share a SPI bus used for SD cards with other SPI devices such as a LCD display. This is currently not possible with esp-idf since the sdspi_host driver assumes the SD card will be the only device on the SPI bus.

This problem was fixed in espressif/esp-idf@067f3d2, but that commit is not included yet in Micropython (at least not on the last release v1.12, which lv_micropython is aligned to).
If you want, you can try building lv_micropython with a more up to date esp-idf that includes this fix, but youā€™ll probably need to change the SD driver to use the new sdspi_host_init_device , sdspi_host_remove_device functions.


Using Wemos Lolin D32 Pro v2 (ESP32 WROVER-B) 16Mb
with current 1.12 uPy and IDF V4.0-beta1
git checkout 310beae373446ceb9a4ad9b36b5428d7fdf2705f
gpio isā€¦
miso=19 with 10k pull-up
mosi=23 with 10k pull-up
clk=18 with 10k pull-up

cs=4 for sd card with 10k pull-up
cs=12 for xpt2046
cs=14 for ili9341

TFT & Touchā€¦ ok
SD aloneā€¦ ok
SD & TFTā€¦ fail

Is there a fix ??? and how to implement it
I canā€™t believe there isnā€™t more posts related to this issue or is there a remedy?

Iā€™m pretty sure the solution @amirgon mentioned is the only solution right now (rebuilding lv_micropython with a newer ESP-IDF).

Fair enough. However, this is quite a major show-stopper. Quite a few ESP32 boards use the same SPI pins for the screen and SD card. For some, one has to take the board as is: no soldering is possible since everything is integrated.

For the time being, I am quite content to play around without using the SD card, but if I am to use my board properly, I may want to have access to the 8GB of my micro SD: without them, I only have about 1MB storage spaceā€¦

I believe I have already and still not workingā€¦
using 1.12 uPy and IDF V4.0-beta1 shown above.
I updated uPy with help from fstengel

Do I mount the same way??
uos.mount(SDCard(slot=2, sck=18, miso=19, mosi=23, cs=4), ā€˜/sdā€™)

alsoā€¦ how to use these commands

That means one will have to hack into the C source code for machine.SDCard (ports/esp32/machine_sdcard.c). I gather this is something happening around line 221. That is as far as my knowledge of uPyā€™s innards go. My C is more than rusty and I cannot reliably go beyond elementary things

I see you also posted in the micropython forum; I was giong to suggest it. So I gather one will have to waitā€¦

I canā€™t believe the minute that the LVGL was release that no one tried using it with an SD card.
As you know (fstengel) this project is not a hobby and the powers to be are displeased with my hardware choice. There must be other coders that found a workaround.

Please keep in mind that LVGL itself is not really the problem here. It seems that ESP-IDF didnā€™t support this in the first place until recently, and MicroPython has not yet updated their driver to take advantage of the fix.

I just want to mention that one of the ideas behind Open Source Software is the involvement of the community.

  • Something is not working for you? Just try to fix it yourself!
  • Your fix is working well? Contribute it back to the community!
  • You donā€™t know how to / donā€™t want to fix it? Either keep learning and trying, or pay someone else to do it!

When a very small team is working on a large open source project, it is expected that the community participates. Itā€™s not always possible to address every feature request or even every bug.

If you need some feature/bugfix, you are welcome to discuss it here in the forum. (like you are doing right now).
After discussing it, one of the following can happen:

  • The discussion helps you to understand the problem better. You research and fix it, and (hopefully) contribute it back to the communitty.
  • Someone else volunteers to research it and fix it, either because he needs that fix, or because he thinks itā€™s important. Did you notice the word ā€œvolunteerā€? No one is paying that someone to do it!
  • No one volunteers, so the feature/bugfix remains unresolved.

Remember - if you are working on a commercial product and are willing to spend some money, you can always pay someone to do that work for you! Just google ā€œhire freelancerā€.
If the problem is well defined (like in this case) it can be very easy to freelance it.

Only in case you are paying someone to fix a bug you have the right to expect the bug to be fixed, or complain about it not being fixed.
In all other cases, doing so would not achieve any goal, would not contribute to the discussion and certainly would not encourage anyone to make effort trying to solve the problem.

2 Likes

I assume thereā€™s also a limited number of people using ESP32+MicroPython who are experienced enough/have the time to delve into this bug and fix it. I, for instance, am quite familiar with LittlevGL and somewhat familiar with MicroPython, but I know nothing about how ESP32 or ESP-IDF work.

And far less using ESP32+MicroPython+LittlevGL
That is exactly what I was inferring !
Itā€™s unfortunate but this ā€œcommunityā€ is infinitesimally small at this time.
The assumption when I started this project, that there was a large base of support. My Bad

Luckily over at micropython one person saidā€¦

Are you using the Python or C based ILI9341 display driver? If you use the C driver I found a work around ā€¦

Hopefully this works out!
It is much more helpful than the ~300 word diatribe form a thin skin developer.