-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Description
Describe the bug
Environment
- Board: STM32WB5MMG-DK
- Zephyr version: v4.1.0
- SoC: STM32WB55
- Architecture: ARM Cortex-M4
Bug Description
When configuring the STM32WB55 with PLL as the system clock source at 64MHz, UART baud rate calculations are incorrect and don't respect the APB2 prescaler setting. The actual UART baud rate is double the configured current-speed
value when cpu1-prescaler = <1>
, and the apb2-prescaler
setting has no effect on the actual baud rate.
Expected Clock Tree Configuration
According to STM32CubeIDE clock tree analysis, with the following configuration:
- SYSCLK: 64MHz (from PLL)
- HCLK1: 64MHz (
cpu1-prescaler = <1>
) - APB2: 64MHz (
apb2-prescaler = <1>
) - USART1 Clock: Should be 64MHz (from APB2)
Device Tree Configuration
&pll {
div-m = <2>;
mul-n = <8>;
div-q = <2>;
div-r = <2>;
clocks = <&clk_hse>;
status = "okay";
};
&rcc {
clocks = <&pll>;
clock-frequency = <DT_FREQ_M(64)>;
cpu1-prescaler = <1>;
cpu2-prescaler = <2>;
ahb4-prescaler = <1>;
apb1-prescaler = <1>;
apb2-prescaler = <1>;
};
&usart1 {
pinctrl-0 = <&usart1_tx_pb6 &usart1_rx_pb7>;
pinctrl-names = "default";
current-speed = <115200>;
status = "okay";
};
Problem Details
Current Behavior:
- With
cpu1-prescaler = <1>
andapb2-prescaler = <1>
: Actual baud rate is ~230400 (double the configured 115200) - With
cpu1-prescaler = <2>
andapb2-prescaler = <1>
: Actual baud rate matches 115200 - Changing
apb2-prescaler
to<2>
,<4>
, etc. has no effect on actual baud rate
Expected Behavior:
- Changing
apb2-prescaler
should directly affect the UART clock and thus the baud rate - The actual baud rate should match the
current-speed
property
Clock Tree Analysis
Expected clock flow:
PLL (64MHz) → SYSCLK (64MHz) → HCLK1 (64MHz ÷ cpu1-prescaler) → APB2 (HCLK1 ÷ apb2-prescaler) → USART1
Current (incorrect) behavior suggests:
PLL (64MHz) → SYSCLK (64MHz) → USART1 (ignoring APB2 prescaler)
Root Cause Analysis
The issue appears to be in the STM32WB clock driver where:
- The UART clock calculation doesn't properly account for APB2 prescaler
- The driver may be using SYSCLK or HCLK1 directly instead of the properly prescaled APB2 clock
- This affects all APB2-connected peripherals, not just UART
Workaround
Currently, the only workaround is to adjust the current-speed
to compensate:
&usart1 {
pinctrl-0 = <&usart1_tx_pb6 &usart1_rx_pb7>;
pinctrl-names = "default";
current-speed = <57600>; // The effective baud rate is 115200
status = "okay";
};
Impact
This bug affects:
- UART/USART peripherals on APB2 bus (USART1)
- Potentially other APB2 peripherals that depend on accurate clock calculations
- System timing accuracy when precise baud rates are required
Additional Information
- The issue is specific to STM32WB series when using PLL clock source
- This suggests the bug is in Zephyr's STM32WB clock driver implementation
Files Likely Affected
drivers/clock_control/clock_stm32_ll_wb.c
- uart_stm32.c (UART clock source selection)
Regression
- This is a regression.
Steps to reproduce
- Configure STM32WB5MMG-DK with PLL clock source at 64MHz
- Set
cpu1-prescaler = <1>
andapb2-prescaler = <1>
- Configure USART1 with
current-speed = <115200>
- Measure actual baud rate - it will be ~230400 instead of 115200
- Change
apb2-prescaler
to<2>
- actual baud rate remains unchanged - Change
cpu1-prescaler
to<2>
- actual baud rate becomes correct 115200
Relevant log output
Impact
Annoyance – Minor irritation; no significant impact on usability or functionality.
Environment
- Board: STM32WB5MMG-DK
- Zephyr version: v4.1.0
- SoC: STM32WB55
- Architecture: ARM Cortex-M4
Additional Context
No response