aboutsummaryrefslogtreecommitdiff
path: root/examples/stm32f1_bluepill_blinky/src/main.rs
diff options
context:
space:
mode:
authorrnld wbr <ronaldxweber@gmail.com>2025-01-15 20:11:27 +0100
committerGitHub <noreply@github.com>2025-01-15 19:11:27 +0000
commit6f6a56387c22b8a4c5d526d407e2249a7ef7a538 (patch)
treefe883d794be7fb6b828da38531f8d8dda221afcd /examples/stm32f1_bluepill_blinky/src/main.rs
parent1a1237690cf676733579ffde0f507a00950e474e (diff)
Add blinky example for STM32F1 bluepill board (#1007)
Code taken from stm32f3_blinky example with LED port adapted to bluepill board. Port initialization and README from v1 rtic-examples with slight edits.
Diffstat (limited to 'examples/stm32f1_bluepill_blinky/src/main.rs')
-rw-r--r--examples/stm32f1_bluepill_blinky/src/main.rs73
1 files changed, 73 insertions, 0 deletions
diff --git a/examples/stm32f1_bluepill_blinky/src/main.rs b/examples/stm32f1_bluepill_blinky/src/main.rs
new file mode 100644
index 0000000..08cf1cc
--- /dev/null
+++ b/examples/stm32f1_bluepill_blinky/src/main.rs
@@ -0,0 +1,73 @@
+#![deny(unsafe_code)]
+#![deny(warnings)]
+#![no_main]
+#![no_std]
+
+use panic_rtt_target as _;
+use rtic::app;
+use rtic_monotonics::systick::prelude::*;
+use rtt_target::{rprintln, rtt_init_print};
+use stm32f1xx_hal::gpio::{Output, PinState, PushPull, PC13};
+use stm32f1xx_hal::prelude::*;
+
+systick_monotonic!(Mono, 1000);
+
+#[app(device = stm32f1xx_hal::pac, peripherals = true, dispatchers = [SPI1])]
+mod app {
+ use super::*;
+
+ #[shared]
+ struct Shared {}
+
+ #[local]
+ struct Local {
+ led: PC13<Output<PushPull>>,
+ state: bool,
+ }
+
+ #[init]
+ fn init(cx: init::Context) -> (Shared, Local) {
+ // Setup clocks
+ let mut flash = cx.device.FLASH.constrain();
+ let rcc = cx.device.RCC.constrain();
+
+ // Initialize the systick interrupt & obtain the token to prove that we did
+ Mono::start(cx.core.SYST, 36_000_000);
+
+ 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 gpioc = cx.device.GPIOC.split();
+ let led = gpioc
+ .pc13
+ .into_push_pull_output_with_state(&mut gpioc.crh, PinState::Low);
+
+ // 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();
+ *cx.local.state = false;
+ } else {
+ cx.local.led.set_low();
+ *cx.local.state = true;
+ }
+ Mono::delay(1000.millis()).await;
+ }
+ }
+}