Mutable static to keep stack for 2nd core

Hi there,

I'm new to Rust and eager to learn more. So please apologize my basic question.

I'm building a MCU project based on an Raspberry Pi pico2 using rp235x-hal. I need access four HX711 load cells and return readings by USB. Reading the load cells (blocking) seems to take too long (25 ms) to be done on core0 where also the USB need to handled that needs a faster polling rate or else will not correctly talk to the host PC. Hence I'm trying to move reading the HX711 to core1 to avoid a very complex sate machine.

I tried to follow this instructions: rp235x_hal::multicore - Rust
Unfortunately I could not make this work as my version of Rust is preventing the mutual reference to the stack memory.

let _test = core1.spawn(CORE1_STACK.take().unwrap(), core1_task);
| ^^^^^^^^^^^ use of mutable static
|
= note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior

I tried to get around it using StaticCell but could not get that to work either.

Does someone have a suggestion here?

Best regards
Alex

I think the example code is outdated, you can just remove the mut keyword, the Stack type already uses interior mutability:

-static mut CORE1_STACK: Stack<4096> = Stack::new();
+static CORE1_STACK: Stack<4096> = Stack::new();
4 Likes

Thanks a lot! It compiles now.