forked from atsamd-rs/atsamd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update atsamd-hal to 0.16 and add built-in pin definitions * Add LED and VBatt sensor pins. Update each of 3 examples to use new atsamd-hal API * Update version number and changelog * arduino_mkrzero: add blinky_rtic example Signed-off-by: Arne Kappen <[email protected]> * fix fmt Signed-off-by: Arne Kappen <[email protected]> * Update blinky RTIC example to work with latest BSP changes --------- Signed-off-by: Arne Kappen <[email protected]> Co-authored-by: Arne Kappen <[email protected]>
- Loading branch information
1 parent
59fca95
commit d0b91e8
Showing
10 changed files
with
479 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "arduino_mkrzero" | ||
version = "0.12.0" | ||
version = "0.12.1" | ||
authors = ["Wez Furlong <[email protected]>", "David McGillicuddy <[email protected]>"] | ||
description = "Board Support crate for the Arduino MKRZERO" | ||
keywords = ["no-std", "arm", "cortex-m", "embedded-hal", "arduino"] | ||
|
@@ -15,18 +15,23 @@ version = "0.7" | |
optional = true | ||
|
||
[dependencies.atsamd-hal] | ||
version = "0.14" | ||
version = "0.16" | ||
default-features = false | ||
|
||
[dependencies.usb-device] | ||
version = "0.2" | ||
optional = true | ||
|
||
[dependencies.embedded-sdmmc] | ||
version = "0.3" | ||
optional = true | ||
|
||
[dev-dependencies] | ||
cortex-m = "0.7" | ||
usbd-serial = "0.1" | ||
panic-halt = "0.2" | ||
panic-semihosting = "0.5" | ||
cortex-m-rtic = "1.0" | ||
|
||
[features] | ||
# ask the HAL to enable atsamd21g support | ||
|
@@ -35,14 +40,22 @@ rt = ["cortex-m-rt", "atsamd-hal/samd21g-rt"] | |
usb = ["atsamd-hal/usb", "usb-device"] | ||
unproven = ["atsamd-hal/unproven"] | ||
use_semihosting = [] | ||
rtic = ["atsamd-hal/rtic"] | ||
|
||
# for cargo flash | ||
[package.metadata] | ||
chip = "ATSAMD21G18A" | ||
|
||
[dependencies] | ||
embedded-hal = "0.2.7" | ||
|
||
[[example]] | ||
name = "blinky_basic" | ||
|
||
[[example]] | ||
name = "blinky_rtic" | ||
required-features = ["rtic", "unproven"] | ||
|
||
[[example]] | ||
name = "usb_logging" | ||
required-features = ["usb"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
//! Uses RTIC with the RTC as time source to blink an LED. | ||
//! | ||
//! The idle task is sleeping the CPU, so in practice this gives similar power | ||
//! figure as the "sleeping_timer_rtc" example. | ||
#![no_std] | ||
#![no_main] | ||
|
||
use arduino_mkrzero as bsp; | ||
|
||
#[cfg(not(feature = "use_semihosting"))] | ||
use panic_halt as _; | ||
#[cfg(feature = "use_semihosting")] | ||
use panic_semihosting as _; | ||
use rtic::app; | ||
|
||
#[app(device = bsp::pac, peripherals = true, dispatchers = [EVSYS])] | ||
mod app { | ||
use super::*; | ||
use bsp::hal; | ||
use hal::clock::{ClockGenId, ClockSource, GenericClockController}; | ||
use hal::pac::Peripherals; | ||
use hal::prelude::*; | ||
use hal::rtc::{Count32Mode, Duration, Rtc}; | ||
|
||
#[local] | ||
struct Local {} | ||
|
||
#[shared] | ||
struct Shared { | ||
// The LED could be a local resource, since it is only used in one task | ||
// But we want to showcase shared resources and locking | ||
led: bsp::pins::Led, | ||
} | ||
|
||
#[monotonic(binds = RTC, default = true)] | ||
type RtcMonotonic = Rtc<Count32Mode>; | ||
|
||
#[init] | ||
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) { | ||
let mut peripherals: Peripherals = cx.device; | ||
let pins = bsp::pins::Pins::new(peripherals.PORT); | ||
let mut core: rtic::export::Peripherals = cx.core; | ||
let mut clocks = GenericClockController::with_external_32kosc( | ||
peripherals.GCLK, | ||
&mut peripherals.PM, | ||
&mut peripherals.SYSCTRL, | ||
&mut peripherals.NVMCTRL, | ||
); | ||
let _gclk = clocks.gclk0(); | ||
let rtc_clock_src = clocks | ||
.configure_gclk_divider_and_source(ClockGenId::GCLK2, 1, ClockSource::XOSC32K, false) | ||
.unwrap(); | ||
clocks.configure_standby(ClockGenId::GCLK2, true); | ||
let rtc_clock = clocks.rtc(&rtc_clock_src).unwrap(); | ||
let rtc = Rtc::count32_mode(peripherals.RTC, rtc_clock.freq(), &mut peripherals.PM); | ||
let led = bsp::pin_alias!(pins.led).into(); | ||
|
||
// We can use the RTC in standby for maximum power savings | ||
core.SCB.set_sleepdeep(); | ||
|
||
// Start the blink task | ||
blink::spawn().unwrap(); | ||
|
||
(Shared { led }, Local {}, init::Monotonics(rtc)) | ||
} | ||
|
||
#[task(shared = [led])] | ||
fn blink(mut cx: blink::Context) { | ||
// If the LED were a local resource, the lock would not be necessary | ||
let _ = cx.shared.led.lock(|led| led.toggle()); | ||
blink::spawn_after(Duration::secs(3)).ok(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.