blinking working

This commit is contained in:
Priec
2025-12-03 11:40:19 +01:00
parent b44ede04cb
commit 60d1ae9a45
13 changed files with 1546 additions and 9 deletions

View File

@@ -34,7 +34,33 @@ unsafe extern "C" {
}
const PWR_FLAG_SBF: u32 = 1 << 1;
static mut IWDG_HANDLE: [u8; 64] = [0; 64];
#[repr(C)]
struct IWDG_InitTypeDef {
prescaler: u32,
reload: u32,
window: u32,
ewi: u32,
}
#[repr(C)]
struct IWDG_HandleTypeDef {
instance: *mut u32,
init: IWDG_InitTypeDef,
}
const IWDG_PRESCALER_256: u32 = 0x06; // prescaler divider
const IWDG_BASE: u32 = 0x4000_3000; // IWDG base address (STM32U5)
static mut IWDG_HANDLE: IWDG_HandleTypeDef = IWDG_HandleTypeDef {
instance: IWDG_BASE as *mut u32,
init: IWDG_InitTypeDef {
prescaler: IWDG_PRESCALER_256,
reload: 125, // ~1s timeout with 32kHz LSI
window: 0xFFF, // disabled window
ewi: 0, // no early wake-up interrupt
},
};
#[embassy_executor::main]
async fn main(spawner: Spawner) {
@@ -68,21 +94,27 @@ async fn main(spawner: Spawner) {
info!("Wake from Standby");
pwr.sr().write(|w| w.set_sbf(true));
}
info!("Iwdg 1 init");
let rcc = pac::RCC;
let csr = rcc.csr().read();
if csr.iwdgrstf() {
info!("Reset source: IWDG");
}
rcc.csr().write(|w| w.set_rmvf(true)); // clear reset flags
info!("Iwdg 1 init");
unsafe {
HAL_IWDG_Init(addr_of_mut!(IWDG_HANDLE) as *mut ());
}
info!("Iwdg 2 init");
info!("Iwdg 2 init");
info!("Iwdg 2 init");
info!("Iwdg 2 init");
info!("Iwdg 2 init");
loop {
info!("tick start");
led.set_high();
Timer::after(Duration::from_secs(1)).await;
// info!("tick end");
info!("LED IS HIGH");
Timer::after(Duration::from_millis(500)).await;
led.set_low();
info!("LED IS LOW");
Timer::after(Duration::from_millis(500)).await;
led.set_high();
info!("LED IS HIGH");
unsafe {
info!("Standby...");