e310x_hal/
lib.rs

1//! HAL for the E310x family of microcontrollers
2//!
3//! This is an implementation of the [`embedded-hal`] traits for the E310x
4//! family of microcontrollers.
5//!
6//! # Building an application for the E310x chips
7//!
8//! The E310x chips implement the [Zaamo](https://github.com/riscv/riscv-zaamo-zalrsc/blob/main/zaamo-zalrsc.adoc)
9//! extension for atomic instructions. This means that it *partially* supports the `A`
10//! extension for atomic. Specifically, it supports the `amo*` instructions, but not the
11//! `lr*` and `sc*` instructions.
12//!
13//! It is discouraged to use the `riscv32imac-unknown-none-elf` target for E310x chips, as it
14//! will potentially generate code that uses the `lr*` and `sc*` instructions, which are not
15//! supported by the E310x chips. Thus, it is recommended to use `riscv32imc-unknown-none-elf`.
16//!
17//! # Working with atomic operations
18//!
19//! If you are using the `riscv32imc-unknown-none-elf` target, you will notice that
20//! `core::sync::atomic` is not available. To work around this, you can use the
21//! [`portable-atomic`](https://docs.rs/portable-atomic/1.8.0/portable_atomic/) crate.
22//! This crate allows us to use native `amo*` instructions on the E310x chips without requiring
23//! the `A` extension. Furthermore, you can emulate the `lr*` and `sc*` instructions if needed.
24//!
25//! Thus, the recommended way to work with E310x chips is:
26//!
27//! 1. Compile your code against the `riscv32imc-unknown-none-elf` target.
28//! 2. Add the following configuration to your `.cargo/config.toml`:
29//!
30//! ```toml
31//! [target.'cfg(all(target_arch = "riscv32", target_os = "none"))']
32//! rustflags = [
33//!    "--cfg", "portable_atomic_target_feature=\"zaamo\"",
34//! ]
35//!
36//! [build]
37//! target = "riscv32imc-unknown-none-elf"
38//! ```
39//!
40//! This will ensure that the `portable-atomic` crate is correctly configured to work with the E310x chips.
41
42#![deny(missing_docs)]
43#![no_std]
44
45pub use e310x;
46
47pub mod clock;
48pub mod core;
49pub mod delay;
50pub mod device;
51pub mod gpio;
52pub mod pmu;
53pub mod prelude;
54pub mod pwm;
55pub mod rtc;
56pub mod serial;
57pub mod spi;
58pub mod stdout;
59pub mod time;
60pub mod wdog;
61
62#[cfg(feature = "g002")]
63pub mod i2c;
64
65pub use device::DeviceResources;