mirror of
https://github.com/rtic-rs/rtic.git
synced 2025-12-19 06:15:45 +01:00
Split remove old examples
This commit is contained in:
parent
ef8046b060
commit
5a9135961f
13 changed files with 505 additions and 0 deletions
74
examples/stm32f3_blinky/src/main.rs
Normal file
74
examples/stm32f3_blinky/src/main.rs
Normal file
|
|
@ -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::*;
|
||||
|
||||
rtic_monotonics::make_systick_handler!();
|
||||
|
||||
#[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();
|
||||
|
||||
Systick::start(cx.core.SYST, 36_000_000); // 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue