I wrote some ST7789 screen driver Rust code which just takes bytes from memory and flushes them into the screen. It seems to work but somehow the screen turns completely white less than one second after the memory write operation. This used to work fine, so I was wondering if maybe some other driver was interfering with the SPI, but nope, I disabled everything else and it still does that. I wrote a small test program which uses a different library to speak to the ST, and it works just fine. I am probably doing something wrong somewhere, BUT THEN WHY WAS IT WORKING OK BEFORE? I suspect some weird timing issues. Or maybe my driver code is being optimized by the compiler somehow, and things are not being done in the correct order?

I will probably plug in a logic analyzer tomorrow, but if anyone has any tips on how to debug it...

#st7789 #embeddedrust #embedded #rust #electronics

@ubik 2 things came to my mind.
1st check the CS PIN some inconsistency could "blank" the screen.
2nd Is a keep-alive necessary? Some screens need "activity" to not go asleep.

I remember using one of these for SPI, maybe a good "invest"

https://de.aliexpress.com/item/1005003669762661.html

good look

USB logic analyzer single-chip-mikrocomputer geeignet für ARM FPGA debugging-tool 24M probenahme 8 kanäle - AliExpress 502

Smarter Shopping, Better Living! Aliexpress.com

aliexpress.
@bino yeah, i have one of those logic analyzers, thanks! and no keep-alive is necessary AFAIK. thanks!
@bino so, I hooked up the logic analyzer and suddenly the whole thing started working. I narrowed it down to the screen's RST pin. If I leave it connected to the analyzer, it works. If I disconnect it, the whole thing turns white. I thought maybe some pull-up/pull-down effect might be going on, but this is just an output pin...
@bino OH, I FOUND THE PROBLEM. I think this had already bit me in the ass once. Basically, in the framework I'm using (Embassy), whenever a pin structure is dropped (not sure if you're familiar with Rust, but that's when it goes out of scope), it resets the pin's config. I stored the pin in a parent struct, to make sure it stays in scope, and it now just works. So much time wasted trying to figure this one out... Anyway, thanks for your help!
@ubik nice to hear you found it. I'll try to keep it in mind, need to dig into embassy soon. Writing the ZigBee stack from scratch 🤯
Contributions welcome
github.com/thebino/zigbee-rs
heh, I was considering joking that it was Rust's object ownership semantics that required that, once you viewed what's on the screen, it had to be blanked out; I decided not to, because it wouldn't be useful, but since you've figured it out... the joke wasn't too far off

interesting and useful to know that Rust's memory safety features can also bite

CC: @bino@mastodon.cloud
@lxo @bino Hahaha, good one 🤣