Skip to content

Commit 335c8c2

Browse files
authored
Merge pull request #504 from newAM/eh1
cortex-m: add support for embedded-hal 1.0 delays
2 parents 6df9a38 + ec6b3ba commit 335c8c2

File tree

17 files changed

+58
-23
lines changed

17 files changed

+58
-23
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818

1919
include:
2020
# Test MSRV
21-
- rust: 1.59.0
21+
- rust: 1.60.0
2222

2323
# Test nightly but don't fail
2424
- rust: nightly

.github/workflows/rt-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
continue-on-error: ${{ matrix.experimental || false }}
1414
strategy:
1515
matrix:
16-
rust: [nightly, stable, 1.59.0]
16+
rust: [nightly, stable, 1.60.0]
1717

1818
include:
1919
# Nightly is only for reference and allowed to fail

cortex-m-rt/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1010
- Add `zero-init-ram` feature to initialize RAM with zeros on startup. This can be necessary on
1111
safety-critical hardware to properly initialize memory integrity measures.
1212
- Add optional `exception` argument for `HardFault`. It has one option `trampoline` which is true by default. When set to false, no trampoline will be created and the function will be called as the exception handler directly.
13+
- MSRV increased to 1.60.0 to align with `embedded-hal` version 1.
1314

1415
## [v0.7.3]
1516

cortex-m-rt/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ version = "0.7.3"
1616
autoexamples = true
1717
links = "cortex-m-rt" # Prevent multiple versions of cortex-m-rt being linked
1818
edition = "2021"
19-
rust-version = "1.59"
19+
rust-version = "1.60"
2020

2121
[dependencies]
2222
cortex-m-rt-macros = { path = "macros", version = "=0.7.0" }

cortex-m-rt/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This project is developed and maintained by the [Cortex-M team][team].
1111

1212
# Minimum Supported Rust Version (MSRV)
1313

14-
This crate is guaranteed to compile on stable Rust 1.59.0 and up. It *might*
14+
This crate is guaranteed to compile on stable Rust 1.60.0 and up. It *might*
1515
compile with older versions but that may change in any new patch release.
1616

1717
# License

cortex-m-rt/macros/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ name = "cortex-m-rt-macros"
99
repository = "https://github.com/rust-embedded/cortex-m"
1010
version = "0.7.0"
1111
edition = "2021"
12-
rust-version = "1.59"
12+
rust-version = "1.60"
1313

1414
[lib]
1515
proc-macro = true

cortex-m-rt/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@
442442
//!
443443
//! # Minimum Supported Rust Version (MSRV)
444444
//!
445-
//! The MSRV of this release is Rust 1.59.0.
445+
//! The MSRV of this release is Rust 1.60.0.
446446
447447
// # Developer notes
448448
//

cortex-m-semihosting/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
55

66
## [Unreleased]
77

8+
- MSRV bumped to 1.60 to align with `embedded-hal` version 1.
9+
810
## [v0.5.0] - 2022-03-01
911

1012
- Always use inline-asm, requiring Rust 1.59.

cortex-m-semihosting/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ readme = "README.md"
1313
repository = "https://github.com/rust-embedded/cortex-m"
1414
version = "0.5.0"
1515
edition = "2021"
16-
rust-version = "1.59"
16+
rust-version = "1.60"
1717

1818
[features]
1919
jlink-quirks = []

cortex-m-semihosting/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This project is developed and maintained by the [Cortex-M team][team].
1111

1212
# Minimum Supported Rust Version (MSRV)
1313

14-
This crate is guaranteed to compile on stable Rust 1.59.0 and up. It *might*
14+
This crate is guaranteed to compile on stable Rust 1.60.0 and up. It *might*
1515
compile with older versions but that may change in any new patch release.
1616

1717
## License

cortex-m/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1010
### Breaking changes
1111

1212
- `NVIC::request()` no longer requires `&mut self`.
13+
- `embedded-hal` version 0.2 delay implementations now required the `eh0` feature.
1314

1415
### Added
1516
- Updated `SCB.ICSR.VECTACTIVE`/`SCB::vect_active()` to be 9 bits instead of 8.
@@ -22,6 +23,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2223
- Add `std` and `serde` crate features for improved host-side ITM decode functionality when working with the downstream `itm`, `cargo-rtic-scope` crates (#363, #366).
2324
- Added the ability to name the statics generated by `singleton!()` for better debuggability (#364, #380).
2425
- Added `critical-section-single-core` feature which provides an implementation for the `critical_section` crate for single-core systems, based on disabling all interrupts. (#447)
26+
- Added support for `embedded-hal` version 1 delay traits, requiring rust 1.60.
2527

2628
### Fixed
2729
- Fixed `singleton!()` statics sometimes ending up in `.data` instead of `.bss` (#364, #380).

cortex-m/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ readme = "README.md"
1313
repository = "https://github.com/rust-embedded/cortex-m"
1414
version = "0.7.4"
1515
edition = "2021"
16-
rust-version = "1.59"
16+
rust-version = "1.60"
1717
links = "cortex-m" # prevent multiple versions of this crate to be linked together
1818

1919
[dependencies]
2020
critical-section = "1.0.0"
2121
volatile-register = "0.2.2"
2222
bitfield = "0.13.2"
23-
embedded-hal = "0.2.4"
23+
eh0 = { package = "embedded-hal", version = "0.2.4", optional = true }
24+
eh1 = { package = "embedded-hal", version = "1.0.0" }
2425

2526
[dependencies.serde]
2627
version = "1"

cortex-m/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This project is developed and maintained by the [Cortex-M team][team].
1111

1212
## Minimum Supported Rust Version (MSRV)
1313

14-
This crate is guaranteed to compile on stable Rust 1.59 and up. It might compile with older versions but that may change in any new patch release.
14+
This crate is guaranteed to compile on stable Rust 1.60.0 and up. It might compile with older versions but that may change in any new patch release.
1515

1616
## License
1717

cortex-m/src/delay.rs

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! A delay driver based on SysTick.
22
33
use crate::peripheral::{syst::SystClkSource, SYST};
4-
use embedded_hal::blocking::delay::{DelayMs, DelayUs};
4+
use eh1::delay::DelayNs;
55

66
/// System timer (SysTick) as a delay provider.
77
pub struct Delay {
@@ -75,62 +75,91 @@ impl Delay {
7575
}
7676
}
7777

78-
impl DelayMs<u32> for Delay {
78+
#[cfg(feature = "eh0")]
79+
impl eh0::blocking::delay::DelayMs<u32> for Delay {
7980
#[inline]
8081
fn delay_ms(&mut self, ms: u32) {
8182
Delay::delay_ms(self, ms);
8283
}
8384
}
8485

8586
// This is a workaround to allow `delay_ms(42)` construction without specifying a type.
86-
impl DelayMs<i32> for Delay {
87+
#[cfg(feature = "eh0")]
88+
impl eh0::blocking::delay::DelayMs<i32> for Delay {
8789
#[inline(always)]
8890
fn delay_ms(&mut self, ms: i32) {
8991
assert!(ms >= 0);
9092
Delay::delay_ms(self, ms as u32);
9193
}
9294
}
9395

94-
impl DelayMs<u16> for Delay {
96+
#[cfg(feature = "eh0")]
97+
impl eh0::blocking::delay::DelayMs<u16> for Delay {
9598
#[inline(always)]
9699
fn delay_ms(&mut self, ms: u16) {
97100
Delay::delay_ms(self, u32::from(ms));
98101
}
99102
}
100103

101-
impl DelayMs<u8> for Delay {
104+
#[cfg(feature = "eh0")]
105+
impl eh0::blocking::delay::DelayMs<u8> for Delay {
102106
#[inline(always)]
103107
fn delay_ms(&mut self, ms: u8) {
104108
Delay::delay_ms(self, u32::from(ms));
105109
}
106110
}
107111

108-
impl DelayUs<u32> for Delay {
112+
#[cfg(feature = "eh0")]
113+
impl eh0::blocking::delay::DelayUs<u32> for Delay {
109114
#[inline]
110115
fn delay_us(&mut self, us: u32) {
111116
Delay::delay_us(self, us);
112117
}
113118
}
114119

115120
// This is a workaround to allow `delay_us(42)` construction without specifying a type.
116-
impl DelayUs<i32> for Delay {
121+
#[cfg(feature = "eh0")]
122+
impl eh0::blocking::delay::DelayUs<i32> for Delay {
117123
#[inline(always)]
118124
fn delay_us(&mut self, us: i32) {
119125
assert!(us >= 0);
120126
Delay::delay_us(self, us as u32);
121127
}
122128
}
123129

124-
impl DelayUs<u16> for Delay {
130+
#[cfg(feature = "eh0")]
131+
impl eh0::blocking::delay::DelayUs<u16> for Delay {
125132
#[inline(always)]
126133
fn delay_us(&mut self, us: u16) {
127134
Delay::delay_us(self, u32::from(us))
128135
}
129136
}
130137

131-
impl DelayUs<u8> for Delay {
138+
#[cfg(feature = "eh0")]
139+
impl eh0::blocking::delay::DelayUs<u8> for Delay {
132140
#[inline(always)]
133141
fn delay_us(&mut self, us: u8) {
134142
Delay::delay_us(self, u32::from(us))
135143
}
136144
}
145+
146+
impl DelayNs for Delay {
147+
#[inline]
148+
fn delay_ns(&mut self, ns: u32) {
149+
// from the rp2040-hal:
150+
let us = ns / 1000 + if ns % 1000 == 0 { 0 } else { 1 };
151+
// With rustc 1.73, this can be replaced by:
152+
// let us = ns.div_ceil(1000);
153+
Delay::delay_us(self, us)
154+
}
155+
156+
#[inline]
157+
fn delay_us(&mut self, us: u32) {
158+
Delay::delay_us(self, us)
159+
}
160+
161+
#[inline]
162+
fn delay_ms(&mut self, ms: u32) {
163+
Delay::delay_ms(self, ms)
164+
}
165+
}

cortex-m/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
//!
2828
//! # Minimum Supported Rust Version (MSRV)
2929
//!
30-
//! This crate is guaranteed to compile on stable Rust 1.59 and up. It *might*
30+
//! This crate is guaranteed to compile on stable Rust 1.60 and up. It *might*
3131
//! compile with older versions but that may change in any new patch release.
3232
3333
#![deny(missing_docs)]

panic-semihosting/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ license = "MIT OR Apache-2.0"
1111
name = "panic-semihosting"
1212
repository = "https://github.com/rust-embedded/cortex-m"
1313
version = "0.6.0"
14-
rust-version = "1.59"
14+
rust-version = "1.60"
1515
edition = "2021"
1616

1717
[dependencies]

panic-semihosting/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This project is developed and maintained by the [Cortex-M team][team].
88

99
## Minimum Supported Rust Version (MSRV)
1010

11-
This crate is guaranteed to compile on stable Rust 1.59.0 and up. It *might*
11+
This crate is guaranteed to compile on stable Rust 1.60.0 and up. It *might*
1212
compile with older versions but that may change in any new patch release.
1313

1414
## License

0 commit comments

Comments
 (0)