Skip to content

Commit 0dc3123

Browse files
committed
Add multiple interrupt sources to single handler; Fix examples
1 parent 4d69adb commit 0dc3123

File tree

21 files changed

+364
-565
lines changed

21 files changed

+364
-565
lines changed

boards/feather_m0/Cargo.toml

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,9 @@ optional = true
3636
version = "0.3"
3737
optional = true
3838

39-
[dependencies.cortex-m-interrupt]
40-
version = "0.2.1-git"
41-
optional = true
42-
git = "https://github.com/datdenkikniet/cortex-m-interrupt.git"
43-
rev = "9baa936"
44-
4539
[dev-dependencies]
46-
cortex-m-rtic = "1.1.3"
40+
rtic = { version = "2.0.1", features = ["thumbv6-backend"] }
41+
rtic-monotonics = { version = "1.3.0", features = ["cortex-m-systick", "systick-10khz"] }
4742
fugit = "0.3.6"
4843
cortex-m = "0.7"
4944
usbd-serial = "0.1"
@@ -58,7 +53,6 @@ panic-semihosting = "0.5"
5853
defmt = "0.3"
5954
defmt-rtt = "0.3"
6055
panic-probe = "0.3"
61-
embassy-executor = { version = "0.3.3", features = ["arch-cortex-m", "defmt", "executor-thread", "executor-interrupt", "nightly"] }
6256

6357
[features]
6458
# ask the HAL to enable atsamd21g support
@@ -76,8 +70,8 @@ max-channels = ["dma", "atsamd-hal/max-channels"]
7670
# Enable pins for the adalogger SD card reader
7771
adalogger = []
7872
sdmmc = ["embedded-sdmmc", "atsamd-hal/sdmmc"]
79-
rtic = ["atsamd-hal/rtic"]
8073
use_semihosting = []
74+
nightly = []
8175

8276
[profile.dev]
8377
incremental = false
@@ -146,7 +140,7 @@ required-features = ["adalogger", "usb", "sdmmc", "unproven"]
146140

147141
[[example]]
148142
name = "blinky_rtic"
149-
required-features = ["rtic", "unproven"]
143+
required-features = ["unproven", "nightly"]
150144

151145
[[example]]
152146
name = "uart"
@@ -158,31 +152,24 @@ required-features = ["dma"]
158152

159153
[[example]]
160154
name = "async_dmac"
161-
required-features = ["dma", "atsamd-hal/async", "atsamd-hal/rtic", "cortex-m-interrupt"]
162-
163-
[[example]]
164-
name = "dmac_embassy"
165-
required-features = ["dma", "atsamd-hal/async", "cortex-m-interrupt"]
155+
required-features = ["dma", "atsamd-hal/async", "nightly"]
166156

167157
[[example]]
168158
name = "async_timer"
169-
required-features = ["atsamd-hal/async", "atsamd-hal/rtic", "cortex-m-interrupt"]
159+
required-features = ["atsamd-hal/async", "nightly"]
170160

171161
[[example]]
172162
name = "async_eic"
173-
required-features = ["atsamd-hal/async", "atsamd-hal/rtic", "cortex-m-interrupt"]
163+
required-features = ["atsamd-hal/async", "nightly"]
174164

175165
[[example]]
176166
name = "async_i2c"
177-
required-features = ["dma", "atsamd-hal/async", "atsamd-hal/rtic", "cortex-m-interrupt"]
167+
required-features = ["dma", "atsamd-hal/async", "nightly"]
178168

179169
[[example]]
180170
name = "async_spi"
181-
required-features = ["dma", "atsamd-hal/async", "atsamd-hal/rtic", "cortex-m-interrupt"]
171+
required-features = ["dma", "atsamd-hal/async", "nightly"]
182172

183173
[[example]]
184174
name = "async_uart"
185-
required-features = ["dma", "atsamd-hal/async", "atsamd-hal/rtic", "cortex-m-interrupt"]
186-
187-
[patch.crates-io]
188-
cortex-m-rtic = { git = "https://github.com/rtic-rs/cortex-m-rtic.git", branch = "async-2022" }
175+
required-features = ["dma", "atsamd-hal/async", "nightly"]

boards/feather_m0/examples/async_dmac.rs

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
44
#![no_std]
55
#![no_main]
6+
#![feature(type_alias_impl_trait)]
67

78
use defmt_rtt as _;
89
use panic_probe as _;
@@ -13,20 +14,15 @@ atsamd_hal::bind_interrupts!(struct Irqs {
1314

1415
#[rtic::app(device = bsp::pac, dispatchers = [I2S])]
1516
mod app {
16-
use bsp::{hal, pac};
17+
use bsp::hal;
1718
use feather_m0 as bsp;
1819
use hal::{
19-
clock::{enable_internal_32kosc, ClockGenId, ClockSource, GenericClockController},
20+
clock::GenericClockController,
2021
dmac::{
21-
self, Ch0, Channel, DmaController, PriorityLevel, ReadyFuture, TriggerAction,
22-
TriggerSource,
22+
Ch0, Channel, DmaController, PriorityLevel, ReadyFuture, TriggerAction, TriggerSource,
2323
},
24-
rtc::{Count32Mode, Rtc},
2524
};
2625

27-
#[monotonic(binds = RTC, default = true)]
28-
type Monotonic = Rtc<Count32Mode>;
29-
3026
#[shared]
3127
struct Shared {}
3228

@@ -36,34 +32,20 @@ mod app {
3632
}
3733

3834
#[init]
39-
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
35+
fn init(cx: init::Context) -> (Shared, Local) {
4036
let mut peripherals = cx.device;
4137
let _core = cx.core;
4238

43-
let mut clocks = GenericClockController::with_external_32kosc(
39+
let _clocks = GenericClockController::with_external_32kosc(
4440
peripherals.GCLK,
4541
&mut peripherals.PM,
4642
&mut peripherals.SYSCTRL,
4743
&mut peripherals.NVMCTRL,
4844
);
4945

50-
enable_internal_32kosc(&mut peripherals.SYSCTRL);
51-
let timer_clock = clocks
52-
.configure_gclk_divider_and_source(ClockGenId::GCLK2, 1, ClockSource::OSC32K, false)
53-
.unwrap();
54-
clocks.configure_standby(ClockGenId::GCLK2, true);
55-
56-
// Setup RTC monotonic
57-
let rtc_clock = clocks.rtc(&timer_clock).unwrap();
58-
let rtc = Rtc::count32_mode(peripherals.RTC, rtc_clock.freq(), &mut peripherals.PM);
59-
6046
// Initialize DMA Controller
6147
let dmac = DmaController::init(peripherals.DMAC, &mut peripherals.PM);
62-
// Get handle to IRQ
63-
let dmac_irq = dmac::Interrupts::new(cortex_m_interrupt::take_nvic_interrupt!(
64-
pac::Interrupt::DMAC,
65-
2
66-
));
48+
6749
// Turn dmac into an async controller
6850
let mut dmac = dmac.into_future(crate::Irqs);
6951
// Get individual handles to DMA channels
@@ -73,15 +55,15 @@ mod app {
7355
let channel = channels.0.init(PriorityLevel::LVL0);
7456

7557
async_task::spawn().ok();
76-
(Shared {}, Local { channel }, init::Monotonics(rtc))
58+
(Shared {}, Local { channel })
7759
}
7860

7961
#[task(local = [channel])]
8062
async fn async_task(cx: async_task::Context) {
81-
let async_task::LocalResources { channel } = cx.local;
63+
let channel = cx.local.channel;
8264

83-
let mut source = [0xff; 50];
84-
let mut dest = [0x0; 50];
65+
let mut source = [0xff; 500];
66+
let mut dest = [0x0; 500];
8567

8668
defmt::info!(
8769
"Launching a DMA transfer.\n\tSource: {}\n\tDestination: {}",

boards/feather_m0/examples/async_eic.rs

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,38 @@
55
use defmt_rtt as _;
66
use panic_probe as _;
77

8+
use bsp::{hal, pin_alias};
9+
use feather_m0 as bsp;
10+
use hal::{
11+
clock::{enable_internal_32kosc, ClockGenId, ClockSource, GenericClockController},
12+
ehal::digital::v2::ToggleableOutputPin,
13+
eic::{
14+
pin::{ExtInt2, Sense},
15+
EIC,
16+
},
17+
gpio::{pin::PA18, Pin, PullUpInterrupt},
18+
rtc::{Count32Mode, Rtc},
19+
};
20+
21+
atsamd_hal::bind_interrupts!(struct Irqs {
22+
EIC => atsamd_hal::eic::InterruptHandler;
23+
});
24+
825
#[rtic::app(device = bsp::pac, dispatchers = [I2S])]
926
mod app {
10-
use bsp::{hal, pac, pin_alias};
11-
use feather_m0 as bsp;
12-
use hal::{
13-
clock::{enable_internal_32kosc, ClockGenId, ClockSource, GenericClockController},
14-
ehal::digital::v2::ToggleableOutputPin,
15-
eic::{
16-
pin::{ExtInt2, Sense},
17-
EIC,
18-
},
19-
gpio::{pin::PA18, Pin, PullUpInterrupt},
20-
rtc::{Count32Mode, Rtc},
21-
};
22-
23-
#[monotonic(binds = RTC, default = true)]
24-
type Monotonic = Rtc<Count32Mode>;
27+
use super::*;
2528

2629
#[shared]
2730
struct Shared {}
2831

2932
#[local]
3033
struct Local {
31-
extint: ExtInt2<Pin<PA18, PullUpInterrupt>, hal::pac::Interrupt>,
34+
extint: ExtInt2<Pin<PA18, PullUpInterrupt>>,
3235
red_led: bsp::RedLed,
3336
}
3437

3538
#[init]
36-
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
39+
fn init(cx: init::Context) -> (Shared, Local) {
3740
let mut peripherals = cx.device;
3841
let _core = cx.core;
3942

@@ -46,33 +49,25 @@ mod app {
4649
let pins = bsp::Pins::new(peripherals.PORT);
4750
let red_led: bsp::RedLed = pin_alias!(pins.red_led).into();
4851

49-
let timer_clock = clocks
52+
let internal_clock = clocks
5053
.configure_gclk_divider_and_source(ClockGenId::GCLK2, 1, ClockSource::OSC32K, false)
5154
.unwrap();
5255
clocks.configure_standby(ClockGenId::GCLK2, true);
5356

54-
let eic_irq = cortex_m_interrupt::take_nvic_interrupt!(pac::Interrupt::EIC, 2);
55-
// tc4_irq.set_priority(2);
56-
5757
enable_internal_32kosc(&mut peripherals.SYSCTRL);
5858

59-
// Setup RTC monotonic
60-
let rtc_clock = clocks.rtc(&timer_clock).unwrap();
61-
let rtc = Rtc::count32_mode(peripherals.RTC, rtc_clock.freq(), &mut peripherals.PM);
62-
63-
// configure a clock for the EIC peripheral
64-
let gclk0 = clocks.gclk0();
65-
let eic_clock = clocks.eic(&gclk0).unwrap();
59+
// Configure a clock for the EIC peripheral
60+
let gclk2 = clocks.gclk2();
61+
let eic_clock = clocks.eic(&gclk2).unwrap();
6662

67-
let mut eic =
68-
EIC::init(&mut peripherals.PM, eic_clock, peripherals.EIC).into_future(eic_irq);
63+
let mut eic = EIC::init(&mut peripherals.PM, eic_clock, peripherals.EIC).into_future(Irqs);
6964
let button: Pin<_, PullUpInterrupt> = pins.d10.into();
7065
let mut extint = ExtInt2::new(button, &mut eic);
7166
extint.enable_interrupt_wake();
7267

7368
async_task::spawn().ok();
7469

75-
(Shared {}, Local { extint, red_led }, init::Monotonics(rtc))
70+
(Shared {}, Local { extint, red_led })
7671
}
7772

7873
#[task(local = [extint, red_led])]

boards/feather_m0/examples/async_i2c.rs

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,19 @@
55
use defmt_rtt as _;
66
use panic_probe as _;
77

8-
use atsamd_hal::sercom::Sercom3;
8+
use bsp::hal;
9+
use feather_m0 as bsp;
10+
use fugit::MillisDuration;
11+
use hal::{
12+
clock::GenericClockController,
13+
dmac::{Ch0, DmaController, PriorityLevel},
14+
prelude::*,
15+
sercom::{
16+
i2c::{self, Config, I2cFutureDma},
17+
Sercom3,
18+
},
19+
};
20+
use rtic_monotonics::systick::Systick;
921

1022
atsamd_hal::bind_interrupts!(struct Irqs {
1123
SERCOM3 => atsamd_hal::sercom::i2c::InterruptHandler<Sercom3>;
@@ -15,19 +27,6 @@ atsamd_hal::bind_interrupts!(struct Irqs {
1527
#[rtic::app(device = bsp::pac, dispatchers = [I2S])]
1628
mod app {
1729
use super::*;
18-
use bsp::hal;
19-
use feather_m0 as bsp;
20-
use fugit::MillisDuration;
21-
use hal::{
22-
clock::{enable_internal_32kosc, ClockGenId, ClockSource, GenericClockController},
23-
dmac::{Ch0, DmaController, PriorityLevel},
24-
prelude::*,
25-
rtc::{Count32Mode, Rtc},
26-
sercom::i2c::{self, Config, I2cFutureDma},
27-
};
28-
29-
#[monotonic(binds = RTC, default = true)]
30-
type Monotonic = Rtc<Count32Mode>;
3130

3231
#[shared]
3332
struct Shared {}
@@ -38,7 +37,7 @@ mod app {
3837
}
3938

4039
#[init]
41-
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
40+
fn init(cx: init::Context) -> (Shared, Local) {
4241
let mut peripherals = cx.device;
4342
let _core = cx.core;
4443

@@ -54,16 +53,6 @@ mod app {
5453
// Take SDA and SCL
5554
let (sda, scl) = (pins.sda, pins.scl);
5655

57-
enable_internal_32kosc(&mut peripherals.SYSCTRL);
58-
let timer_clock = clocks
59-
.configure_gclk_divider_and_source(ClockGenId::GCLK2, 1, ClockSource::OSC32K, false)
60-
.unwrap();
61-
clocks.configure_standby(ClockGenId::GCLK2, true);
62-
63-
// Setup RTC monotonic
64-
let rtc_clock = clocks.rtc(&timer_clock).unwrap();
65-
let rtc = Rtc::count32_mode(peripherals.RTC, rtc_clock.freq(), &mut peripherals.PM);
66-
6756
// Initialize DMA Controller
6857
let dmac = DmaController::init(peripherals.DMAC, &mut peripherals.PM);
6958

@@ -91,7 +80,7 @@ mod app {
9180

9281
async_task::spawn().ok();
9382

94-
(Shared {}, Local { i2c }, init::Monotonics(rtc))
83+
(Shared {}, Local { i2c })
9584
}
9685

9786
#[task(local = [i2c])]
@@ -107,7 +96,7 @@ mod app {
10796
let mut buffer = [0xff; 4];
10897
i2c.read(0x76, &mut buffer).await.unwrap();
10998
defmt::info!("Read buffer: {:#x}", buffer);
110-
crate::app::monotonics::delay(MillisDuration::<u32>::from_ticks(500).convert()).await;
99+
Systick::delay(MillisDuration::<u32>::from_ticks(500).convert()).await;
111100
}
112101
}
113102
}

0 commit comments

Comments
 (0)