-
Notifications
You must be signed in to change notification settings - Fork 168
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
Can't mount SD card and display at the same time when sharing the same SPI bus #69
Comments
Hi @ryanfobel !
That's true. I'm currently using and supporting only the micropython driver. It provides good performance (when using it in the hybrid mode), it's more flexible than the C driver and easier to maintain.
The reason I chose half duplex mode - is performance. This is important for high enough frame-rates, especially when using animations. In case of ili9341 we only care about writing, so half duplex makes sense.
This is already supported. All drivers that share the same SPI bus should be either half-duplex or full-duplex.
As I mentioned above, full duplex limits performance. |
Hi @amirgon. Thanks for your reply and for all of your work on the micropython bindings for LittlevGL; I'm finding them super useful! I tried running the following code based on your hint to set import os
import machine
import lvgl as lv
import ili9341
os.mount(machine.SDCard(slot=3, sck=18, mosi=23, miso=19, cs=4), '/sd')
lv.init()
disp = ili9341.ili9341(spihost=1, mosi=-1, cs=14, dc=27,
rst=33, backlight=32, mhz=20, backlight_on=1,
hybrid=True, width=320, height=240,
colormode=ili9341.ili9341.COLOR_MODE_BGR,
rot=ili9341.ili9341.MADCTL_ML)
disp.send_cmd(0x21)
scr = lv.obj()
label = lv.label(scr)
label.set_text("Hello World!")
label.align(lv.scr_act(), lv.ALIGN.CENTER, 0, 0)
lv.scr_load(scr)
print(os.listdir('/sd')) When I run the above code against the default micropython build (i.e., with the ili9341 driver initialized using half-duplex SPI), I get the following errors:
If I rebuild micropython with the ili9341 driver initialized using full-duplex mode, the first error disappears, but I still get the second one:
I couldn't find any way to mount the SD card on a pre-initialized SPI bus, but maybe that's something I should ask about on the micropython forums. |
It looks like DMA size is too large. The problem is that the SD card driver initializes the bus with small DMA buffer size. If you can't configure the buffer size on the SD card driver you'd have to use smaller buffers on the ili9341 driver (= higher factors). This will impact performance but save some RAM. |
I tried |
I'm not really sure why this happens. Did you see this issue: espressif/esp-idf#1597 ?
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). Another thing to try on the ili9341 driver is sending SPI transactions exclusively by Bus Acquiring. I'm not sure why this is working at all with the C driver, but not with the micropython driver. Did you make sure it is working stably? |
This issue or pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Hello guys, |
Hi @favnec5 ! I don't think there was any progress on this. Since I can't debug this, I was hoping someone from the LVGL community would face it and would want to invest some time exploring it. I don't think we fully understand the problem yet, specifically why the C driver works where the Python driver doesn't.
This might also be related: #80 So if you (or anyone else) would like to explore this - I'll be happy to re-open this issue. |
Hi amirgon, |
Sorry, i don't think it's possible. espidf module list
|
@embeddedt - I didn't know this @favnec5 - I'm not sure I understand. Doesn't Micropython has its own implementation for sdcard driver? |
Sure, but sdcard.py use internal micropython machine.SPI function. it do not support -1 value into mosi/miso/cl. |
espidf is a generated module. The tricky part is how to not include the whole ESP-IDF because of dependent includes. This is done by defining include guards and filtering out include files explicitly in CMake. |
Hi amirgon,
maybe you would be interested in testing this? reguard, |
That's great! Could you open a PR on lv_binding_micropython to add your |
Sure ! :-) |
Support some LVGL external libs. Related: lvgl/lv_binding_micropython#180 ESP32: Freeze lv_spi.py and sdcard.py. Related: lvgl/lv_binding_micropython#186, lvgl/lv_binding_micropython#69
Summary
I'm trying to use LittlevGL with an m5stack development board (esp32-based with an ili9341 display). Both the display and SD card interface share the same SPI bus, and it's not currently possible to initialize either device on an existing SPI bus.
Based on the work of @miketeachman, I was able to produce a workaround using the ILI9341 C module (details here). Basically, this involves removing the SPI initialization code in
disp_spi_init()
and setting the display to communicate in full-duplex instead of half-duplex mode. I have tried to port these changes to the Pure/Hybrid ili9341 driver, but I can't seem to get it work.boot.py (v1)
The following
boot.py
is a minimal example of loading a LittlevGL button on the m5stack:This produces a blue button on a white screen:
boot.py (v2): mount SD card before initializing display
This is the same
boot.py
, but it tries to mount an SD card prior to initializing the display:As expected, this fails with the error:
Attempted workaround
I tried modifying the pure/hybrid ili9341 driver by removing the SPI initialization code in
disp_spi_init()
and setting the display to communicate in full-duplex mode instead of half-duplex (the things that seemed to resolve the issue for the ILI9341 C module). The changes can be seen here. When I tried testing this modified driver with theboot.py (v2)
from above, it resulted in the following error:I'm not really sure what else to try. I'm happy to have a workaround using the C module, but it looks like the C module is being deprecated in favor of the pure/hybrid python driver, so if possible, I'd like to find a fix for that too. It would also be nice to be able to decide at run time whether you want to attach to a new or pre-initialized SPI bus.
The text was updated successfully, but these errors were encountered: