Reputation: 715
with the given example from here: What is the use of __IO & static keywords in C?, I am working on converting some C files that are using microcontrollers to rust
I would like to know the equivalent of this volatile type in rust
i am aware of unsafe code in rust: is the __IO alternative an example of this?
I'm using a STM32f4XX type HAL
Upvotes: 1
Views: 195
Reputation: 93476
All the I/O qualifier macros are defined in core_cm4.h (normally included indirectly via stm324xx.h) thus:
#ifdef __cplusplus
#define __I volatile /*!< Defines 'read only' permissions */
#else
#define __I volatile const /*!< Defines 'read only' permissions */
#endif
#define __O volatile /*!< Defines 'write only' permissions */
#define __IO volatile /*!< Defines 'read / write' permissions */
as you can see they are simply aliases for standard C qualifiers and not themselves C keyword or even compiler extensions - they are part of the CMSIS.
I am no Rust expert, but it seems that there is no direct equivalent in Rust, in that you cannot simply qualify a variable to ensure all accesses are explicit, so memory-mapped I/O uses a different approach. There is an mmio crate and read_volatile
/write_volatile
and also a Volatile
wrapper, all of which may be relevant to this issue.
Upvotes: 1