Topics / RCC
Topic

RCC Reset and clock control

Where every clock comes from: oscillators, PLLs, bus prescalers, and the on/off switch of each peripheral.

What it is

The RCC decides how fast everything runs and which peripherals are powered at all. It picks a clock source (HSI inside the chip, or HSE from the board’s 25 MHz oscillator), multiplies it with a PLL, divides it down for the buses, and feeds each peripheral.

Two things from this chapter matter on day one. After reset every peripheral’s clock is off, so you enable it in an RCC_xxxENR register before touching the peripheral. And many peripherals (UART, ADC, SPI…) have a separate kernel clock chosen in an RCC_DxCCIPxR register; that clock, not the CPU clock, sets their baud rate or sample rate.

You need it for
  • Switching on the clock of a peripheral before you use it
  • Running the CPU faster than the 64 MHz it starts with (up to 480 MHz)
  • Choosing the kernel clock that sets a UART baud rate or an ADC conversion rate
  • Finding out the bus clock a timer or peripheral actually receives

Read in this order

The shortest path through the documents. Each link opens the exact page; the line under it says what to look for.

  1. RM04338.1 RCC main featuresp.325What the RCC controls, on one page
  2. RM0433Figure 45. Top-level clock treep.337The clock tree figure: keep it open while you configure anything
  3. RM04338.5.11 Peripheral clock gating controlp.373Why peripherals start unclocked and how the enable bits work
  4. RM04338.5.2 Oscillators descriptionp.338HSI, HSE (and bypass), LSE, CSI: the possible sources
  5. RM04338.5.5 PLL descriptionp.345How M, N, P, Q, R turn 25 MHz into 480 MHz
  6. RM04338.5.8 Kernel clock selectionp.353Which clock each peripheral’s kernel can use
  7. UM24886.5 Clock sourcesp.13The board side: a 25 MHz oscillator (X1) and a 32.768 kHz crystal (X2)

Registers to learn first

In the order you usually program them. The other 46 registers of the chapter can wait until you need them.

1RCC_AHB4ENRClock enables for GPIO ports A–K (and other AHB4 peripherals)p.457
2RCC_APB1LENRClock enables for APB1 peripherals: USART2/3, UART4/5/7/8, TIM2–7, I2C1–3…p.461
3RCC_APB2ENRClock enables for APB2 peripherals: USART1/6, TIM1/8, TIM15–17, SPI1/4/5…p.467
4RCC_CRSwitch oscillators and PLLs on, and wait for their ready flagsp.382
5RCC_PLLCKSELRPLL source (HSI/CSI/HSE) and the input divider Mp.397
6RCC_PLL1DIVRPLL1 multiplier N and output dividers P, Q, Rp.402
7RCC_D1CFGRPrescalers for the CPU, AXI/AHB and APB3 busesp.393
8RCC_D2CFGRPrescalers for APB1 and APB2 (they also set the timer clocks)p.395
9RCC_CFGRSystem clock switch: HSI, CSI, HSE or PLL1p.390
10RCC_D2CCIP2RKernel clock choice for USARTs, I2C, RNG, USB…p.415
All 56 registers in Reset and Clock Control (RCC)

Map of the chapter

Every reference-manual chapter has the same shape. Sections marked ● are in the reading order above.

Common mistakes

  • Writing a peripheral’s registers before enabling its clock. The writes are ignored and reading back gives 0.
  • Raising the CPU clock without first raising the flash wait states (FLASH_ACR) and the voltage scale. The chip crashes on the next flash read.
  • Computing a baud rate from the CPU clock. USARTs use their kernel clock, chosen in RCC_D2CCIP2R.
  • Forgetting that a timer clock is doubled when its APB prescaler is not 1. Check the timer clock rule in the RCC chapter.

Where to go next