flash: Add init boot seq

- Max flash erase time for PSize = 8 and 128KiB Sector is 4s
- Watchdog period is changed accordingly
This commit is contained in:
linuswck 2024-01-15 17:06:27 +08:00
parent 74325a3cee
commit d190b8b192
2 changed files with 7 additions and 5 deletions

View File

@ -1,5 +1,6 @@
use core::marker::PhantomData; use core::marker::PhantomData;
use super::{gpio, sys_timer, usb}; use super::{gpio, sys_timer, usb};
use crate::device::flash_store::{self, FlashStore};
use crate::laser_diode::current_sources::{*}; use crate::laser_diode::current_sources::{*};
use crate::laser_diode::ld_drive::{self, LdDrive}; use crate::laser_diode::ld_drive::{self, LdDrive};
use crate::thermostat::max1968::MAX1968; use crate::thermostat::max1968::MAX1968;
@ -16,14 +17,14 @@ use stm32f4xx_hal::{
use uom::si::{electric_current::ampere, f64::ElectricCurrent}; use uom::si::{electric_current::ampere, f64::ElectricCurrent};
#[cfg(not(feature = "semihosting"))] #[cfg(not(feature = "semihosting"))]
const WATCHDOG_PERIOD: u32 = 1000; const WATCHDOG_PERIOD: u32 = 4000;
#[cfg(feature = "semihosting")] #[cfg(feature = "semihosting")]
const WATCHDOG_PERIOD: u32 = 30000; const WATCHDOG_PERIOD: u32 = 30000;
pub fn bootup( pub fn bootup(
mut core_perif: CorePeripherals, mut core_perif: CorePeripherals,
perif: Peripherals, perif: Peripherals,
) -> (IndependentWatchdog, LdDrive, Thermostat) { ) -> (IndependentWatchdog, FlashStore, LdDrive, Thermostat) {
core_perif.SCB.enable_icache(); core_perif.SCB.enable_icache();
core_perif.SCB.enable_dcache(&mut core_perif.CPUID); core_perif.SCB.enable_dcache(&mut core_perif.CPUID);
@ -78,11 +79,13 @@ pub fn bootup(
thermostat.calibrate_dac_value(); thermostat.calibrate_dac_value();
thermostat.set_i(ElectricCurrent::new::<ampere>(1.0)); thermostat.set_i(ElectricCurrent::new::<ampere>(1.0));
let flash_store = flash_store::store(perif.FLASH);
let mut wd = IndependentWatchdog::new(perif.IWDG); let mut wd = IndependentWatchdog::new(perif.IWDG);
wd.start(WATCHDOG_PERIOD.millis()); wd.start(WATCHDOG_PERIOD.millis());
wd.feed(); wd.feed();
info!("Kirdy setup complete"); info!("Kirdy setup complete");
(wd, laser, thermostat) (wd, flash_store, laser, thermostat)
} }

View File

@ -4,7 +4,6 @@
use cortex_m_rt::entry; use cortex_m_rt::entry;
use log::info; use log::info;
use stm32f4xx_hal::pac::{CorePeripherals, Peripherals}; use stm32f4xx_hal::pac::{CorePeripherals, Peripherals};
mod device; mod device;
mod laser_diode; mod laser_diode;
mod thermostat; mod thermostat;
@ -38,7 +37,7 @@ fn main() -> ! {
let core_perif = CorePeripherals::take().unwrap(); let core_perif = CorePeripherals::take().unwrap();
let perif = Peripherals::take().unwrap(); let perif = Peripherals::take().unwrap();
let (mut wd, mut laser, mut thermostat,) = bootup(core_perif, perif); let (mut wd, _flash_store, mut laser, mut thermostat,) = bootup(core_perif, perif);
// https://github.com/iliekturtles/uom/blob/master/examples/si.rs // https://github.com/iliekturtles/uom/blob/master/examples/si.rs
let volt_fmt = ElectricPotential::format_args(volt, Abbreviation); let volt_fmt = ElectricPotential::format_args(volt, Abbreviation);