Global object like LCD/USART in Rust

โš“ rust    ๐Ÿ“… 2025-07-04    ๐Ÿ‘ค surdeus    ๐Ÿ‘๏ธ 2      

surdeus

I would like to know how to create a static (global) LCD or USART object that different parts of my program can use. I've tried various approaches, but I believe it may not be possible.

In embedded Rust, you need to take ownership of the hardware, as shown below:

rust

let mut dp = pac::Peripherals::take().unwrap();

Once you take ownership, you cannot take it again. Taking partial ownership also prevents you from passing dp to other places.

How can you send text to USART or LCD from different functionsโ€”not just from main? I am beginning to think this might not be feasible.

Please avoid suggesting the use of Mutex or other multi-thread-safe constructs. This issue is not about safety; itโ€™s about the ability to access peripherals from different functions within my project. Thank you.

6 posts - 3 participants

Read full topic

๐Ÿท๏ธ rust_feed