rp-rs / rp-hal

A Rust Embedded-HAL for the rp series microcontrollers
https://crates.io/crates/rp2040-hal
Apache License 2.0
1.46k stars 237 forks source link

PIO fails when used on core1 but works on core0 #876

Closed NotQuiteApex closed 1 week ago

NotQuiteApex commented 1 week ago

Howdy! I'm running into an issue where some PIO code seemingly locks up core1 (all things executing on core1 cease, and any messages made with defmt fail to make it back to my computer), whereas it works fine on core0. The code is based off the ST7789 example from pico-examples. Note that I am not using the same pins as the original example. Interestingly, I can get ws2812-pio working on core1 just fine. I also know that the ST7789 driver from the example does work on core1 when writing C code.

I've uploaded the code here: https://github.com/NotQuiteApex/pio-core1-issue

jannic commented 1 week ago

This is most likely a stack overflow: You initialize core1 with a stack size of only 4k words (16kBytes). But your St7789 object that gets allocated on the stack contains a frame buffer that's much larger (~150kBytes). You could try increasing the stack size in static mut CORE1_STACK: Stack<4096> = Stack::new();.

NotQuiteApex commented 1 week ago

That seems to have been it, thank you so much. Should've been obvious lol. Is there a better way to catch these sorts of errors so that it doesn't leave me stumped for a day and a half?

jannic commented 6 days ago

I don't know. I guess that the HardFault handler doesn't have a chance to write out a log message because to do so it also needs some stack space. So all you get is silence. Maybe that's one of the cases where using gdb to step through the program has advantages compared to defmt logging?