Skip to content

Commit

Permalink
Merge pull request #504 from newAM/eh1
Browse files Browse the repository at this point in the history
cortex-m: add support for embedded-hal 1.0 delays
  • Loading branch information
adamgreig authored Feb 18, 2024
2 parents 6df9a38 + ec6b3ba commit 335c8c2
Show file tree
Hide file tree
Showing 17 changed files with 58 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

include:
# Test MSRV
- rust: 1.59.0
- rust: 1.60.0

# Test nightly but don't fail
- rust: nightly
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rt-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
continue-on-error: ${{ matrix.experimental || false }}
strategy:
matrix:
rust: [nightly, stable, 1.59.0]
rust: [nightly, stable, 1.60.0]

include:
# Nightly is only for reference and allowed to fail
Expand Down
1 change: 1 addition & 0 deletions cortex-m-rt/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Add `zero-init-ram` feature to initialize RAM with zeros on startup. This can be necessary on
safety-critical hardware to properly initialize memory integrity measures.
- 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.
- MSRV increased to 1.60.0 to align with `embedded-hal` version 1.

## [v0.7.3]

Expand Down
2 changes: 1 addition & 1 deletion cortex-m-rt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ version = "0.7.3"
autoexamples = true
links = "cortex-m-rt" # Prevent multiple versions of cortex-m-rt being linked
edition = "2021"
rust-version = "1.59"
rust-version = "1.60"

[dependencies]
cortex-m-rt-macros = { path = "macros", version = "=0.7.0" }
Expand Down
2 changes: 1 addition & 1 deletion cortex-m-rt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This project is developed and maintained by the [Cortex-M team][team].

# Minimum Supported Rust Version (MSRV)

This crate is guaranteed to compile on stable Rust 1.59.0 and up. It *might*
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.

# License
Expand Down
2 changes: 1 addition & 1 deletion cortex-m-rt/macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ name = "cortex-m-rt-macros"
repository = "https://github.com/rust-embedded/cortex-m"
version = "0.7.0"
edition = "2021"
rust-version = "1.59"
rust-version = "1.60"

[lib]
proc-macro = true
Expand Down
2 changes: 1 addition & 1 deletion cortex-m-rt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@
//!
//! # Minimum Supported Rust Version (MSRV)
//!
//! The MSRV of this release is Rust 1.59.0.
//! The MSRV of this release is Rust 1.60.0.

// # Developer notes
//
Expand Down
2 changes: 2 additions & 0 deletions cortex-m-semihosting/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

- MSRV bumped to 1.60 to align with `embedded-hal` version 1.

## [v0.5.0] - 2022-03-01

- Always use inline-asm, requiring Rust 1.59.
Expand Down
2 changes: 1 addition & 1 deletion cortex-m-semihosting/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ readme = "README.md"
repository = "https://github.com/rust-embedded/cortex-m"
version = "0.5.0"
edition = "2021"
rust-version = "1.59"
rust-version = "1.60"

[features]
jlink-quirks = []
Expand Down
2 changes: 1 addition & 1 deletion cortex-m-semihosting/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This project is developed and maintained by the [Cortex-M team][team].

# Minimum Supported Rust Version (MSRV)

This crate is guaranteed to compile on stable Rust 1.59.0 and up. It *might*
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.

## License
Expand Down
2 changes: 2 additions & 0 deletions cortex-m/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Breaking changes

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

### Added
- Updated `SCB.ICSR.VECTACTIVE`/`SCB::vect_active()` to be 9 bits instead of 8.
Expand All @@ -22,6 +23,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- 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).
- Added the ability to name the statics generated by `singleton!()` for better debuggability (#364, #380).
- 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)
- Added support for `embedded-hal` version 1 delay traits, requiring rust 1.60.

### Fixed
- Fixed `singleton!()` statics sometimes ending up in `.data` instead of `.bss` (#364, #380).
Expand Down
5 changes: 3 additions & 2 deletions cortex-m/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ readme = "README.md"
repository = "https://github.com/rust-embedded/cortex-m"
version = "0.7.4"
edition = "2021"
rust-version = "1.59"
rust-version = "1.60"
links = "cortex-m" # prevent multiple versions of this crate to be linked together

[dependencies]
critical-section = "1.0.0"
volatile-register = "0.2.2"
bitfield = "0.13.2"
embedded-hal = "0.2.4"
eh0 = { package = "embedded-hal", version = "0.2.4", optional = true }
eh1 = { package = "embedded-hal", version = "1.0.0" }

[dependencies.serde]
version = "1"
Expand Down
2 changes: 1 addition & 1 deletion cortex-m/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This project is developed and maintained by the [Cortex-M team][team].

## Minimum Supported Rust Version (MSRV)

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.
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.

## License

Expand Down
47 changes: 38 additions & 9 deletions cortex-m/src/delay.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! A delay driver based on SysTick.

use crate::peripheral::{syst::SystClkSource, SYST};
use embedded_hal::blocking::delay::{DelayMs, DelayUs};
use eh1::delay::DelayNs;

/// System timer (SysTick) as a delay provider.
pub struct Delay {
Expand Down Expand Up @@ -75,62 +75,91 @@ impl Delay {
}
}

impl DelayMs<u32> for Delay {
#[cfg(feature = "eh0")]
impl eh0::blocking::delay::DelayMs<u32> for Delay {
#[inline]
fn delay_ms(&mut self, ms: u32) {
Delay::delay_ms(self, ms);
}
}

// This is a workaround to allow `delay_ms(42)` construction without specifying a type.
impl DelayMs<i32> for Delay {
#[cfg(feature = "eh0")]
impl eh0::blocking::delay::DelayMs<i32> for Delay {
#[inline(always)]
fn delay_ms(&mut self, ms: i32) {
assert!(ms >= 0);
Delay::delay_ms(self, ms as u32);
}
}

impl DelayMs<u16> for Delay {
#[cfg(feature = "eh0")]
impl eh0::blocking::delay::DelayMs<u16> for Delay {
#[inline(always)]
fn delay_ms(&mut self, ms: u16) {
Delay::delay_ms(self, u32::from(ms));
}
}

impl DelayMs<u8> for Delay {
#[cfg(feature = "eh0")]
impl eh0::blocking::delay::DelayMs<u8> for Delay {
#[inline(always)]
fn delay_ms(&mut self, ms: u8) {
Delay::delay_ms(self, u32::from(ms));
}
}

impl DelayUs<u32> for Delay {
#[cfg(feature = "eh0")]
impl eh0::blocking::delay::DelayUs<u32> for Delay {
#[inline]
fn delay_us(&mut self, us: u32) {
Delay::delay_us(self, us);
}
}

// This is a workaround to allow `delay_us(42)` construction without specifying a type.
impl DelayUs<i32> for Delay {
#[cfg(feature = "eh0")]
impl eh0::blocking::delay::DelayUs<i32> for Delay {
#[inline(always)]
fn delay_us(&mut self, us: i32) {
assert!(us >= 0);
Delay::delay_us(self, us as u32);
}
}

impl DelayUs<u16> for Delay {
#[cfg(feature = "eh0")]
impl eh0::blocking::delay::DelayUs<u16> for Delay {
#[inline(always)]
fn delay_us(&mut self, us: u16) {
Delay::delay_us(self, u32::from(us))
}
}

impl DelayUs<u8> for Delay {
#[cfg(feature = "eh0")]
impl eh0::blocking::delay::DelayUs<u8> for Delay {
#[inline(always)]
fn delay_us(&mut self, us: u8) {
Delay::delay_us(self, u32::from(us))
}
}

impl DelayNs for Delay {
#[inline]
fn delay_ns(&mut self, ns: u32) {
// from the rp2040-hal:
let us = ns / 1000 + if ns % 1000 == 0 { 0 } else { 1 };
// With rustc 1.73, this can be replaced by:
// let us = ns.div_ceil(1000);
Delay::delay_us(self, us)
}

#[inline]
fn delay_us(&mut self, us: u32) {
Delay::delay_us(self, us)
}

#[inline]
fn delay_ms(&mut self, ms: u32) {
Delay::delay_ms(self, ms)
}
}
2 changes: 1 addition & 1 deletion cortex-m/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
//!
//! # Minimum Supported Rust Version (MSRV)
//!
//! This crate is guaranteed to compile on stable Rust 1.59 and up. It *might*
//! This crate is guaranteed to compile on stable Rust 1.60 and up. It *might*
//! compile with older versions but that may change in any new patch release.

#![deny(missing_docs)]
Expand Down
2 changes: 1 addition & 1 deletion panic-semihosting/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ license = "MIT OR Apache-2.0"
name = "panic-semihosting"
repository = "https://github.com/rust-embedded/cortex-m"
version = "0.6.0"
rust-version = "1.59"
rust-version = "1.60"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion panic-semihosting/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This project is developed and maintained by the [Cortex-M team][team].

## Minimum Supported Rust Version (MSRV)

This crate is guaranteed to compile on stable Rust 1.59.0 and up. It *might*
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.

## License
Expand Down

0 comments on commit 335c8c2

Please sign in to comment.