Added blink application

This commit is contained in:
Sebastian 2021-04-11 17:23:17 +02:00
parent d0b5039b71
commit f53b9190ef
4 changed files with 77 additions and 2 deletions

34
src/application/mod.rs Normal file
View File

@ -0,0 +1,34 @@
use cortex_m::prelude::*;
use embedded_hal::digital::v2::OutputPin;
use stm32f1xx_hal::{
delay::Delay,
gpio::{gpioc, Output, PushPull},
};
mod setup;
//use crate::exit;
pub use setup::setup;
pub struct App {
delay: Delay,
board_led: gpioc::PC13<Output<PushPull>>,
}
impl App {
pub fn run(mut self) -> ! {
defmt::info!("Application Startup!");
loop {
defmt::info!("Blink!");
self.board_led.set_high().unwrap();
self.delay.delay_ms(500u32);
defmt::info!("Blonk!");
self.board_led.set_low().unwrap();
self.delay.delay_ms(500u32);
}
//exit();
}
}

31
src/application/setup.rs Normal file
View File

@ -0,0 +1,31 @@
use stm32f1xx_hal::{delay::Delay, prelude::*, stm32};
use crate::application::App;
pub fn setup(cp: cortex_m::peripheral::Peripherals, dp: stm32::Peripherals) -> App {
// Take ownership over the raw flash and rcc devices and convert them into the corresponding
// HAL structs
let mut flash = dp.FLASH.constrain();
let mut rcc = dp.RCC.constrain();
// Freeze the configuration of all the clocks in the system and store the frozen frequencies in
// `clocks`
let clocks = rcc
.cfgr
.use_hse(8.mhz())
.sysclk(72.mhz())
.pclk1(36.mhz())
.freeze(&mut flash.acr);
defmt::info!("Clock Setup done");
// Acquire the GPIOC peripheral
let mut gpioc = dp.GPIOC.split(&mut rcc.apb2);
let board_led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);
let delay = Delay::new(cp.SYST, clocks);
App { delay, board_led }
}

View File

@ -7,6 +7,8 @@ use defmt_rtt as _; // global logger
use panic_probe as _;
use stm32f1xx_hal as _;
pub mod application;
// same panicking *behavior* as `panic-probe` but doesn't print a panic message
// this prevents the panic message being printed *twice* when `defmt::panic` is invoked
#[defmt::panic_handler]

View File

@ -1,11 +1,19 @@
#![no_std]
#![no_main]
use wspr_beacon::exit;
use stm32f1xx_hal::pac;
use wspr_beacon::application;
#[cortex_m_rt::entry]
fn main() -> ! {
defmt::info!("Hello, world!");
exit()
// Get access to the core peripherals from the cortex-m crate
let cp = cortex_m::Peripherals::take().unwrap();
// Get access to the device specific peripherals from the peripheral access crate
let dp = pac::Peripherals::take().unwrap();
let app = application::setup(cp, dp);
app.run()
}