Skip to content

Commit c062ff2

Browse files
committed
Add a convenient patch crate for cortex-m-rt
This adds a `cortex-m-rt-patch` directory that contains a tiny crate that re-exports `teensy4-rt` in its entirety under the crate name `cortex-m-rt` to provide a convenient way of patching upstream crates. The hope is to make workarounds for issues like mciantyre#62 a little easier pending solving rust-embedded/cortex-m-rt#164 and the reconciliation of `cortex-m-rt` and `teensy4-rt`.
1 parent 1d971e4 commit c062ff2

File tree

6 files changed

+50
-5
lines changed

6 files changed

+50
-5
lines changed

Cargo.toml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ Part of the teensy4-rs project.
1212

1313
[dependencies]
1414
cortex-m = "0.6.2"
15+
cortex-m-rt = "0.6.12"
1516
log = "0.4.8"
1617
teensy4-fcb = { path = "teensy4-fcb" }
17-
teensy4-rt = { path = "teensy4-rt" }
1818
teensy4-usb-sys = { path = "teensy4-usb-sys" }
1919

2020
[dependencies.imxrt-hal]
@@ -28,6 +28,7 @@ panic-halt = "0.2.0"
2828

2929
[workspace]
3030
members = [
31+
"cortex-m-rt-patch",
3132
"teensy4-fcb",
3233
"teensy4-rt",
3334
"teensy4-usb-sys",
@@ -36,4 +37,9 @@ members = [
3637
# Don't optimize build dependencies, like proc macros.
3738
# Helps with build times.
3839
[profile.release.build-override]
39-
opt-level = 0
40+
opt-level = 0
41+
42+
# Patch `cortex-m-rt` for reasons described here:
43+
# https://github.com/mciantyre/teensy4-rs#runtime
44+
[patch.crates-io.cortex-m-rt]
45+
path = "cortex-m-rt-patch"

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ To support compatibility with the `cortex-m-rt` crate, the `teensy4-rt` crate us
9898
9999
It is our hope that the `teensy4-rt` crate can be transparently replaced with the `cortext-m-rt` crate once the necessary features are available. If you think that the `teensy4-rt` crate is be diverging from the `cortex-m-rt` crate and might miss that goal, please file an issue!
100100
101+
In the meantime, a patch for the `cortex-m-rt` crate is provided within the `cortex-m-rt-patch` directory. See [cortex-m-rt-patch/README.md](./cortex-m-rt-patch/README.md) for details on how to use the patch.
102+
101103
## Contributing
102104
103105
We welcome support! A great way to contribute is to start using the crates to develop Teensy 4 applications. Submit an issue to help us identify bugs, feature requests, or documentation gaps. See [CONTRIBUTING.md](CONTRIBUTING.md) to learn about the best issue tracker for your request.
@@ -150,4 +152,4 @@ Licensed under either of
150152
http://www.apache.org/licenses/LICENSE-2.0)
151153
- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
152154
153-
at your option.
155+
at your option.

cortex-m-rt-patch/Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# NOTE: This is a temporary patch for `cortex-m-rt` - see the README.
2+
3+
[package]
4+
name = "cortex-m-rt"
5+
version = "0.6.12"
6+
authors = ["mitchmindtree <[email protected]>"]
7+
edition = "2018"
8+
9+
[dependencies]
10+
teensy4-rt = { path = "../teensy4-rt" }

cortex-m-rt-patch/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# `cortex-m-rt` patch for teensy4
2+
3+
The sole purpose of this crate is to allow for patching the `cortex-m-rt`
4+
dependency of upstream crates with the `teensy4-rt` crate. To understand why
5+
this is necessary, please refer to [the Runtime section][1] of the top-level
6+
README.
7+
8+
If you are looking for the repository of the real `cortex-m-rt` crate, see
9+
[here][2].
10+
11+
## Usage
12+
13+
Add the `[patch]` for `cortex-m-rt` to your project like so:
14+
15+
```toml
16+
# Patch `cortex-m-rt` for reasons described here:
17+
# https://github.com/mciantyre/teensy4-rs#runtime
18+
[patch.crates-io.cortex-m-rt]
19+
git = "https://github.com/mciantyre/teensy4-rs"
20+
branch = "master"
21+
```
22+
23+
[1]: https://github.com/mciantyre/teensy4-rs#runtime
24+
[2]: https://github.com/rust-embedded/cortex-m-rt

cortex-m-rt-patch/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#![no_std]
2+
3+
pub use teensy4_rt::*;

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ pub mod usb;
112112

113113
pub use hal::ral::interrupt;
114114

115+
pub use cortex_m_rt as rt;
115116
pub use imxrt_hal as hal;
116-
pub use teensy4_rt as rt;
117117

118118
/// The LED in its final configuration
119119
pub type LED = hal::gpio::GPIO2IO03<hal::gpio::GPIO7, hal::gpio::Output>;
@@ -339,7 +339,7 @@ pub extern "C" fn delay(millis: u32) {
339339

340340
/// Scoping of data related to SYSTICK
341341
mod systick {
342-
use teensy4_rt::exception;
342+
use crate::rt::exception;
343343

344344
#[no_mangle]
345345
static mut systick_millis_count: u32 = 0;

0 commit comments

Comments
 (0)