Skip to content

Commit 829ea57

Browse files
committed
Adapt e310x-hal to new version of e310x
1 parent 242de11 commit 829ea57

28 files changed

+397
-344
lines changed

.github/workflows/changelog.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ jobs:
1919
filters: |
2020
e310x:
2121
- 'e310x/**'
22+
e310x-hal:
23+
- 'e310x-hal/**'
2224
2325
- name: Check for CHANGELOG.md (e310x)
2426
if: steps.changes.outputs['e310x'] == 'true'
@@ -27,3 +29,12 @@ jobs:
2729
changeLogPath: ./e310x/CHANGELOG.md
2830
skipLabels: 'skip changelog'
2931
missingUpdateErrorMessage: 'Please add a changelog entry in the e310x/CHANGELOG.md file.'
32+
33+
- name: Check for CHANGELOG.md (e310x-hal)
34+
if: steps.changes.outputs['e310x-hal'] == 'true'
35+
uses: dangoslen/changelog-enforcer@v3
36+
with:
37+
changeLogPath: ./e310x-hal/CHANGELOG.md
38+
skipLabels: 'skip changelog'
39+
missingUpdateErrorMessage: 'Please add a changelog entry in the e310x-hal/CHANGELOG.md file.'
40+

.github/workflows/e310x-hal.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
on:
2+
push:
3+
branches: [ master ]
4+
pull_request:
5+
merge_group:
6+
7+
name: Build check (e310x-hal)
8+
9+
jobs:
10+
# We check that the crate builds and links for all the toolchains and targets.
11+
build-riscv:
12+
strategy:
13+
matrix:
14+
# All generated code should be running on stable now, MRSV is 1.65.0
15+
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
19+
include:
20+
# Nightly is only for reference and allowed to fail
21+
- toolchain: nightly
22+
experimental: true
23+
runs-on: ubuntu-latest
24+
continue-on-error: ${{ matrix.experimental || false }}
25+
steps:
26+
- uses: actions/checkout@v4
27+
- name: Update Rust toolchain
28+
run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }}
29+
- name: Install Rust target
30+
run: rustup target install ${{ matrix.target }}
31+
- name: Build (no features)
32+
run: cargo build --package e310x-hal --target ${{ matrix.target }}
33+
- name: Build (all features)
34+
run: cargo build --package e310x-hal --target ${{ matrix.target }} --all-features
35+
36+
# On MacOS and Ubuntu, we at least make sure that the crate builds and links.
37+
# On Windows, linking fails when the rt feature is enabled.
38+
build-others:
39+
strategy:
40+
matrix:
41+
os: [ macos-latest, ubuntu-latest ]
42+
runs-on: ${{ matrix.os }}
43+
steps:
44+
- uses: actions/checkout@v4
45+
- name: Update Rust toolchain
46+
run: rustup update stable && rustup default stable
47+
- name: Build (no features)
48+
run: cargo test --package e310x-hal
49+
- name: Build (all features)
50+
run: cargo test --package e310x-hal --all-features
51+

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
Cargo.lock
2-
target/
2+
target/
3+
.vscode/

.travis.yml

Lines changed: 0 additions & 33 deletions
This file was deleted.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
resolver = "2"
33
members = [
44
"e310x",
5+
"e310x-hal",
56
]

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
This repository contains various crates useful for writing Rust programs on E310x microcontrollers:
44

55
* [`e310x`]: Peripheral Access Crate (PAC) for E310x chips.
6+
* [`e310x-hal`]: HAL for the E310x family of microcontrollers.
67

78
This project is developed and maintained by the [RISC-V team][team].
89

e310x-hal/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
### Changed
11+
- Update `e310x` dependency and adapt code
12+
- Bump MSRV to 1.65.0 (check Cargo.toml)
1013
- Use `portable-atomic` to allow builds on `riscv32imc-unknown-none-elf`` targets when needed.
1114

1215
## [v0.10.0] - 2023-03-28

e310x-hal/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
name = "e310x-hal"
33
version = "0.11.0"
44
authors = ["David Craven <david@craven.ch>"]
5-
repository = "https://github.com/riscv-rust/e310x-hal"
5+
repository = "https://github.com/riscv-rust/e310x"
66
categories = ["embedded", "hardware-support", "no-std"]
77
description = "HAL for the E310x family of microcontrollers."
88
keywords = ["riscv", "e310", "hal"]
99
license = "ISC"
10-
edition = "2018"
11-
rust-version = "1.59"
10+
edition = "2021"
11+
rust-version = "1.65"
1212

1313
[dependencies]
1414
embedded-hal = { version = "0.2.6", features = ["unproven"] }
1515
nb = "1.0.0"
1616
riscv = { version = "0.10.1", features = ["critical-section-single-hart"] }
17-
e310x = { version = "0.11.0", features = ["rt", "critical-section"] }
17+
e310x = { path = "../e310x", version = "0.11.0", features = ["rt", "critical-section"] }
1818

1919
[target.'cfg(not(target_has_atomic = "32"))'.dependencies]
2020
portable-atomic = { version = "1.4", default-features = false, features = ["unsafe-assume-single-core"] }

e310x-hal/src/clock.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Clock configuration
22
use crate::core::clint::MTIME;
33
use crate::time::Hertz;
4-
use e310x::{AONCLK, PRCI};
4+
use e310x::{Aonclk as AONCLK, Prci as PRCI};
55
use riscv::interrupt;
66
use riscv::register::mcycle;
77

@@ -72,10 +72,10 @@ impl CoreClk {
7272
// Assume `psdclkbypass_n` is not used
7373

7474
// Temporarily switch to the internal oscillator
75-
let prci = unsafe { &*PRCI::ptr() };
75+
let prci = unsafe { PRCI::steal() };
7676
let hfrosc_freq = self.configure_hfrosc();
7777
// Switch to HFROSC, bypass PLL
78-
prci.pllcfg
78+
prci.pllcfg()
7979
.modify(|_, w| w.sel().bit(false).bypass().bit(true));
8080

8181
if let Some(freq) = self.hfxosc {
@@ -87,27 +87,27 @@ impl CoreClk {
8787

8888
/// Configures clock generation system with external oscillator
8989
fn configure_with_external(self, source_freq: Hertz) -> Hertz {
90-
let prci = unsafe { &*PRCI::ptr() };
90+
let prci = unsafe { PRCI::steal() };
9191

9292
// Enable HFXOSC
93-
prci.hfxosccfg.write(|w| w.enable().bit(true));
93+
prci.hfxosccfg().write(|w| w.enable().bit(true));
9494

9595
// Wait for HFXOSC to stabilize
96-
while !prci.hfxosccfg.read().ready().bit_is_set() {}
96+
while !prci.hfxosccfg().read().ready().bit_is_set() {}
9797

9898
// Select HFXOSC as pllref
99-
prci.pllcfg.modify(|_, w| w.refsel().bit(true));
99+
prci.pllcfg().modify(|_, w| w.refsel().bit(true));
100100

101101
let freq;
102102
if source_freq.0 == self.coreclk.0 {
103103
// Use external oscillator with bypassed PLL
104104
freq = source_freq;
105105

106106
// Bypass PLL
107-
prci.pllcfg.modify(|_, w| w.bypass().bit(true));
107+
prci.pllcfg().modify(|_, w| w.bypass().bit(true));
108108

109109
// Bypass divider
110-
prci.plloutdiv.write(|w| w.divby1().bit(true));
110+
prci.plloutdiv().write(|w| w.divby1().bit(true));
111111
} else {
112112
// Use external oscillator with PLL
113113

@@ -116,57 +116,57 @@ impl CoreClk {
116116
}
117117

118118
// Switch to PLL
119-
prci.pllcfg.modify(|_, w| w.sel().bit(true));
119+
prci.pllcfg().modify(|_, w| w.sel().bit(true));
120120

121121
// Disable HFROSC to save power
122-
prci.hfrosccfg.write(|w| w.enable().bit(false));
122+
prci.hfrosccfg().write(|w| w.enable().bit(false));
123123

124124
freq
125125
}
126126

127127
/// Configures clock generation system with internal oscillator
128128
fn configure_with_internal(self, hfrosc_freq: Hertz) -> Hertz {
129-
let prci = unsafe { &*PRCI::ptr() };
129+
let prci = unsafe { PRCI::steal() };
130130

131131
let freq;
132132
if hfrosc_freq.0 == self.coreclk.0 {
133133
// Use internal oscillator with bypassed PLL
134134
freq = hfrosc_freq;
135135

136136
// Switch to HFROSC, bypass PLL to save power
137-
prci.pllcfg
137+
prci.pllcfg()
138138
.modify(|_, w| w.sel().bit(false).bypass().bit(true));
139139

140140
//
141-
prci.pllcfg.modify(|_, w| w.bypass().bit(true));
141+
prci.pllcfg().modify(|_, w| w.bypass().bit(true));
142142
} else {
143143
// Use internal oscillator with PLL
144144

145145
// Configure PLL and divider
146146
freq = self.configure_pll(hfrosc_freq, self.coreclk);
147147

148148
// Switch to PLL
149-
prci.pllcfg.modify(|_, w| w.sel().bit(true));
149+
prci.pllcfg().modify(|_, w| w.sel().bit(true));
150150
}
151151

152152
// Disable HFXOSC to save power
153-
prci.hfxosccfg.write(|w| w.enable().bit(false));
153+
prci.hfxosccfg().write(|w| w.enable().bit(false));
154154

155155
freq
156156
}
157157

158158
/// Configures internal high-frequency oscillator (`HFROSC`)
159159
fn configure_hfrosc(&self) -> Hertz {
160-
let prci = unsafe { &*PRCI::ptr() };
160+
let prci = unsafe { PRCI::steal() };
161161

162162
// TODO: use trim value from OTP
163163

164164
// Configure HFROSC to 13.8 MHz
165-
prci.hfrosccfg
165+
prci.hfrosccfg()
166166
.write(|w| unsafe { w.div().bits(4).trim().bits(16).enable().bit(true) });
167167

168168
// Wait for HFROSC to stabilize
169-
while !prci.hfrosccfg.read().ready().bit_is_set() {}
169+
while !prci.hfrosccfg().read().ready().bit_is_set() {}
170170

171171
Hertz(13_800_000)
172172
}
@@ -270,8 +270,8 @@ impl CoreClk {
270270
};
271271

272272
// Configure PLL
273-
let prci = unsafe { &*PRCI::ptr() };
274-
prci.pllcfg.modify(|_, w| unsafe {
273+
let prci = unsafe { PRCI::steal() };
274+
prci.pllcfg().modify(|_, w| unsafe {
275275
w.pllr()
276276
.bits(r)
277277
.pllf()
@@ -283,7 +283,7 @@ impl CoreClk {
283283
});
284284

285285
// Configure PLL Output Divider
286-
prci.plloutdiv
286+
prci.plloutdiv()
287287
.write(|w| unsafe { w.div().bits(divider_div as u8).divby1().bit(divider_bypass) });
288288

289289
// Wait for PLL Lock
@@ -295,7 +295,7 @@ impl CoreClk {
295295
let time = mtime.mtime() + 4;
296296
while mtime.mtime() < time {}
297297
// Now it is safe to check for PLL Lock
298-
while !prci.pllcfg.read().lock().bit_is_set() {}
298+
while !prci.pllcfg().read().lock().bit_is_set() {}
299299

300300
Hertz(divout_freq)
301301
}
@@ -318,13 +318,13 @@ impl AonClk {
318318

319319
/// Freezes low-frequency clock configuration, making it effective
320320
pub(crate) fn freeze(self) -> Hertz {
321-
let aonclk = unsafe { &*AONCLK::ptr() };
321+
let aonclk = unsafe { AONCLK::steal() };
322322

323323
if let Some(freq) = self.lfaltclk {
324324
// Use external oscillator.
325325

326326
// Disable unused LFROSC to save power.
327-
aonclk.lfrosccfg.write(|w| w.enable().bit(false));
327+
aonclk.lfrosccfg().write(|w| w.enable().bit(false));
328328

329329
freq
330330
} else {
@@ -334,14 +334,14 @@ impl AonClk {
334334
let div = 4; // LFROSC/5
335335

336336
// Configure LFROSC
337-
aonclk.lfrosccfg.write(|w| unsafe {
337+
aonclk.lfrosccfg().write(|w| unsafe {
338338
w.trim().bits(trim);
339339
w.div().bits(div);
340340
w.enable().bit(true)
341341
});
342342

343343
// Wait for LFROSC to stabilize
344-
while !aonclk.lfrosccfg.read().ready().bit_is_set() {}
344+
while !aonclk.lfrosccfg().read().ready().bit_is_set() {}
345345

346346
Hertz(32_768) // It's not so accurate: ≈30 kHz according to the datasheet
347347
}

0 commit comments

Comments
 (0)