Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| stm32:peripherals:rcc_clock [2016/02/29 13:14] – feur | stm32:peripherals:rcc_clock [2022/12/27 19:27] (current) – [Setup System Clocks] ruan | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Setup System Clocks ====== | + | ====== |
| To setup the system clocks you have to: | To setup the system clocks you have to: | ||
| Line 6: | Line 6: | ||
| * Configure the [[# | * Configure the [[# | ||
| \\ | \\ | ||
| + | |||
| + | ==== Available Oscillators ==== | ||
| + | |||
| + | |< 100% 5em 5em >| | ||
| + | ^ ^f< | ||
| + | |LSI|32 kHz|Low speed internal oscillator| | ||
| + | |LSE|32 kHz|Low speed external oscillator| | ||
| + | |HSI|16 MHz|High speed internal oscillator| | ||
| + | |HSE|8 MHz|High speed external oscillator| | ||
| + | |||
| + | ==== Available Clocks ==== | ||
| + | |||
| + | |< 100% 5em 5em >| | ||
| + | ^ ^f< | ||
| + | |PLLCLK|var.|PLL clock, used to generate all other clocks| | ||
| + | |PLL48CLK|48 MHz|PLL48 clock, used for USB or SDIO| | ||
| + | |RTCCLK|var.|RTC clock, used by real time clock| | ||
| + | |SYSCLK|168 MHz|System clock, used by CPU| | ||
| + | |HCLK|84 MHz|AHB clock, used for AHB peripherals| | ||
| + | |PCLK1|42 MHz|APB1 clock, used for APB1 peripherals| | ||
| + | |PCLK2|84 MHz|APB2 clock, used for APB2 peripherals| | ||
| + | |TCLK|84 MHz|Timer clock, used for the timers| | ||
| ===== Clock Source ===== | ===== Clock Source ===== | ||
| Line 16: | Line 38: | ||
| * Set xxxON bit of desired oscillator. | * Set xxxON bit of desired oscillator. | ||
| * Wait until xxxRDY flag is set. | * Wait until xxxRDY flag is set. | ||
| + | \\ | ||
| <code c> | <code c> | ||
| Line 40: | Line 63: | ||
| * Choose PLLN and PLLP values, so that you reach the desired system clock frequency. | * Choose PLLN and PLLP values, so that you reach the desired system clock frequency. | ||
| * If USB is used, choose PLLQ value, so that f< | * If USB is used, choose PLLQ value, so that f< | ||
| + | \\ | ||
| <code c> | <code c> | ||
| Line 46: | Line 70: | ||
| uint32_t reg; | uint32_t reg; | ||
| RCC-> | RCC-> | ||
| - | RCC-> | + | RCC-> |
| - | RCC-> | + | RCC-> |
| RCC-> | RCC-> | ||
| RCC-> | RCC-> | ||
| Line 67: | Line 91: | ||
| * Choose HPRE, maximum allowed clock on AHB is 168 MHz. | * Choose HPRE, maximum allowed clock on AHB is 168 MHz. | ||
| * Choose PPRE1, maximum allowed clock on APB1 is 42 MHz. | * Choose PPRE1, maximum allowed clock on APB1 is 42 MHz. | ||
| - | * Choose PPRE2, maximum allowed clock on APB2 is 168 MHz. | + | * Choose PPRE2, maximum allowed clock on APB2 is 84 MHz. |
| * Select input source. | * Select input source. | ||
| + | \\ | ||
| <code c> | <code c> | ||
| Line 75: | Line 100: | ||
| uint32_t reg; | uint32_t reg; | ||
| - | RCC-> | + | RCC-> |
| - | RCC-> | + | RCC-> |
| - | RCC-> | + | RCC-> |
| - | TCLK => 84 MHz * 1 => 84MHz */ | + | TCLK => |
| RCC-> | RCC-> | ||
| Line 86: | Line 111: | ||
| } | } | ||
| </ | </ | ||
| + | \\ | ||
| ===== Configuration Registers ===== | ===== Configuration Registers ===== | ||
| - | ==== CR ==== | + | ==== CR - Control register |
| - | + | ||
| - | Control register | + | |
| \\ {{clock_reg_cr.svg}} \\ \\ | \\ {{clock_reg_cr.svg}} \\ \\ | ||
| Line 105: | Line 129: | ||
| |:::|1|X ready| | |:::|1|X ready| | ||
| - | ==== PLLCFGR | + | ==== CSR - Control and status register |
| - | PLL configuration register | + | \\ {{clock_reg_csr.svg}} \\ \\ |
| + | |||
| + | |< 100% 5em 5em >| | ||
| + | |LSION|0|Internal low speed clock enabled| | ||
| + | |::: | ||
| + | |LSIRDY|0|Internal low speed clock **not** ready| | ||
| + | |::: | ||
| + | |||
| + | ==== PLLCFGR - PLL configuration register | ||
| \\ {{clock_reg_pllcfgr.svg}} \\ \\ | \\ {{clock_reg_pllcfgr.svg}} \\ \\ | ||
| Line 121: | Line 153: | ||
| * Please refer to reference manual (p.162ff) for detailed explanation of register values. \\ \\ | * Please refer to reference manual (p.162ff) for detailed explanation of register values. \\ \\ | ||
| - | ==== CFGR ==== | + | ==== CFGR - Configuration register |
| - | + | ||
| - | Configuration register | + | |
| \\ {{clock_reg_cfgr.svg}} \\ \\ | \\ {{clock_reg_cfgr.svg}} \\ \\ | ||
| |< 100% 5em 5em 15em 5em >| | |< 100% 5em 5em 15em 5em >| | ||
| - | |SW|00|HSI as SYSCLK (reset state)| | + | |SW|00|Enable |
| - | |:::|01|HSE as SYSCLK| | + | |:::|01|Enable |
| - | |:::|10|PLL as SYSCLK| | + | |:::|10|Enable |
| + | |SWS|00|HSI used as SYSCLK|| | ||
| + | |:::|01|HSE used as SYSCLK|| | ||
| + | |:::|10|PLL used as SYSCLK|| | ||
| |HPRE|0xxx|SYSCLK not divided (reset state)||| | |HPRE|0xxx|SYSCLK not divided (reset state)||| | ||
| - | |::: | + | |::: |
| - | |::: | + | |::: |
| - | |::: | + | |::: |
| - | |::: | + | |::: |
| |PPRE1|0xx|HCLK not divided (reset state)||| | |PPRE1|0xx|HCLK not divided (reset state)||| | ||
| - | |::: | + | |::: |
| - | |::: | + | |::: |
| |PPRE2*|0xx|HCLK not divided (reset state)||| | |PPRE2*|0xx|HCLK not divided (reset state)||| | ||
| - | |::: | + | |::: |
| - | |::: | + | |::: |
| - | * if PPRE2 **not** 0xx then TCLK => PCLK2 / 2 \\ \\ | + | * if PPRE2 **not** 0xx then TCLK => f<sub>PCLK2</sub> • 2 \\ \\ |