All checks were successful
Rust/sat-rs/pipeline/head This commit looks good
89 lines
2.7 KiB
Rust
89 lines
2.7 KiB
Rust
#![no_main]
|
|
#![no_std]
|
|
|
|
use rtic::app;
|
|
use satrs_stm32h7_nucleo_rtic as _; // global logger + panicking-behavior + memory layout
|
|
|
|
const DEFAULT_BLINK_FREQ_MS: u32 = 1000;
|
|
|
|
#[app(device = stm32h7xx_hal::stm32, peripherals = true)]
|
|
mod app {
|
|
use super::*;
|
|
use rtic_monotonics::systick::fugit::MillisDurationU32;
|
|
use rtic_monotonics::systick::Systick;
|
|
use stm32h7xx_hal::gpio::{Output, Pin};
|
|
use stm32h7xx_hal::prelude::*;
|
|
|
|
#[shared]
|
|
struct Shared {
|
|
blink_freq: MillisDurationU32,
|
|
}
|
|
|
|
struct Leds {
|
|
led0: Pin<'B', 0, Output>,
|
|
led1: Pin<'B', 7, Output>,
|
|
led2: Pin<'B', 14, Output>,
|
|
}
|
|
#[local]
|
|
struct Local {
|
|
leds: Leds,
|
|
}
|
|
|
|
#[init]
|
|
fn init(cx: init::Context) -> (Shared, Local) {
|
|
defmt::println!("Starting sat-rs demo application for the STM32H743ZIT");
|
|
|
|
let pwr = cx.device.PWR.constrain();
|
|
let pwrcfg = pwr.freeze();
|
|
|
|
let rcc = cx.device.RCC.constrain();
|
|
// Try to keep the clock configuration similar to one used in STM examples:
|
|
// https://github.com/STMicroelectronics/STM32CubeH7/blob/master/Projects/NUCLEO-H743ZI/Examples/GPIO/GPIO_EXTI/Src/main.c
|
|
let ccdr = rcc
|
|
.sys_ck(400.MHz())
|
|
.hclk(200.MHz())
|
|
.use_hse(8.MHz())
|
|
.bypass_hse()
|
|
.pclk1(100.MHz())
|
|
.pclk2(100.MHz())
|
|
.pclk3(100.MHz())
|
|
.pclk4(100.MHz())
|
|
.freeze(pwrcfg, &cx.device.SYSCFG);
|
|
|
|
// 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,
|
|
ccdr.clocks.sys_ck().to_Hz(),
|
|
systick_mono_token,
|
|
);
|
|
|
|
let gpiob = cx.device.GPIOB.split(ccdr.peripheral.GPIOB);
|
|
let led0 = gpiob.pb0.into_push_pull_output();
|
|
let led1 = gpiob.pb7.into_push_pull_output();
|
|
let led2 = gpiob.pb14.into_push_pull_output();
|
|
let leds = Leds { led0, led1, led2 };
|
|
|
|
blink::spawn().expect("spawning blink task failed");
|
|
(
|
|
Shared {
|
|
blink_freq: MillisDurationU32::from_ticks(DEFAULT_BLINK_FREQ_MS),
|
|
},
|
|
Local { leds },
|
|
)
|
|
}
|
|
|
|
#[task(local = [leds], shared=[blink_freq])]
|
|
async fn blink(mut cx: blink::Context) {
|
|
let leds = cx.local.leds;
|
|
loop {
|
|
defmt::info!("toggling LEDs");
|
|
leds.led0.toggle();
|
|
leds.led1.toggle();
|
|
leds.led2.toggle();
|
|
let current_blink_freq = cx.shared.blink_freq.lock(|current| *current);
|
|
Systick::delay(current_blink_freq).await;
|
|
}
|
|
}
|
|
}
|