From d190b8b1922a25f50ef9a5d42b18fd09e5a53b0d Mon Sep 17 00:00:00 2001 From: linuswck Date: Mon, 15 Jan 2024 17:06:27 +0800 Subject: [PATCH] flash: Add init boot seq - Max flash erase time for PSize = 8 and 128KiB Sector is 4s - Watchdog period is changed accordingly --- src/device/boot.rs | 9 ++++++--- src/main.rs | 3 +-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/device/boot.rs b/src/device/boot.rs index 407cccd..e0f05b0 100644 --- a/src/device/boot.rs +++ b/src/device/boot.rs @@ -1,5 +1,6 @@ use core::marker::PhantomData; use super::{gpio, sys_timer, usb}; +use crate::device::flash_store::{self, FlashStore}; use crate::laser_diode::current_sources::{*}; use crate::laser_diode::ld_drive::{self, LdDrive}; use crate::thermostat::max1968::MAX1968; @@ -16,14 +17,14 @@ use stm32f4xx_hal::{ use uom::si::{electric_current::ampere, f64::ElectricCurrent}; #[cfg(not(feature = "semihosting"))] -const WATCHDOG_PERIOD: u32 = 1000; +const WATCHDOG_PERIOD: u32 = 4000; #[cfg(feature = "semihosting")] const WATCHDOG_PERIOD: u32 = 30000; pub fn bootup( mut core_perif: CorePeripherals, perif: Peripherals, -) -> (IndependentWatchdog, LdDrive, Thermostat) { +) -> (IndependentWatchdog, FlashStore, LdDrive, Thermostat) { core_perif.SCB.enable_icache(); core_perif.SCB.enable_dcache(&mut core_perif.CPUID); @@ -78,11 +79,13 @@ pub fn bootup( thermostat.calibrate_dac_value(); thermostat.set_i(ElectricCurrent::new::(1.0)); + let flash_store = flash_store::store(perif.FLASH); + let mut wd = IndependentWatchdog::new(perif.IWDG); wd.start(WATCHDOG_PERIOD.millis()); wd.feed(); info!("Kirdy setup complete"); - (wd, laser, thermostat) + (wd, flash_store, laser, thermostat) } diff --git a/src/main.rs b/src/main.rs index 761f717..c635b00 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,6 @@ use cortex_m_rt::entry; use log::info; use stm32f4xx_hal::pac::{CorePeripherals, Peripherals}; - mod device; mod laser_diode; mod thermostat; @@ -38,7 +37,7 @@ fn main() -> ! { let core_perif = CorePeripherals::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 let volt_fmt = ElectricPotential::format_args(volt, Abbreviation);