2021-04-12 00:06:18 +02:00
|
|
|
use stm32f1xx_hal::{
|
|
|
|
delay::Delay,
|
2021-04-14 20:19:33 +02:00
|
|
|
pac::Interrupt,
|
2021-04-12 00:06:18 +02:00
|
|
|
prelude::*,
|
|
|
|
serial::{Config, Serial},
|
|
|
|
stm32,
|
2021-04-14 20:19:33 +02:00
|
|
|
timer::{Event, Timer},
|
2021-04-12 00:06:18 +02:00
|
|
|
};
|
2021-04-11 17:23:17 +02:00
|
|
|
|
2021-04-14 20:19:33 +02:00
|
|
|
use nmea0183::Parser;
|
|
|
|
|
2021-04-11 17:23:17 +02:00
|
|
|
use crate::application::App;
|
2021-04-14 20:19:33 +02:00
|
|
|
use crate::time;
|
2021-04-11 17:23:17 +02:00
|
|
|
|
|
|
|
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
|
2021-04-12 00:06:18 +02:00
|
|
|
let mut gpiob = dp.GPIOB.split(&mut rcc.apb2);
|
2021-04-11 17:23:17 +02:00
|
|
|
let mut gpioc = dp.GPIOC.split(&mut rcc.apb2);
|
|
|
|
|
2021-04-12 00:06:18 +02:00
|
|
|
let mut afio = dp.AFIO.constrain(&mut rcc.apb2);
|
|
|
|
|
2021-04-11 17:23:17 +02:00
|
|
|
let board_led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);
|
|
|
|
|
|
|
|
let delay = Delay::new(cp.SYST, clocks);
|
|
|
|
|
2021-04-12 00:06:18 +02:00
|
|
|
// USART3
|
|
|
|
// Configure pb10 as a push_pull output, this will be the tx pin
|
|
|
|
let tx = gpiob.pb10.into_alternate_push_pull(&mut gpiob.crh);
|
|
|
|
// Take ownership over pb11
|
|
|
|
let rx = gpiob.pb11;
|
|
|
|
|
|
|
|
// Set up the usart device. Taks ownership over the USART register and tx/rx pins. The rest of
|
|
|
|
// the registers are used to enable and configure the device.
|
|
|
|
let serial = Serial::usart3(
|
|
|
|
dp.USART3,
|
|
|
|
(tx, rx),
|
|
|
|
&mut afio.mapr,
|
|
|
|
Config::default().baudrate(9600.bps()),
|
|
|
|
clocks,
|
|
|
|
&mut rcc.apb1,
|
|
|
|
);
|
|
|
|
|
2021-04-14 20:19:33 +02:00
|
|
|
let gps_parser = Parser::new();
|
|
|
|
|
|
|
|
time::setup(dp.TIM2, &clocks, &mut rcc.apb1);
|
|
|
|
|
2021-04-12 00:06:18 +02:00
|
|
|
App {
|
|
|
|
delay,
|
|
|
|
board_led,
|
|
|
|
serial,
|
2021-04-14 20:19:33 +02:00
|
|
|
gps_parser,
|
2021-04-12 00:06:18 +02:00
|
|
|
}
|
2021-04-11 17:23:17 +02:00
|
|
|
}
|