Skip to content

Commit a783004

Browse files
committed
Using portable-atomic always
1 parent 829ea57 commit a783004

File tree

7 files changed

+53
-13
lines changed

7 files changed

+53
-13
lines changed

.cargo/config.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[target.'cfg(all(target_arch = "riscv32", target_os = "none"))']
2+
rustflags = [
3+
"--cfg", "portable_atomic_target_feature=\"zaamo\"",
4+
]
5+
6+
[build]
7+
target = "riscv32imc-unknown-none-elf"

.github/workflows/e310x-hal.yaml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ jobs:
1313
matrix:
1414
# All generated code should be running on stable now, MRSV is 1.65.0
1515
toolchain: [ stable, nightly, 1.65.0 ]
16-
target:
17-
- riscv32imc-unknown-none-elf
18-
- riscv32imac-unknown-none-elf # TODO e310x is not a purely IMAC core
1916
include:
2017
# Nightly is only for reference and allowed to fail
2118
- toolchain: nightly
@@ -27,11 +24,11 @@ jobs:
2724
- name: Update Rust toolchain
2825
run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }}
2926
- name: Install Rust target
30-
run: rustup target install ${{ matrix.target }}
27+
run: rustup target install riscv32imc-unknown-none-elf
3128
- name: Build (no features)
32-
run: cargo build --package e310x-hal --target ${{ matrix.target }}
29+
run: cargo build --package e310x-hal --target riscv32imc-unknown-none-elf
3330
- name: Build (all features)
34-
run: cargo build --package e310x-hal --target ${{ matrix.target }} --all-features
31+
run: cargo build --package e310x-hal --target riscv32imc-unknown-none-elf --all-features
3532

3633
# On MacOS and Ubuntu, we at least make sure that the crate builds and links.
3734
# On Windows, linking fails when the rt feature is enabled.
@@ -44,6 +41,8 @@ jobs:
4441
- uses: actions/checkout@v4
4542
- name: Update Rust toolchain
4643
run: rustup update stable && rustup default stable
44+
- name: Rename .cargo/config to .cargo/config.bak to ignore it
45+
run: mv .cargo/config.toml .cargo/config.bak
4746
- name: Build (no features)
4847
run: cargo test --package e310x-hal
4948
- name: Build (all features)

.github/workflows/e310x.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ jobs:
4444
- uses: actions/checkout@v4
4545
- name: Update Rust toolchain
4646
run: rustup update stable && rustup default stable
47+
- name: Rename .cargo/config to .cargo/config.bak to ignore it
48+
run: mv .cargo/config.toml .cargo/config.bak
4749
- name: Build (no features)
4850
run: cargo test --package e310x
4951
- name: Build (all features)

e310x-hal/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88
## [Unreleased]
99

1010
### Changed
11+
- Use `portable-atomic` with `zaamo` feature to use native `amo*` operations.
12+
- Official target is now `riscv32imc-unknown-none-elf`, as it does not fully support the A extension.
1113
- Update `e310x` dependency and adapt code
1214
- Bump MSRV to 1.65.0 (check Cargo.toml)
13-
- Use `portable-atomic` to allow builds on `riscv32imc-unknown-none-elf`` targets when needed.
1415

1516
## [v0.10.0] - 2023-03-28
1617

e310x-hal/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ embedded-hal = { version = "0.2.6", features = ["unproven"] }
1515
nb = "1.0.0"
1616
riscv = { version = "0.10.1", features = ["critical-section-single-hart"] }
1717
e310x = { path = "../e310x", version = "0.11.0", features = ["rt", "critical-section"] }
18-
19-
[target.'cfg(not(target_has_atomic = "32"))'.dependencies]
20-
portable-atomic = { version = "1.4", default-features = false, features = ["unsafe-assume-single-core"] }
18+
portable-atomic = { version = "1.9", default-features = false}
2119

2220
[features]
2321
g002 = ["e310x/g002"]

e310x-hal/src/gpio.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
33
use core::marker::PhantomData;
44

5-
#[cfg(target_has_atomic = "32")]
6-
use core::sync::atomic::{AtomicU32, Ordering};
7-
#[cfg(not(target_has_atomic = "32"))]
85
use portable_atomic::{AtomicU32, Ordering};
96

107
/// GpioExt trait extends the GPIO0 peripheral.

e310x-hal/src/lib.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,42 @@
22
//!
33
//! This is an implementation of the [`embedded-hal`] traits for the E310x
44
//! 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.
541
642
#![deny(missing_docs)]
743
#![no_std]

0 commit comments

Comments
 (0)