Rust and Volatile - (register type volatile)

So - I see this 'volatile' crate:

volatile - Rust

HOWEVER - that is NOT what I am looking for.

I am specifically looking for a means to access HARDWARE register in the rather standard way it is done with Embedded C language drivers.

This means there are:

 A) Volatile Pointers - to a register one can read and write.

 AN example would be a status register for a UART.

 B) "Volatile const pointers" - to a data register that can only be read.

 An Example would be a 'RX_DATA' register that you can read but you cannot write.  The idea would be the TX_DATA register might be at a different address/Location.

Any suggestions? Or is the answer: Give up and write the driver in C.

Have you checked The Embedded Rust Book?

It has a section on peripherals.

1 Like

Is that what you're looking for?

If you search "volatile", you'll find a few others in the standard library, though they may not be relevant.

1 Like

In Rust, volatile is a property of the read or write operation, not the pointer. You can still do all the things you ask for by using ptr::read_volatile or ptr::write_volatile with raw pointers. Raw pointers comes in both const and mut forms.

1 Like

You can definitely use Rust to write embedded code controlling hardware via device memory. The bottom line is get a raw pointer, and use read_volatile() and write_volatile().

If you're looking for better ergonomics, such as keeping track which access permission each register should have, the volatile crate you linked helps with that.

If for some reason you don't find its interface appealing, you could have a look at my reg-map crate. It offers similar functionality, but with a somewhat different interface. The examples on the docs should be quite clear, or at least that's the intention.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.