From 6d003e20a83edc064b532d67853f27ec13f4fa4f Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Wed, 7 Oct 2020 15:17:00 +0200 Subject: [PATCH 1/4] Now core contains the same `Peripherals` type based on monotonic --- examples/t-schedule-core-stable.rs | 28 ++++++++++++++++++++++++++++ macros/src/codegen/module.rs | 4 ++-- 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 examples/t-schedule-core-stable.rs diff --git a/examples/t-schedule-core-stable.rs b/examples/t-schedule-core-stable.rs new file mode 100644 index 0000000000..c2a8fdb54a --- /dev/null +++ b/examples/t-schedule-core-stable.rs @@ -0,0 +1,28 @@ +//! [compile-pass] Check `schedule` code generation + +#![deny(unsafe_code)] +#![deny(warnings)] +#![no_main] +#![no_std] + +use panic_halt as _; + +#[rtic::app(device = lm3s6965, monotonic = rtic::cyccnt::CYCCNT)] +mod app { + #[init] + fn init(c: init::Context) -> init::LateResources { + let _c: rtic::Peripherals = c.core; + + init::LateResources {} + } + + #[task] + fn some_task(_: some_task::Context) {} + + // RTIC requires that unused interrupts are declared in an extern block when + // using software tasks; these free interrupts will be used to dispatch the + // software tasks. + extern "C" { + fn SSI0(); + } +} diff --git a/macros/src/codegen/module.rs b/macros/src/codegen/module.rs index 2e51e7db6e..3d90cbd355 100644 --- a/macros/src/codegen/module.rs +++ b/macros/src/codegen/module.rs @@ -15,7 +15,7 @@ pub fn codegen(ctxt: Context, resources_tick: bool, app: &App, extra: &Extra) -> let mut lt = None; match ctxt { Context::Init => { - if app.uses_schedule() { + if extra.monotonic.is_some() { let m = extra.monotonic(); fields.push(quote!( @@ -277,7 +277,7 @@ pub fn codegen(ctxt: Context, resources_tick: bool, app: &App, extra: &Extra) -> }; let core = if ctxt.is_init() { - if app.uses_schedule() { + if extra.monotonic.is_some() { Some(quote!(core: rtic::Peripherals,)) } else { Some(quote!(core: rtic::export::Peripherals,)) From 1fb42536cfa33e43ec2933f58e03fab23a393435 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Mon, 12 Oct 2020 10:25:02 +0200 Subject: [PATCH 2/4] UI fix --- ui/single/locals-cfg.stderr | 8 ++++---- ui/single/resources-cfg.stderr | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ui/single/locals-cfg.stderr b/ui/single/locals-cfg.stderr index e58bd935e3..53cdacc32f 100644 --- a/ui/single/locals-cfg.stderr +++ b/ui/single/locals-cfg.stderr @@ -31,11 +31,11 @@ error[E0425]: cannot find value `FOO` in this scope error: duplicate lang item in crate `panic_halt` (which `$CRATE` depends on): `panic_impl`. | = note: the lang item is first defined in crate `std` (which `$CRATE` depends on) - = note: first definition in `std` loaded from /usr/share/rust/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-cf0f33af3a901778.rlib - = note: second definition in `panic_halt` loaded from $DIR/target/tests/target/x86_64-unknown-linux-gnu/debug/deps/libpanic_halt-ba6f0ab3439cbc7e.rmeta + = note: first definition in `std` loaded from /usr/share/rust/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-f14aca24435a5414.rlib + = note: second definition in `panic_halt` loaded from $DIR/target/tests/target/x86_64-unknown-linux-gnu/debug/deps/libpanic_halt-33949299fdfa2375.rmeta error: duplicate lang item in crate `panic_semihosting`: `panic_impl`. | = note: the lang item is first defined in crate `panic_halt` (which `$CRATE` depends on) - = note: first definition in `panic_halt` loaded from $DIR/target/tests/target/x86_64-unknown-linux-gnu/debug/deps/libpanic_halt-ba6f0ab3439cbc7e.rmeta - = note: second definition in `panic_semihosting` loaded from $DIR/target/tests/target/x86_64-unknown-linux-gnu/debug/deps/libpanic_semihosting-805015f4a2d05965.rmeta + = note: first definition in `panic_halt` loaded from $DIR/target/tests/target/x86_64-unknown-linux-gnu/debug/deps/libpanic_halt-33949299fdfa2375.rmeta + = note: second definition in `panic_semihosting` loaded from $DIR/target/tests/target/x86_64-unknown-linux-gnu/debug/deps/libpanic_semihosting-f97442f9ee5cfc78.rmeta diff --git a/ui/single/resources-cfg.stderr b/ui/single/resources-cfg.stderr index 17f08d8133..0b0c749d00 100644 --- a/ui/single/resources-cfg.stderr +++ b/ui/single/resources-cfg.stderr @@ -1,8 +1,8 @@ error: duplicate lang item in crate `panic_halt` (which `$CRATE` depends on): `panic_impl`. | = note: the lang item is first defined in crate `std` (which `$CRATE` depends on) - = note: first definition in `std` loaded from /usr/share/rust/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-cf0f33af3a901778.rlib - = note: second definition in `panic_halt` loaded from $DIR/target/tests/target/x86_64-unknown-linux-gnu/debug/deps/libpanic_halt-ba6f0ab3439cbc7e.rmeta + = note: first definition in `std` loaded from /usr/share/rust/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-f14aca24435a5414.rlib + = note: second definition in `panic_halt` loaded from $DIR/target/tests/target/x86_64-unknown-linux-gnu/debug/deps/libpanic_halt-33949299fdfa2375.rmeta error[E0609]: no field `o1` on type `initResources<'_>` --> $DIR/resources-cfg.rs:47:21 From efe6b516fb4def3b704216362155633c0834dcc7 Mon Sep 17 00:00:00 2001 From: Daniel Carosone Date: Tue, 13 Oct 2020 10:45:03 +1100 Subject: [PATCH 3/4] device path must be absolute; clarify --- book/en/src/by-example/app.md | 13 ++++++++----- book/en/src/by-example/new.md | 18 +++++++++++++++++- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/book/en/src/by-example/app.md b/book/en/src/by-example/app.md index ab6f45240f..c4f18c7ad6 100644 --- a/book/en/src/by-example/app.md +++ b/book/en/src/by-example/app.md @@ -7,11 +7,14 @@ This is the smallest possible RTIC application: ``` All RTIC applications use the [`app`] attribute (`#[app(..)]`). This attribute -must be applied to a `mod`-item. The `app` attribute has -a mandatory `device` argument that takes a *path* as a value. This path must -point to a *peripheral access crate* (PAC) generated using [`svd2rust`] -**v0.14.x** or newer. The `app` attribute will expand into a suitable entry -point so it's not required to use the [`cortex_m_rt::entry`] attribute. +must be applied to a `mod`-item. The `app` attribute has a mandatory `device` +argument that takes a *path* as a value. This must be a full path pointing to a +*peripheral access crate* (PAC) generated using [`svd2rust`] **v0.14.x** or +newer. More details can be found in the [Starting a new project](./new.md) +section. + +The `app` attribute will expand into a suitable entry point so it's not required +to use the [`cortex_m_rt::entry`] attribute. [`app`]: ../../../api/cortex_m_rtic_macros/attr.app.html [`svd2rust`]: https://crates.io/crates/svd2rust diff --git a/book/en/src/by-example/new.md b/book/en/src/by-example/new.md index 866a9fa5ba..82681bf4e5 100644 --- a/book/en/src/by-example/new.md +++ b/book/en/src/by-example/new.md @@ -52,7 +52,23 @@ $ curl \ > src/main.rs ``` -That example depends on the `panic-semihosting` crate: +The `init` example uses the `lm3s6965` device. Remember to adjust the `device` +argument in the app macro attribute to match the path of your PAC crate, if +different, and add peripherals or other arguments if needed. Although aliases +can be used, this needs to be a full path (from the crate root). For many +devices, it is common for the HAL implementation crate (aliased as `hal`) or +Board Support crate to re-export the PAC as `pac`, leading to a pattern similar +to the below: + +```rust +use abcd123_hal as hal; +//... + +#[rtic::app(device = crate::hal::pac, peripherals = true, monotonic = rtic::cyccnt::CYCCNT)] +mod app { /*...*/ } +``` + +The `init` example also depends on the `panic-semihosting` crate: ``` console $ cargo add panic-semihosting From 48abc26e8577e6b57c46dce40e63022fac2c9375 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Wed, 14 Oct 2020 20:27:43 +0200 Subject: [PATCH 4/4] Detect if the rt flag is defined in the PAC/HAL Better error message Improved error string Update UI tests --- macros/src/codegen.rs | 2 +- macros/src/codegen/pre_init.rs | 4 ++-- macros/src/codegen/spawn_body.rs | 5 ++--- macros/src/codegen/timer_queue.rs | 3 +-- macros/src/codegen/util.rs | 2 +- ui/single/locals-cfg.stderr | 6 ------ 6 files changed, 7 insertions(+), 15 deletions(-) diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs index f230d3956d..e89776c5a5 100644 --- a/macros/src/codegen.rs +++ b/macros/src/codegen.rs @@ -144,7 +144,7 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { /// Implementation details mod #name { /// Always include the device crate which contains the vector table - use #device as _; + use #device as you_must_enable_the_rt_feature_for_the_pac_in_your_cargo_toml; #(#imports)* #(#user_imports)* diff --git a/macros/src/codegen/pre_init.rs b/macros/src/codegen/pre_init.rs index 9c5f35ec37..2aaf9ebded 100644 --- a/macros/src/codegen/pre_init.rs +++ b/macros/src/codegen/pre_init.rs @@ -53,14 +53,14 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec TokenStream2 { let spawnee = &app.software_tasks[name]; let priority = spawnee.args.priority; @@ -42,12 +42,11 @@ pub fn codegen( ) }; - let device = extra.device; let enum_ = util::interrupt_ident(); let interrupt = &analysis.interrupts.get(&priority); let pend = { quote!( - rtic::pend(#device::#enum_::#interrupt); + rtic::pend(you_must_enable_the_rt_feature_for_the_pac_in_your_cargo_toml::#enum_::#interrupt); ) }; diff --git a/macros/src/codegen/timer_queue.rs b/macros/src/codegen/timer_queue.rs index 030158e205..0abbf49d2f 100644 --- a/macros/src/codegen/timer_queue.rs +++ b/macros/src/codegen/timer_queue.rs @@ -72,7 +72,6 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec Vec Ident { pub fn interrupt_ident() -> Ident { let span = Span::call_site(); - Ident::new("Interrupt", span) + Ident::new("interrupt", span) } /// Whether `name` is an exception with configurable priority diff --git a/ui/single/locals-cfg.stderr b/ui/single/locals-cfg.stderr index 53cdacc32f..0af1293f25 100644 --- a/ui/single/locals-cfg.stderr +++ b/ui/single/locals-cfg.stderr @@ -33,9 +33,3 @@ error: duplicate lang item in crate `panic_halt` (which `$CRATE` depends on): `p = note: the lang item is first defined in crate `std` (which `$CRATE` depends on) = note: first definition in `std` loaded from /usr/share/rust/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-f14aca24435a5414.rlib = note: second definition in `panic_halt` loaded from $DIR/target/tests/target/x86_64-unknown-linux-gnu/debug/deps/libpanic_halt-33949299fdfa2375.rmeta - -error: duplicate lang item in crate `panic_semihosting`: `panic_impl`. - | - = note: the lang item is first defined in crate `panic_halt` (which `$CRATE` depends on) - = note: first definition in `panic_halt` loaded from $DIR/target/tests/target/x86_64-unknown-linux-gnu/debug/deps/libpanic_halt-33949299fdfa2375.rmeta - = note: second definition in `panic_semihosting` loaded from $DIR/target/tests/target/x86_64-unknown-linux-gnu/debug/deps/libpanic_semihosting-f97442f9ee5cfc78.rmeta