Static variable in no_std (embassy)
⚓ Rust 📅 2026-07-11 👤 surdeus 👁️ 1Hey,
This might not necessarily be an embedded problem. But it came up for me in an embedded project using the Embassy framework.
I want to calculate and store the bias of my IMU during a startup sequence. It shouldn’t change at runtime for the time being, though it might change later on. Once the value has been calculated, I want to access it multiple times at runtime
What would be the idiomatic way to solve this problem? I started by experimenting with static_cell, but couldn't find a workable solution that way.
In C, I would define a static variable—possibly protected by a mutex—and then write a setter and getter function. The AI tools, which in my experience usually work quite well with Rust, have not yet provided me with a satisfactory solution to this problem.
Thank you very much in advance
3 posts - 2 participants
🏷️ Rust_feed