Skip to content

variant(wb55): run STeaMi at 64 MHz from the main PLL - #3126

Open
nedseb wants to merge 1 commit into
stm32duino:mainfrom
nedseb:variant/steami-64mhz
Open

nedseb wants to merge 1 commit into
stm32duino:mainfrom
nedseb:variant/steami-64mhz

Conversation

@nedseb

@nedseb nedseb commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #2526, which added the STeaMi board (STEAM32_WB55RG).

If I read SystemClock_Config() correctly, the variant enables the main PLL (HSI16 / 2 x 16 / 2 = 64 MHz) but selects HSE as SYSCLK, so the core runs at 32 MHz and the PLL output is not used. This PR feeds the PLL from HSE / 2 = 16 MHz (N = 8, R = 2) and selects it as SYSCLK, so the core runs at 64 MHz. CPU2 stays at 32 MHz (HCLK2 divider 2), and the flash latency goes from 1 to 3 wait states. Only SystemClock_Config() of this variant changes.

This PR fixes/implements the following bugs/features

  • Feature: run the STeaMi core at 64 MHz (the STM32WB55 maximum).
  • Bug, I think a small one: anything clocked by PLLSAI1, which shares the PLL input (here the PDM microphone on SAI1), followed the HSI16 tolerance; it now follows the HSE crystal.

Motivation

The current configuration has two effects:

  1. The core runs at half the speed it could. The variant already selects voltage range 1 and turns the PLL on, but does not use it. The P-NUCLEO-WB55 variant also ran at 64 MHz (MSI PLL, HCLK2 / 2, 3 WS) until enabling IPCC module of the stm32WB55 #1191 switched it to HSE at 32 MHz when BLE support was added. I could not find the reason in the PR, so I may be missing a constraint, but BLE works the same at 64 MHz on this board (BLE.begin() and a scan), as it does under MicroPython.
  2. The main PLL and PLLSAI1 share one input (PLLSRC and PLLM). The STeaMi has a PDM microphone on SAI1; its driver (in the board library, not in the core) sets PLLSAI1 to 128 MHz VCO / 2 = 64 MHz from that shared input, so its sample rate followed HSI16. Measured against the LSE crystal, it was 532 to 632 ppm above 16 kHz; with this change it is 79 ppm below, close to the HSE crystal's own offset against the LSE (-77 ppm).

The settings are the same as STM32WB5MM_DK (HSE / 2 = 16 MHz, N = 8, R = 2, HCLK2 / 2, 3 WS). A 16 MHz input is what the HAL recommends to limit PLL jitter (stm32wbxx_hal_rcc.h), and it still lets PLLSAI1 give 64 MHz to SAI1 with an integer N (8).

The STeaMi MicroPython firmware (steamicc/micropython-steami, ports/stm32/powerctrlboot.c) already runs this board at 64 MHz from an HSE-fed PLL, with CPU2 at 32 MHz and 3 wait states, together with the BLE stack and the microphone.

Other clocks (HSE for the radio and SMPS, HSI16 for LPUART1 / Serial, HSI48 for USB and RNG, LSE) and the CPU2 semaphores are unchanged. As far as I can see, I2C, SPI, HardwareTimer and tone() compute their dividers at run time, so they should follow the new bus clocks.

Validation

Measured on a STeaMi V1c (STM32WB55RG), with the same tests at 32 MHz (before) and 64 MHz (after):

32 MHz (before) 64 MHz (after)
SYSCLK, source, flash latency 32 MHz, HSE, 1 WS 64 MHz, PLL, 3 WS
CPU2 clock (HAL_RCC_GetHCLK2Freq()) 32 MHz 32 MHz
CRC-32 over a RAM buffer (flash-bound code gains less) 352.7 ms 176.2 ms
PDM to PCM filter load (microphone) 17.1 % of the CPU 9.4 % of the CPU
PDM sample rate error from 16 kHz (vs LSE) +532 to +632 ppm (varies between runs) -79 ppm (both runs)
Hardware test suites (21 suites, 132 cases: sensors, screens, LED, buzzer, microphone, BLE) 108 pass the same 108 pass
Wake-up from Stop 2, Sleep and Low-power sleep (42 tests) 0 failures 0 failures

One thing that might look like a regression: in full duplex at 921600 baud (an echo sketch), the host sometimes receives a 64-byte block twice at 64 MHz. This is #3125: with a 128-byte TX buffer the copies become 128 bytes, and with an atomic write() they disappear.

Sketch to check the clock tree:

void setup() {
  Serial.begin(115200);
  delay(1000);
  Serial.print("SystemCoreClock: ");
  Serial.println(SystemCoreClock);
  Serial.print("SYSCLK source (2 HSE, 3 PLL): ");
  Serial.println((RCC->CFGR & RCC_CFGR_SWS) >> RCC_CFGR_SWS_Pos);
  Serial.print("Flash latency (WS): ");
  Serial.println(FLASH->ACR & FLASH_ACR_LATENCY);
  Serial.print("HCLK2 (CPU2): ");
  Serial.println(HAL_RCC_GetHCLK2Freq());
  Serial.print("PLL source (2 HSI16, 3 HSE): ");
  Serial.println((RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) >> RCC_PLLCFGR_PLLSRC_Pos);
}

void loop() {}

SystemClock_Config() enabled the main PLL (HSI16 / 2 x 16 / 2 =
64 MHz) but selected HSE as SYSCLK, so the core ran at 32 MHz and
the PLL output was unused.

Feed the PLL from HSE / 2 = 16 MHz (N = 8, R = 2) and select it as
SYSCLK: HCLK1, HCLK4, PCLK1 and PCLK2 run at 64 MHz, HCLK2 (CPU2)
stays at 32 MHz (divider 2), with 3 flash wait states.

The PLL input is shared with PLLSAI1, which clocks the PDM
microphone on SAI1. It now comes from the HSE crystal instead of
HSI16, and 16 MHz still divides 128 MHz, so PLLSAI1 can give 64 MHz
to SAI1 with N = 8.

Signed-off-by: Sébastien Nedjar <sebastien.nedjar@univ-amu.fr>
@nedseb
nedseb marked this pull request as ready for review November 30, 2026 02:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant