STM32CubeWBA: System Clock Manager

1 Introduction

The system clock manager (SCM) is the module that manages the CPU system clock source and frequency. It defines different users that can request different configurations. It determines which one suits the system and user needs best.

2 Features

2.1 SCM users principle

The module is based on a client request mechanism. The SCM defines (up to 32) users that can request a modification of the clock frequency. Two users are defined by default: SCM_USER_LL_FW (system user for link layer purposes) and SCM_USER_APP (application-related user).

All users have the same weight/priority.

Among the requests, the system clock manager determines the one that fulfills all the needs. The best system clock evaluation is realized at each new request.

2.2 Supported configurations

2.2.1 Overview

Supported configurations are fixed. Unlike SCM users, it is not possible to add SCM configurations over existing ones.

Each SCM configuration has a defined purpose.
The table below presents all supported configurations (in an increasing order of priority) and their use by the system.

Supported SCM configurations table
SCM configuration Purpose
HSE 16 MHz
Low priority
Nominal - no radio activity.
Requested in radio interrupt.
(Ending radio event notification from link layer.)
HSE 32 MHz Radio activity.
Requested in radio interrupt.
(Starting radio event notification from link layer.)
PLL
High priority
PLL is used for high-performance use cases (e.g. Bluetooth® Low Energy audio).


Info white.png Information
HSI as system clock source is not supported.
Info white.png Information
The SCM always selects the highest priority request (as needs with the lower ones are fulfilled).
Info white.png Information
The SCM PLL configuration is mainly used for audio use cases (the system clock change is requested inside the Bluetooth® Low Energy audio library). The PLL configuration can be requested at application level too.

2.2.2 Corresponding SoC configuration

To achieve these configurations, the SCM module is responsible for adapting several SoC-related parameters:

  • Flash memory & SRAM latency.
  • Regulator supply output voltage (VOS).
  • AHB5 divider.

They are presented per SCM configuration in the table below.

SCM-related SoC parameters table
SCM configuration Flash & SRAM latency VOS AHB5 divider
HSE 16 MHz Flash latency: 1
SRAM1/2 latencies: 1
2 2
HSE 32 MHz Flash latency: 0
SRAM1/2 latencies: 0
1 1
PLL Flash latencies: 3
SRAM1/2 latency: 0
1 1

2.3 PLL usage

PLL usage and configuration are defined as follows:

  • The PLL source is always HSE 32 MHz.
  • If there is one global PLL configuration for SCM, the PLL parameters (PLL mode, PLL multiplier, and dividers) can be adapted to the user needs with dedicated interfaces. Refer to the PLL management interfaces section for more information.

2.4 Low-power management

The SCM module is used in low-power management for both low-power entry and exit.

  • For low-power-mode entry (Stop1 or Standby), the SCM interface scm_setwaitstates(LP) is used for adapting the flash memory & SRAM latencies.
  • For low-power-mode exit (Stop1 and Standby), the SCM interface scm_setup() is used for applying the system clock configuration used before low-power entry. Regarding Standby-mode exit, the PLL configuration is reapplied (even if not used at that time) because the PLL registers have been reset.

2.5 SCM configuration update

On the one hand, decreasing the clock speed is handled immediately.
On the other hand, increasing the clock speed requires more time to set up (enabling the oscillators, propagation delays, PLL lock, etc.). To ensure system performance and radio activity timing, the SCM implements an interrupt-based mechanism.

Indeed, when the system clock source has to be changed, the targeted oscillator (HSE or PLL) is enabled alongside dedicated RCC ready flags. The other part of the system clock configuration is done in the RCC interrupts directly when the clock is ready. This allows the firmware to continue running with the actual clock source and speed until the targeted clock is ready.

The SCM handles two RCC interrupts:

  • RCC HSE ready flag (raised just after low-power-mode exit, with the system clock on HSI 16 MHz).
  • RCC PLL ready flag (always raised when the system clock is on HSE, because HSE is the PLL source clock).

2.6 SCM concept summary

The following diagram summarizes the SCM module:

System clock manager concept summary

3 Interfaces

3.1 SCM users

The available SCM users are listed in the table below.

SCM users table
SCM user Description
SCM_USER_LL_FW Link-layer system user.
Requests system clock changes on radio, starting/ending radio activity.
SCM_USER_APP Application-related user.
Requests system clock changes for application needs.
Info white.png Information
The customer can add up to 30 new SCM users (for 32 users in total) if necessary.

3.2 SCM functions

3.2.1 General interfaces

scm_init

Description

Initialize the system clock manager module.
Syntax
void scm_init(void);
Parameters
None
Return Value
None
scm_setsystemclock

Description

Request a system clock configuration (clock source and frequency) change.
Syntax
void scm_setsystemclock (scm_user_id_t user_id, scm_clockconfig_t sysclockconfig);
Parameters
[in] user_id
Type: scm_user_id_t
Description: SCM user that requests the change
[in] sysclockconfig
Type: scm_clockconfig_t
Description: Requested SCM configuration
Return Value
None
scm_setwaitstates

Description

Configure the flash memory and SRAM wait states (when required for a system clock source change).
Syntax
void scm_setwaitstates(const scm_ws_lp_t ws_lp_config);
Parameters
[in] ws_lp_config
Type: const scm_ws_lp_t
Description: Flash memory and SRAM wait cycle configuration
Return Value
None
scm_notifyradiostate

Description

Notify the SCM of the state of the radio.
Syntax
void scm_notifyradiostate(const scm_radio_state_t radio_state);
Parameters
[in] radio_state
Type: scm_radio_state_t
Description: State of the radio (active or inactive).
Return Value
None

3.2.2 Low-power management

scm_setup

Description

Set up the system clock source in a usable configuration for connectivity use cases. Called at startup or when coming out of low-power modes.
Syntax
void scm_setup(void);
Parameters
None
Return Value
None
scm_standbyexit

Description

Restore the system clock configuration when moving out of standby.
Syntax
void scm_standbyexit(void);
Parameters
None
Return Value
None

3.2.3 PLL management

scm_pll_setconfig

Description

Configure the PLL mode and parameters before selecting PLL as system clock.
Syntax
void scm_pll_setconfig(const scm_pll_config_t *p_pll_config);
Parameters
[in] p_pll_config
Type: scm_pll_config_t
Description: PLL configuration to apply
Return Value
None
scm_pll_fractional_update

Description

Configure the PLL for switching fractional parameters on the fly.
Syntax
void scm_pll_fractional_update(uint32_t pll_frac);
Parameters
[in] pll_frac
Type: uint32_t
Description: Up-to-date fractional configuration
Return Value
None
scm_pllready

Description

Called each time the PLL is ready.

This function is defined as weak in the SCM module and can be overridden by the user.

Syntax
void scm_pllconfigready(void);
Parameters
None
Return Value
None

3.2.4 RCC ISR handling

scm_hserdy_isr

Description

SCM HSERDY interrupt hander. Switch the system clock to HSE.
Syntax
void scm_hserdy_isr(void);
Parameters
None
Return Value
None
scm_pllrdy_isr

Description

SCM PLLRDY interrupt hander. Switch the system clock to PLL.
Syntax
void scm_pllrdy_isr(void);
Parameters
None
Return Value
None

4 How to

4.1 Initialize the SCM

To initialize the SCM module, the scm_init function has to be called before any connectivity host stack initializations (this sets up the link layer). scm_init is responsible for retrieving the current system clock configuration (which is done in the common HAL function SystemClock_Config, in the main.c file) to set up the internal context.

From this point on, users can request system clock changes.

4.2 Request a system clock change

To request a system clock change with the SCM, the only function to call is scm_setsystemclock. This function takes two parameters:

  • The SCM user making the request.
  • The configuration to apply.
Warning white.png Important
Before requesting a system clock change to PLL with scm_setsystemclock(, SYS_PLL), the PLL mode and parameters must be configured through scm_pll_setconfig.