aboutsummaryrefslogtreecommitdiff
path: root/examples/stm32f3_blinky/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2023-04-16 19:19:09 +0000
committerGitHub <noreply@github.com>2023-04-16 19:19:09 +0000
commit55083fb3ccee36c623c91b48ecc7d1f563ed80f8 (patch)
treeb2166e9a5f93646f7123e2eb323331bf9a4b2fa2 /examples/stm32f3_blinky/src
parent56bf829931cd3f8267ad435f6ff8f3ae200418b4 (diff)
parentb7e4498a7136041d89541bdc7725c8c023fa5c9c (diff)
Merge #736
736: More `xtasks` and add examples to `rtic` repo r=korken89 a=datdenkikniet This was in #732 before, but decluttering that PR seemed sensible Co-authored-by: datdenkikniet <jcdra1@gmail.com>
Diffstat (limited to 'examples/stm32f3_blinky/src')
-rw-r--r--examples/stm32f3_blinky/src/main.rs74
1 files changed, 74 insertions, 0 deletions
diff --git a/examples/stm32f3_blinky/src/main.rs b/examples/stm32f3_blinky/src/main.rs
new file mode 100644
index 0000000..b6da714
--- /dev/null
+++ b/examples/stm32f3_blinky/src/main.rs
@@ -0,0 +1,74 @@
+#![deny(unsafe_code)]
+#![deny(warnings)]
+#![no_main]
+#![no_std]
+#![feature(type_alias_impl_trait)]
+
+use panic_rtt_target as _;
+use rtic::app;
+use rtic_monotonics::systick::*;
+use rtt_target::{rprintln, rtt_init_print};
+use stm32f3xx_hal::gpio::{Output, PushPull, PA5};
+use stm32f3xx_hal::prelude::*;
+
+#[app(device = stm32f3xx_hal::pac, peripherals = true, dispatchers = [SPI1])]
+mod app {
+ use super::*;
+
+ #[shared]
+ struct Shared {}
+
+ #[local]
+ struct Local {
+ led: PA5<Output<PushPull>>,
+ state: bool,
+ }
+
+ #[init]
+ fn init(cx: init::Context) -> (Shared, Local) {
+ // Setup clocks
+ let mut flash = cx.device.FLASH.constrain();
+ let mut rcc = cx.device.RCC.constrain();
+
+ // Initialize the systick interrupt & obtain the token to prove that we did
+ let systick_mono_token = rtic_monotonics::create_systick_token!();
+ Systick::start(cx.core.SYST, 36_000_000, systick_mono_token); // default STM32F303 clock-rate is 36MHz
+
+ rtt_init_print!();
+ rprintln!("init");
+
+ let _clocks = rcc
+ .cfgr
+ .use_hse(8.MHz())
+ .sysclk(36.MHz())
+ .pclk1(36.MHz())
+ .freeze(&mut flash.acr);
+
+ // Setup LED
+ let mut gpioa = cx.device.GPIOA.split(&mut rcc.ahb);
+ let mut led = gpioa
+ .pa5
+ .into_push_pull_output(&mut gpioa.moder, &mut gpioa.otyper);
+ led.set_high().unwrap();
+
+ // Schedule the blinking task
+ blink::spawn().ok();
+
+ (Shared {}, Local { led, state: false })
+ }
+
+ #[task(local = [led, state])]
+ async fn blink(cx: blink::Context) {
+ loop {
+ rprintln!("blink");
+ if *cx.local.state {
+ cx.local.led.set_high().unwrap();
+ *cx.local.state = false;
+ } else {
+ cx.local.led.set_low().unwrap();
+ *cx.local.state = true;
+ }
+ Systick::delay(1000.millis()).await;
+ }
+ }
+}