-
Notifications
You must be signed in to change notification settings - Fork 13
Description
On my Raspberry Pi Pico W using the latest SDK, trying to use the library leads to crashing the CPU β execution just hangs, and the chip doesn't do anything else. Here's my project that reproduces the bug: pico-st7789-bug. (This is happening regardless of whether there's any display connected to the Pico.)
I found out that it's caused by the sleep_us(1) calls at various places in the code (lines: 28, 33, 38, 40, 45, 50, 159, 164, 170, 175). It seems that there is a race condition in the SDK that leads to missing the interrupt for the short timer and hanging indefinitely β potentially only on Pico W devices. Related issues: raspberrypi/pico-sdk#1552, raspberrypi/pico-sdk#1500, micropython/micropython#12873
If I remove all these sleep_us calls, the library starts working as expected, and I'm able to run the blink example on a 240x240 display. If there isn't sufficient rationale for the sleep_us(1) calls, I advise to remove them altogether β at least for me the library works perfectly without them. However, if they are necessary for correct timing, we can replace them with something like busy_wait_at_least_cycles, and if they're a walkaround for spi_write_blocking not blocking enough, they can be replaced with a busywait until SPI is done:
while (((spi_hw_t *)st7789_cfg.spi)->sr & SPI_SSPSR_BSY_BITS)
{
tight_loop_contents();
}I can make a PR with any of the proposed solutions.