2022-10-22 15:49:01 +08:00
|
|
|
use super::{gpio, log_setup, sys_timer, usb};
|
|
|
|
use crate::laser_diode::current_sources::*;
|
|
|
|
use fugit::ExtU32;
|
|
|
|
use log::info;
|
2022-10-20 21:21:01 +08:00
|
|
|
use stm32f4xx_hal::{
|
|
|
|
pac::{CorePeripherals, Peripherals},
|
2022-10-22 15:49:01 +08:00
|
|
|
rcc::RccExt,
|
|
|
|
time::MegaHertz,
|
|
|
|
watchdog::IndependentWatchdog,
|
2022-10-20 21:21:01 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#[cfg(not(feature = "semihosting"))]
|
|
|
|
const WATCHDOG_PERIOD: u32 = 1000;
|
|
|
|
#[cfg(feature = "semihosting")]
|
|
|
|
const WATCHDOG_PERIOD: u32 = 30000;
|
|
|
|
|
2022-10-22 15:49:01 +08:00
|
|
|
pub fn bootup(mut core_perif: CorePeripherals, perif: Peripherals) -> IndependentWatchdog {
|
2022-10-20 21:21:01 +08:00
|
|
|
log_setup::init_log();
|
|
|
|
info!("Kirdy init");
|
|
|
|
|
|
|
|
core_perif.SCB.enable_icache();
|
|
|
|
core_perif.SCB.enable_dcache(&mut core_perif.CPUID);
|
|
|
|
|
2022-10-22 15:49:01 +08:00
|
|
|
let clocks = perif
|
|
|
|
.RCC
|
|
|
|
.constrain()
|
2022-10-20 21:21:01 +08:00
|
|
|
.cfgr
|
|
|
|
.use_hse(MegaHertz::from_raw(8).convert())
|
|
|
|
.sysclk(MegaHertz::from_raw(168).convert())
|
|
|
|
.hclk(MegaHertz::from_raw(168).convert())
|
|
|
|
.pclk1(MegaHertz::from_raw(32).convert())
|
|
|
|
.pclk2(MegaHertz::from_raw(64).convert())
|
|
|
|
.freeze();
|
|
|
|
|
2022-10-22 01:58:18 +08:00
|
|
|
sys_timer::setup(core_perif.SYST, clocks);
|
|
|
|
|
2022-10-22 15:49:01 +08:00
|
|
|
let (eth_pins, usb, current_source_phy) = gpio::setup(
|
|
|
|
clocks,
|
|
|
|
perif.GPIOA,
|
|
|
|
perif.GPIOB,
|
|
|
|
perif.GPIOC,
|
|
|
|
perif.GPIOD,
|
|
|
|
perif.GPIOG,
|
|
|
|
perif.SPI2,
|
|
|
|
perif.OTG_FS_GLOBAL,
|
|
|
|
perif.OTG_FS_DEVICE,
|
|
|
|
perif.OTG_FS_PWRCLK,
|
2022-10-21 12:05:55 +08:00
|
|
|
);
|
2022-10-22 01:58:18 +08:00
|
|
|
|
|
|
|
usb::State::setup(usb);
|
|
|
|
|
2022-10-22 15:49:01 +08:00
|
|
|
let mut laser = CurrentSource {
|
2022-10-22 01:58:18 +08:00
|
|
|
phy: current_source_phy,
|
2022-10-22 15:49:01 +08:00
|
|
|
setting: CurrentSourceSettingsConstruct {
|
|
|
|
output_current: 0.0,
|
|
|
|
},
|
2022-10-22 01:58:18 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
laser.setup();
|
|
|
|
laser.set_current(0.1);
|
2022-10-22 15:49:01 +08:00
|
|
|
|
2022-10-20 21:21:01 +08:00
|
|
|
let mut wd = IndependentWatchdog::new(perif.IWDG);
|
|
|
|
wd.start(WATCHDOG_PERIOD.millis());
|
|
|
|
wd.feed();
|
|
|
|
|
2022-10-21 12:05:55 +08:00
|
|
|
info!("Kirdy setup complete");
|
|
|
|
|
2022-10-22 01:58:18 +08:00
|
|
|
wd
|
2022-10-22 15:49:01 +08:00
|
|
|
}
|