wokwi / rp2040js

A Raspberry Pi Pico Emulator in JavaScript
MIT License
384 stars 40 forks source link

ILI9341 freeze with adafruit_ili9341 lib #98

Closed danilinao closed 11 months ago

danilinao commented 2 years ago

When i'm try run this code:

import board
import busio
import displayio
import terminalio
import adafruit_ili9341
from adafruit_display_text import label

dc=board.GP5
rst=board.GP6
blk=board.GP7
cs=board.GP8

spi = busio.SPI(clock=board.GP2, MOSI=board.GP3, MISO=board.GP4)

displayio.release_displays()
display_bus = displayio.FourWire(spi, command = dc, chip_select=cs, reset=rst)

display = adafruit_ili9341.ILI9341(display_bus, width=320, height=240, rotation = 180)

splash = displayio.Group()
display.show(splash)

the emulator freezes and the following messages appear in the js console

image

urish commented 2 years ago

Thanks for reporting! Can you please share the link to the relevant project on Wokwi?

danilinao commented 2 years ago

Sure, https://wokwi.com/projects/333969171970785876

urish commented 2 years ago

Just updating that I managed to reproduce the issue, but still haven't had a chance to dig into it. It's on my radar, though.

guysv commented 11 months ago

reporting here beacuse it seems related:

I tried to run some micropython SPI code on the emulator, and found out that spi.write fails to write any any buffer of length longer than 32 (included). no data ever reaches the rp2040js's spi data callback, not even the first 32 bytes.

e.g given the firmware:

from machine import SPI
spi = SPI(0)
spi.write(b"0123456789abcdef0123456789abcde")
spi.write(b"0123456789abcdef0123456789abcdef")

the rp2040js spi callback will only be called for every byte in the first write.

investigating the micropython repo, I figured ports/rp2/machine_spi.c#machine_spi_transfer is the function responsible for actually calling the pico sdk spi_write_blocking func. Look at its code: if the input buffer length is >= 32, then data is sent to SPI via DMA (a valid optimization) which in rp2040js is not yet implement

good news are DMA already exists in rp2040js, it just doesn't seem wired into the SPI peripherial. Im looking into the fix 🙏

urish commented 11 months ago

Fixed!

image

Thanks @guysv for figuring this out