From 13f0c64a8c3cd7d9bc743bd0d69d4ce09c9ea11c Mon Sep 17 00:00:00 2001 From: Eric Yanush Date: Thu, 16 Mar 2023 21:21:39 -0600 Subject: [PATCH] Fix APB clock calculation for several STM32 families --- embassy-stm32/src/rcc/l0.rs | 2 +- embassy-stm32/src/rcc/l1.rs | 2 +- embassy-stm32/src/rcc/l4.rs | 2 +- embassy-stm32/src/rcc/l5.rs | 2 +- embassy-stm32/src/rcc/u5.rs | 4 ++-- embassy-stm32/src/rcc/wb.rs | 2 +- embassy-stm32/src/rcc/wl.rs | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/embassy-stm32/src/rcc/l0.rs b/embassy-stm32/src/rcc/l0.rs index c3d29f16..42a481a7 100644 --- a/embassy-stm32/src/rcc/l0.rs +++ b/embassy-stm32/src/rcc/l0.rs @@ -313,7 +313,7 @@ pub(crate) unsafe fn init(config: Config) { pre => { let pre: Ppre = pre.into(); let pre: u8 = 1 << (pre.0 - 3); - let freq = ahb_freq / (1 << (pre as u8 - 3)); + let freq = ahb_freq / pre as u32; (freq, freq * 2) } }; diff --git a/embassy-stm32/src/rcc/l1.rs b/embassy-stm32/src/rcc/l1.rs index e0180b24..c907fa88 100644 --- a/embassy-stm32/src/rcc/l1.rs +++ b/embassy-stm32/src/rcc/l1.rs @@ -314,7 +314,7 @@ pub(crate) unsafe fn init(config: Config) { pre => { let pre: Ppre = pre.into(); let pre: u8 = 1 << (pre.0 - 3); - let freq = ahb_freq / (1 << (pre as u8 - 3)); + let freq = ahb_freq / pre as u32; (freq, freq * 2) } }; diff --git a/embassy-stm32/src/rcc/l4.rs b/embassy-stm32/src/rcc/l4.rs index c820018a..e650490f 100644 --- a/embassy-stm32/src/rcc/l4.rs +++ b/embassy-stm32/src/rcc/l4.rs @@ -483,7 +483,7 @@ pub(crate) unsafe fn init(config: Config) { pre => { let pre: Ppre = pre.into(); let pre: u8 = 1 << (pre.0 - 3); - let freq = ahb_freq / (1 << (pre as u8 - 3)); + let freq = ahb_freq / pre as u32; (freq, freq * 2) } }; diff --git a/embassy-stm32/src/rcc/l5.rs b/embassy-stm32/src/rcc/l5.rs index 81bf36be..f56fce36 100644 --- a/embassy-stm32/src/rcc/l5.rs +++ b/embassy-stm32/src/rcc/l5.rs @@ -481,7 +481,7 @@ pub(crate) unsafe fn init(config: Config) { pre => { let pre: Ppre = pre.into(); let pre: u8 = 1 << (pre.0 - 3); - let freq = ahb_freq / (1 << (pre as u8 - 3)); + let freq = ahb_freq / pre as u32; (freq, freq * 2) } }; diff --git a/embassy-stm32/src/rcc/u5.rs b/embassy-stm32/src/rcc/u5.rs index 2ba339ec..81507a4d 100644 --- a/embassy-stm32/src/rcc/u5.rs +++ b/embassy-stm32/src/rcc/u5.rs @@ -481,7 +481,7 @@ pub(crate) unsafe fn init(config: Config) { pre => { let pre: u8 = pre.into(); let pre: u8 = 1 << (pre - 3); - let freq = ahb_freq / (1 << (pre as u8 - 3)); + let freq = ahb_freq / pre as u32; (freq, freq * 2) } }; @@ -491,7 +491,7 @@ pub(crate) unsafe fn init(config: Config) { pre => { let pre: u8 = pre.into(); let pre: u8 = 1 << (pre - 3); - let freq = ahb_freq / (1 << (pre as u8 - 3)); + let freq = ahb_freq / pre as u32; (freq, freq * 2) } }; diff --git a/embassy-stm32/src/rcc/wb.rs b/embassy-stm32/src/rcc/wb.rs index c9ada83e..e6123821 100644 --- a/embassy-stm32/src/rcc/wb.rs +++ b/embassy-stm32/src/rcc/wb.rs @@ -151,7 +151,7 @@ pub(crate) unsafe fn init(config: Config) { pre => { let pre: u8 = pre.into(); let pre: u8 = 1 << (pre - 3); - let freq = ahb_freq / (1 << (pre as u8 - 3)); + let freq = ahb_freq / pre as u32; (freq, freq * 2) } }; diff --git a/embassy-stm32/src/rcc/wl.rs b/embassy-stm32/src/rcc/wl.rs index 82b0d04e..7072db98 100644 --- a/embassy-stm32/src/rcc/wl.rs +++ b/embassy-stm32/src/rcc/wl.rs @@ -240,7 +240,7 @@ pub(crate) unsafe fn init(config: Config) { pre => { let pre: u8 = pre.into(); let pre: u8 = 1 << (pre - 3); - let freq = ahb_freq / (1 << (pre as u8 - 3)); + let freq = ahb_freq / pre as u32; (freq, freq * 2) } };