Skip to content

Commit 43da651

Browse files
Merge #301
301: Upgrade examples to rtic v1.0.0 r=richardeoin a=richardeoin Co-authored-by: Richard Meadows <962920+richardeoin@users.noreply.github.com>
2 parents 22848b6 + 660ea7a commit 43da651

11 files changed

+446
-399
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ optional = true
5959

6060
[dev-dependencies]
6161
cortex-m-rt = ">=0.6.15,<0.8"
62-
cortex-m-rtic = { version = "0.5.8", default-features = false, features = ["cortex-m-7"] }
62+
cortex-m-rtic = { version = "1.0.0" }
6363
log = "0.4.11"
6464
panic-halt = "0.2.0"
6565
panic-rtt-target = { version = "0.1.0", features = ["cortex-m"] }

examples/ethernet-nucleo-h743zi2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![deny(warnings)]
12
#![no_main]
23
#![no_std]
34

@@ -11,7 +12,6 @@ extern crate cortex_m;
1112
mod utilities;
1213
use log::info;
1314

14-
use stm32h7xx_hal::gpio::Speed;
1515
use stm32h7xx_hal::hal::digital::v2::OutputPin;
1616
use stm32h7xx_hal::rcc::CoreClocks;
1717
use stm32h7xx_hal::{ethernet, ethernet::PHY};

examples/ethernet-rtic-stm32h735g-dk.rs

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,21 @@
1111
#![no_main]
1212
#![no_std]
1313

14-
use cortex_m;
15-
use rtic::app;
16-
1714
#[macro_use]
1815
#[allow(unused)]
1916
mod utilities;
2017
use log::info;
2118

19+
use core::sync::atomic::AtomicU32;
20+
2221
use smoltcp::iface::{
2322
Interface, InterfaceBuilder, Neighbor, NeighborCache, Route, Routes,
2423
SocketStorage,
2524
};
2625
use smoltcp::time::Instant;
2726
use smoltcp::wire::{HardwareAddress, IpAddress, IpCidr, Ipv6Cidr};
2827

29-
use stm32h7xx_hal::gpio;
30-
use stm32h7xx_hal::hal::digital::v2::OutputPin;
31-
use stm32h7xx_hal::rcc::CoreClocks;
32-
use stm32h7xx_hal::{ethernet, ethernet::PHY};
33-
use stm32h7xx_hal::{prelude::*, stm32};
34-
35-
use core::sync::atomic::{AtomicU32, Ordering};
28+
use stm32h7xx_hal::{ethernet, rcc::CoreClocks, stm32};
3629

3730
/// Configure SYSTICK for 1ms timebase
3831
fn systick_init(mut syst: stm32::SYST, clocks: CoreClocks) {
@@ -111,16 +104,27 @@ impl<'a> Net<'a> {
111104
}
112105
}
113106

114-
#[app(device = stm32h7xx_hal::stm32, peripherals = true)]
115-
const APP: () = {
116-
struct Resources {
107+
#[rtic::app(device = stm32h7xx_hal::stm32, peripherals = true)]
108+
mod app {
109+
use stm32h7xx_hal::hal::digital::v2::OutputPin;
110+
use stm32h7xx_hal::{ethernet, ethernet::PHY, gpio, prelude::*};
111+
112+
use super::*;
113+
use core::sync::atomic::Ordering;
114+
115+
#[shared]
116+
struct SharedResources {}
117+
#[local]
118+
struct LocalResources {
117119
net: Net<'static>,
118120
lan8742a: ethernet::phy::LAN8742A<ethernet::EthernetMAC>,
119121
link_led: gpio::gpioc::PC3<gpio::Output<gpio::PushPull>>,
120122
}
121123

122124
#[init]
123-
fn init(mut ctx: init::Context) -> init::LateResources {
125+
fn init(
126+
mut ctx: init::Context,
127+
) -> (SharedResources, LocalResources, init::Monotonics) {
124128
utilities::logger::init();
125129
// Initialise power...
126130
let pwr = ctx.device.PWR.constrain();
@@ -202,35 +206,39 @@ const APP: () = {
202206
// 1ms tick
203207
systick_init(ctx.core.SYST, ccdr.clocks);
204208

205-
init::LateResources {
206-
net,
207-
lan8742a,
208-
link_led,
209-
}
209+
(
210+
SharedResources {},
211+
LocalResources {
212+
net,
213+
lan8742a,
214+
link_led,
215+
},
216+
init::Monotonics(),
217+
)
210218
}
211219

212-
#[idle(resources = [lan8742a, link_led])]
220+
#[idle(local = [lan8742a, link_led])]
213221
fn idle(ctx: idle::Context) -> ! {
214222
loop {
215223
// Ethernet
216-
match ctx.resources.lan8742a.poll_link() {
217-
true => ctx.resources.link_led.set_low(),
218-
_ => ctx.resources.link_led.set_high(),
224+
match ctx.local.lan8742a.poll_link() {
225+
true => ctx.local.link_led.set_low(),
226+
_ => ctx.local.link_led.set_high(),
219227
}
220228
.ok();
221229
}
222230
}
223231

224-
#[task(binds = ETH, resources = [net])]
232+
#[task(binds = ETH, local = [net])]
225233
fn ethernet_event(ctx: ethernet_event::Context) {
226234
unsafe { ethernet::interrupt_handler() }
227235

228236
let time = TIME.load(Ordering::Relaxed);
229-
ctx.resources.net.poll(time as i64);
237+
ctx.local.net.poll(time as i64);
230238
}
231239

232240
#[task(binds = SysTick, priority=15)]
233241
fn systick_tick(_: systick_tick::Context) {
234242
TIME.fetch_add(1, Ordering::Relaxed);
235243
}
236-
};
244+
}

examples/ethernet-rtic-stm32h747i-disco.rs

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,21 @@
1111
#![no_main]
1212
#![no_std]
1313

14-
use cortex_m;
15-
use rtic::app;
16-
1714
#[macro_use]
1815
#[allow(unused)]
1916
mod utilities;
2017
use log::info;
2118

19+
use core::sync::atomic::AtomicU32;
20+
2221
use smoltcp::iface::{
2322
Interface, InterfaceBuilder, Neighbor, NeighborCache, Route, Routes,
2423
SocketStorage,
2524
};
2625
use smoltcp::time::Instant;
2726
use smoltcp::wire::{HardwareAddress, IpAddress, IpCidr, Ipv6Cidr};
2827

29-
use stm32h7xx_hal::gpio;
30-
use stm32h7xx_hal::hal::digital::v2::OutputPin;
31-
use stm32h7xx_hal::rcc::CoreClocks;
32-
use stm32h7xx_hal::{ethernet, ethernet::PHY};
33-
use stm32h7xx_hal::{prelude::*, stm32};
34-
35-
use core::sync::atomic::{AtomicU32, Ordering};
28+
use stm32h7xx_hal::{ethernet, rcc::CoreClocks, stm32};
3629

3730
/// Configure SYSTICK for 1ms timebase
3831
fn systick_init(mut syst: stm32::SYST, clocks: CoreClocks) {
@@ -111,16 +104,27 @@ impl<'a> Net<'a> {
111104
}
112105
}
113106

114-
#[app(device = stm32h7xx_hal::stm32, peripherals = true)]
115-
const APP: () = {
116-
struct Resources {
107+
#[rtic::app(device = stm32h7xx_hal::stm32, peripherals = true)]
108+
mod app {
109+
use stm32h7xx_hal::hal::digital::v2::OutputPin;
110+
use stm32h7xx_hal::{ethernet, ethernet::PHY, gpio, prelude::*};
111+
112+
use super::*;
113+
use core::sync::atomic::Ordering;
114+
115+
#[shared]
116+
struct SharedResources {}
117+
#[local]
118+
struct LocalResources {
117119
net: Net<'static>,
118120
lan8742a: ethernet::phy::LAN8742A<ethernet::EthernetMAC>,
119121
link_led: gpio::gpioi::PI14<gpio::Output<gpio::PushPull>>,
120122
}
121123

122124
#[init]
123-
fn init(mut ctx: init::Context) -> init::LateResources {
125+
fn init(
126+
mut ctx: init::Context,
127+
) -> (SharedResources, LocalResources, init::Monotonics) {
124128
utilities::logger::init();
125129
// Initialise power...
126130
let pwr = ctx.device.PWR.constrain();
@@ -205,35 +209,39 @@ const APP: () = {
205209
// 1ms tick
206210
systick_init(ctx.core.SYST, ccdr.clocks);
207211

208-
init::LateResources {
209-
net,
210-
lan8742a,
211-
link_led,
212-
}
212+
(
213+
SharedResources {},
214+
LocalResources {
215+
net,
216+
lan8742a,
217+
link_led,
218+
},
219+
init::Monotonics(),
220+
)
213221
}
214222

215-
#[idle(resources = [lan8742a, link_led])]
223+
#[idle(local = [lan8742a, link_led])]
216224
fn idle(ctx: idle::Context) -> ! {
217225
loop {
218226
// Ethernet
219-
match ctx.resources.lan8742a.poll_link() {
220-
true => ctx.resources.link_led.set_low(),
221-
_ => ctx.resources.link_led.set_high(),
227+
match ctx.local.lan8742a.poll_link() {
228+
true => ctx.local.link_led.set_low(),
229+
_ => ctx.local.link_led.set_high(),
222230
}
223231
.ok();
224232
}
225233
}
226234

227-
#[task(binds = ETH, resources = [net])]
235+
#[task(binds = ETH, local = [net])]
228236
fn ethernet_event(ctx: ethernet_event::Context) {
229237
unsafe { ethernet::interrupt_handler() }
230238

231239
let time = TIME.load(Ordering::Relaxed);
232-
ctx.resources.net.poll(time as i64);
240+
ctx.local.net.poll(time as i64);
233241
}
234242

235243
#[task(binds = SysTick, priority=15)]
236244
fn systick_tick(_: systick_tick::Context) {
237245
TIME.fetch_add(1, Ordering::Relaxed);
238246
}
239-
};
247+
}

0 commit comments

Comments
 (0)