Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
22 changes: 22 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ default-target = "x86_64-unknown-linux-gnu"
[dependencies]
cortex-m = { version = "0.7.7", features = ["critical-section-single-core"] }
cortex-m-rt = "0.7.3"
critical-section = { version = "1.1.3", optional = true }
embassy-time-driver = { version = "0.1.0", optional = true }
embassy-sync = { version = "0.6.0", optional = true }
embedded-dma = "0.2.0"
embedded-hal = "1.0.0"
embedded-hal-02 = { package = "embedded-hal", version = "0.2.7", features = [
Expand All @@ -31,6 +34,12 @@ void = { version = "1.0.2", default-features = false, optional = true }
cortex-m = { version = "0.7.7", features = ["critical-section-single-core"] }
cortex-m-rtic = "1.1.4"
cortex-m-semihosting = "0.5.0"
embassy-executor = { version = "0.6", features = [
"arch-cortex-m",
"executor-thread",
"integrated-timers",
] }
embassy-time = { version = "0.3.2" }
panic-halt = "0.2.0"
panic-itm = "0.4.2"
panic-semihosting = "0.6.0"
Expand All @@ -56,6 +65,15 @@ gd32f190 = ["gd32f1/gd32f190", "device-selected"]
gd32f190x4 = ["gd32f190"]
gd32f190x6 = ["gd32f190"]
gd32f190x8 = ["gd32f190"]
embassy = [
"rt",
"dep:critical-section",
"dep:embassy-sync",
"dep:embassy-time-driver",
]
time-driver-tim1 = ["embassy"]
time-driver-tim2 = ["embassy"]
time-driver-tim14 = ["embassy"]

[profile.dev]
incremental = false
Expand Down Expand Up @@ -109,3 +127,7 @@ required-features = ["rt"]
#[[example]]
#name = "can-rtic"
#required-features = ["has-can", "rt"]

[[example]]
name = "embassy"
required-features = ["time-driver-tim1"]
46 changes: 46 additions & 0 deletions examples/embassy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#![deny(unsafe_code)]
#![no_std]
#![no_main]

use panic_halt as _;

use embassy_executor::{self, Spawner};
use embassy_time::Timer;
use embedded_hal::digital::OutputPin;
use gd32f1x0_hal::{embassy, pac, prelude::*, time::MilliSeconds, watchdog::FreeWatchdog};

#[embassy_executor::task]
async fn blink_task(mut led: impl OutputPin + 'static) {
loop {
Timer::after_millis(1_000).await;
led.set_high().unwrap();
Timer::after_millis(1_000).await;
led.set_low().unwrap();
}
}

#[embassy_executor::main]
async fn main(spawner: Spawner) {
let p = pac::Peripherals::take().unwrap();
let mut rcu = p.rcu.constrain();
let mut flash = p.fmc.constrain();
let clocks = rcu.cfgr.freeze(&mut flash.ws);

embassy::init(p.timer1, &clocks, &mut rcu.apb1);

let mut gpioc = p.gpioc.split(&mut rcu.ahb);
let led = gpioc
.pc13
.into_push_pull_output(&mut gpioc.config)
.downgrade();

// This task will run in parallel with the loop below time-sharing MCU resources
spawner.must_spawn(blink_task(led));

let mut watchdog = FreeWatchdog::new(p.fwdgt);
watchdog.start(MilliSeconds(100));
loop {
Timer::after_micros(500).await;
watchdog.feed();
}
}
9 changes: 9 additions & 0 deletions src/embassy/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use time_driver::{Bus, EmbassyTimeDriver, Timer};

use crate::rcu::Clocks;

mod time_driver;

pub fn init(timer: Timer, clocks: &Clocks, apb: &mut Bus) {
EmbassyTimeDriver::init(timer, clocks, apb)
}
Loading
Loading