basic blinky runs now
All checks were successful
Rust/sat-rs/pipeline/head This commit looks good

This commit is contained in:
2024-05-20 13:14:30 +02:00
parent ac4f99ac6c
commit 26046f5230
3 changed files with 188 additions and 68 deletions

View File

@ -0,0 +1,55 @@
//! Blinks an LED
//!
//! This assumes that LD2 (blue) is connected to pb7 and LD3 (red) is connected
//! to pb14. This assumption is true for the nucleo-h743zi board.
#![no_std]
#![no_main]
use satrs_stm32h7_rtic as _;
use stm32h7xx_hal::{block, prelude::*, timer::Timer};
use cortex_m_rt::entry;
// use embedded_hal::digital::v2::OutputPin;
#[entry]
fn main() -> ! {
// Get access to the device specific peripherals from the peripheral access crate
let dp = stm32h7xx_hal::stm32::Peripherals::take().unwrap();
// Take ownership over the RCC devices and convert them into the corresponding HAL structs
let rcc = dp.RCC.constrain();
let pwr = dp.PWR.constrain();
let pwrcfg = pwr.freeze();
// Freeze the configuration of all the clocks in the system and
// retrieve the Core Clock Distribution and Reset (CCDR) object
let rcc = rcc.use_hse(8.MHz()).bypass_hse();
let ccdr = rcc.freeze(pwrcfg, &dp.SYSCFG);
// Acquire the GPIOB peripheral
let gpiob = dp.GPIOB.split(ccdr.peripheral.GPIOB);
// Configure gpio B pin 0 as a push-pull output.
let mut ld1 = gpiob.pb0.into_push_pull_output();
// Configure gpio B pin 7 as a push-pull output.
let mut ld2 = gpiob.pb7.into_push_pull_output();
// Configure gpio B pin 14 as a push-pull output.
let mut ld3 = gpiob.pb14.into_push_pull_output();
// Configure the timer to trigger an update every second
let mut timer = Timer::tim1(dp.TIM1, ccdr.peripheral.TIM1, &ccdr.clocks);
timer.start(1.Hz());
// Wait for the timer to trigger an update and change the state of the LED
loop {
ld1.toggle();
ld2.toggle();
ld3.toggle();
block!(timer.wait()).unwrap();
}
}

View File

@ -4,22 +4,87 @@
use rtic::app;
use satrs_stm32h7_rtic as _;
#[app(device = stm32h7xx_hal::pac)]
const DEFAULT_BLINK_FREQ_MS: u32 = 1000;
#[app(device = stm32h7xx_hal::stm32, peripherals = true)]
mod app {
use cortex_m_semihosting::debug;
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 {}
#[local]
struct Local {}
#[init]
fn init(_: init::Context) -> (Shared, Local) {
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
(Shared {}, Local {})
struct Shared {
blink_freq: MillisDurationU32,
}
//#[task(local = [leds, curr_dir, last_dir], shared=[blink_freq])]
//async fn blink(mut cx: blink::Context) {}
struct Leds {
led0: Pin<'A', 1, Output>,
led1: Pin<'B', 7, Output>,
led2: Pin<'B', 14, Output>,
}
#[local]
struct Local {
leds: Leds,
}
#[init]
fn init(cx: init::Context) -> (Shared, Local) {
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,
8_000_000,
//ccdr.clocks.sys_ck().to_Hz(),
//8_000_000,
systick_mono_token,
);
defmt::info!("Starting sat-rs demo application for the STM32H743ZIT");
let gpioa = cx.device.GPIOA.split(ccdr.peripheral.GPIOA);
let gpiob = cx.device.GPIOB.split(ccdr.peripheral.GPIOB);
let led0 = gpioa.pa1.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 };
(
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;
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;
}
}