STM32 RTOS 0.2.3
Bare-metal preemptive RTOS for STM32F446RE
Loading...
Searching...
No Matches
rcc_reg.h File Reference

RCC registers: oscillators, PLL, bus clocks, peripheral clock gating and reset flags (RM0390 section 6.3). More...

#include <stdint.h>
Include dependency graph for rcc_reg.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  RccRegisters_t
 RCC register block. More...

Macros

#define RCC_BASE   (0x40023800UL)
 RCC base address (AHB1).
#define RCC   ((RccRegisters_t *)RCC_BASE)
 The RCC instance.
CR - clock control (0x00)
#define RCC_CR_HSION_Pos   (0U)
 Bit 0.
#define RCC_CR_HSION   ((uint32_t)1U << RCC_CR_HSION_Pos)
  rw HSI on.
#define RCC_CR_HSIRDY_Pos   (1U)
 Bit 1.
#define RCC_CR_HSIRDY   ((uint32_t)1U << RCC_CR_HSIRDY_Pos)
  ro HSI ready.
#define RCC_CR_HSEON_Pos   (16U)
 Bit 16.
#define RCC_CR_HSEON   ((uint32_t)1U << RCC_CR_HSEON_Pos)
  rw HSE on.
#define RCC_CR_HSERDY_Pos   (17U)
 Bit 17.
#define RCC_CR_HSERDY   ((uint32_t)1U << RCC_CR_HSERDY_Pos)
  ro HSE ready.
#define RCC_CR_HSEBYP_Pos   (18U)
 Bit 18.
#define RCC_CR_HSEBYP   ((uint32_t)1U << RCC_CR_HSEBYP_Pos)
  rw HSE bypass: external clock on OSC_IN.
#define RCC_CR_CSSON_Pos   (19U)
 Bit 19.
#define RCC_CR_CSSON   ((uint32_t)1U << RCC_CR_CSSON_Pos)
  rw Clock security system on.
#define RCC_CR_PLLON_Pos   (24U)
 Bit 24.
#define RCC_CR_PLLON   ((uint32_t)1U << RCC_CR_PLLON_Pos)
  rw Main PLL on.
#define RCC_CR_PLLRDY_Pos   (25U)
 Bit 25.
#define RCC_CR_PLLRDY   ((uint32_t)1U << RCC_CR_PLLRDY_Pos)
  ro Main PLL locked.
PLLCFGR - PLL configuration (0x04)

Every field is rw and writable only while the PLL is off.

#define RCC_PLLCFGR_PLLM_Pos   (0U)
 Bits 5:0.
#define RCC_PLLCFGR_PLLM_Msk   ((uint32_t)0x3FU << RCC_PLLCFGR_PLLM_Pos)
 Input divider M (2-63): VCO input = source / M, 1-2 MHz.
#define RCC_PLLCFGR_PLLN_Pos   (6U)
 Bits 14:6.
#define RCC_PLLCFGR_PLLN_Msk   ((uint32_t)0x1FFU << RCC_PLLCFGR_PLLN_Pos)
 Multiplier N (50-432): VCO output = VCO input x N, 100-432 MHz.
#define RCC_PLLCFGR_PLLP_Pos   (16U)
 Bits 17:16.
#define RCC_PLLCFGR_PLLP_Msk   ((uint32_t)0x3U << RCC_PLLCFGR_PLLP_Pos)
 Output divider P for SYSCLK; values below.
#define RCC_PLLCFGR_PLLSRC_Pos   (22U)
 Bit 22.
#define RCC_PLLCFGR_PLLSRC   ((uint32_t)1U << RCC_PLLCFGR_PLLSRC_Pos)
 PLL input: 0 = HSI, 1 = HSE.
PLLCFGR.PLLSRC values

Already shifted into position.

#define RCC_PLLCFGR_PLLSRC_HSI   (0x0U)
 HSI feeds the PLL.
#define RCC_PLLCFGR_PLLSRC_HSE   (RCC_PLLCFGR_PLLSRC)
 HSE feeds the PLL.
PLLCFGR.PLLP values
#define RCC_PLLCFGR_PLLP_DIV2   (0x0U)
 VCO / 2.
#define RCC_PLLCFGR_PLLP_DIV4   (0x1U)
 VCO / 4.
#define RCC_PLLCFGR_PLLP_DIV6   (0x2U)
 VCO / 6.
#define RCC_PLLCFGR_PLLP_DIV8   (0x3U)
 VCO / 8.
CFGR - clock configuration (0x08)
#define RCC_CFGR_SW_Pos   (0U)
 Bits 1:0.
#define RCC_CFGR_SW_Msk   ((uint32_t)0x3U << RCC_CFGR_SW_Pos)
  rw SYSCLK source requested; values below.
#define RCC_CFGR_SWS_Pos   (2U)
 Bits 3:2.
#define RCC_CFGR_SWS_Msk   ((uint32_t)0x3U << RCC_CFGR_SWS_Pos)
  ro SYSCLK source in use, reported once a switch completes.
#define RCC_CFGR_HPRE_Pos   (4U)
 Bits 7:4.
#define RCC_CFGR_HPRE_Msk   ((uint32_t)0xFU << RCC_CFGR_HPRE_Pos)
  rw AHB prescaler; values below.
#define RCC_CFGR_PPRE1_Pos   (10U)
 Bits 12:10.
#define RCC_CFGR_PPRE1_Msk   ((uint32_t)0x7U << RCC_CFGR_PPRE1_Pos)
  rw APB1 prescaler; APB1 must stay at or below 45 MHz.
#define RCC_CFGR_PPRE2_Pos   (13U)
 Bits 15:13.
#define RCC_CFGR_PPRE2_Msk   ((uint32_t)0x7U << RCC_CFGR_PPRE2_Pos)
  rw APB2 prescaler; APB2 must stay at or below 90 MHz.
CFGR.SW / CFGR.SWS values

One encoding for both fields; shift by the field's _Pos.

#define RCC_CFGR_SYSCLK_HSI   (0x0U)
 HSI.
#define RCC_CFGR_SYSCLK_HSE   (0x1U)
 HSE.
#define RCC_CFGR_SYSCLK_PLL   (0x2U)
 Main PLL (P output).
CFGR.HPRE values

There is no /32.

#define RCC_CFGR_HPRE_DIV1   (0x0U)
 SYSCLK / 1.
#define RCC_CFGR_HPRE_DIV2   (0x8U)
 SYSCLK / 2.
#define RCC_CFGR_HPRE_DIV4   (0x9U)
 SYSCLK / 4.
#define RCC_CFGR_HPRE_DIV8   (0xAU)
 SYSCLK / 8.
#define RCC_CFGR_HPRE_DIV16   (0xBU)
 SYSCLK / 16.
#define RCC_CFGR_HPRE_DIV64   (0xCU)
 SYSCLK / 64.
#define RCC_CFGR_HPRE_DIV128   (0xDU)
 SYSCLK / 128.
#define RCC_CFGR_HPRE_DIV256   (0xEU)
 SYSCLK / 256.
#define RCC_CFGR_HPRE_DIV512   (0xFU)
 SYSCLK / 512.
CFGR.PPRE1 / CFGR.PPRE2 values

One encoding for both fields; shift by the field's _Pos.

#define RCC_CFGR_PPRE_DIV1   (0x0U)
 HCLK / 1.
#define RCC_CFGR_PPRE_DIV2   (0x4U)
 HCLK / 2.
#define RCC_CFGR_PPRE_DIV4   (0x5U)
 HCLK / 4.
#define RCC_CFGR_PPRE_DIV8   (0x6U)
 HCLK / 8.
#define RCC_CFGR_PPRE_DIV16   (0x7U)
 HCLK / 16.
CIR - clock interrupt (0x0C)
#define RCC_CIR_CSSF_Pos   (7U)
 Bit 7.
#define RCC_CIR_CSSF   ((uint32_t)1U << RCC_CIR_CSSF_Pos)
  ro Clock security system detected an HSE failure.
#define RCC_CIR_CSSC_Pos   (23U)
 Bit 23.
#define RCC_CIR_CSSC   ((uint32_t)1U << RCC_CIR_CSSC_Pos)
  wo Write 1 to clear CSSF.
AHB1RSTR - AHB1 peripheral reset (0x10)

Every bit is rw: set to hold the peripheral in reset.

#define RCC_AHB1RSTR_GPIOARST_Pos   (0U)
 Bit 0.
#define RCC_AHB1RSTR_GPIOARST   ((uint32_t)1U << RCC_AHB1RSTR_GPIOARST_Pos)
 GPIOA reset.
#define RCC_AHB1RSTR_GPIOBRST_Pos   (1U)
 Bit 1.
#define RCC_AHB1RSTR_GPIOBRST   ((uint32_t)1U << RCC_AHB1RSTR_GPIOBRST_Pos)
 GPIOB reset.
#define RCC_AHB1RSTR_GPIOCRST_Pos   (2U)
 Bit 2.
#define RCC_AHB1RSTR_GPIOCRST   ((uint32_t)1U << RCC_AHB1RSTR_GPIOCRST_Pos)
 GPIOC reset.
#define RCC_AHB1RSTR_GPIODRST_Pos   (3U)
 Bit 3.
#define RCC_AHB1RSTR_GPIODRST   ((uint32_t)1U << RCC_AHB1RSTR_GPIODRST_Pos)
 GPIOD reset.
#define RCC_AHB1RSTR_GPIOERST_Pos   (4U)
 Bit 4.
#define RCC_AHB1RSTR_GPIOERST   ((uint32_t)1U << RCC_AHB1RSTR_GPIOERST_Pos)
 GPIOE reset.
#define RCC_AHB1RSTR_GPIOFRST_Pos   (5U)
 Bit 5.
#define RCC_AHB1RSTR_GPIOFRST   ((uint32_t)1U << RCC_AHB1RSTR_GPIOFRST_Pos)
 GPIOF reset.
#define RCC_AHB1RSTR_GPIOGRST_Pos   (6U)
 Bit 6.
#define RCC_AHB1RSTR_GPIOGRST   ((uint32_t)1U << RCC_AHB1RSTR_GPIOGRST_Pos)
 GPIOG reset.
#define RCC_AHB1RSTR_GPIOHRST_Pos   (7U)
 Bit 7.
#define RCC_AHB1RSTR_GPIOHRST   ((uint32_t)1U << RCC_AHB1RSTR_GPIOHRST_Pos)
 GPIOH reset.
AHB1ENR - AHB1 clock enable (0x30)

Every bit is rw.

Read the register back after enabling, before touching the peripheral.

#define RCC_AHB1ENR_GPIOAEN_Pos   (0U)
 Bit 0.
#define RCC_AHB1ENR_GPIOAEN   ((uint32_t)1U << RCC_AHB1ENR_GPIOAEN_Pos)
 GPIOA clock.
#define RCC_AHB1ENR_GPIOBEN_Pos   (1U)
 Bit 1.
#define RCC_AHB1ENR_GPIOBEN   ((uint32_t)1U << RCC_AHB1ENR_GPIOBEN_Pos)
 GPIOB clock.
#define RCC_AHB1ENR_GPIOCEN_Pos   (2U)
 Bit 2.
#define RCC_AHB1ENR_GPIOCEN   ((uint32_t)1U << RCC_AHB1ENR_GPIOCEN_Pos)
 GPIOC clock.
#define RCC_AHB1ENR_GPIODEN_Pos   (3U)
 Bit 3.
#define RCC_AHB1ENR_GPIODEN   ((uint32_t)1U << RCC_AHB1ENR_GPIODEN_Pos)
 GPIOD clock.
#define RCC_AHB1ENR_GPIOEEN_Pos   (4U)
 Bit 4.
#define RCC_AHB1ENR_GPIOEEN   ((uint32_t)1U << RCC_AHB1ENR_GPIOEEN_Pos)
 GPIOE clock.
#define RCC_AHB1ENR_GPIOFEN_Pos   (5U)
 Bit 5.
#define RCC_AHB1ENR_GPIOFEN   ((uint32_t)1U << RCC_AHB1ENR_GPIOFEN_Pos)
 GPIOF clock.
#define RCC_AHB1ENR_GPIOGEN_Pos   (6U)
 Bit 6.
#define RCC_AHB1ENR_GPIOGEN   ((uint32_t)1U << RCC_AHB1ENR_GPIOGEN_Pos)
 GPIOG clock.
#define RCC_AHB1ENR_GPIOHEN_Pos   (7U)
 Bit 7.
#define RCC_AHB1ENR_GPIOHEN   ((uint32_t)1U << RCC_AHB1ENR_GPIOHEN_Pos)
 GPIOH clock.
APB1RSTR - APB1 peripheral reset (0x20)

Every bit is rw.

#define RCC_APB1RSTR_USART2RST_Pos   (17U)
 Bit 17.
#define RCC_APB1RSTR_USART2RST   ((uint32_t)1U << RCC_APB1RSTR_USART2RST_Pos)
 USART2 reset.
#define RCC_APB1RSTR_PWRRST_Pos   (28U)
 Bit 28.
#define RCC_APB1RSTR_PWRRST   ((uint32_t)1U << RCC_APB1RSTR_PWRRST_Pos)
 PWR reset.
APB1ENR - APB1 clock enable (0x40)

Every bit is rw.

#define RCC_APB1ENR_WWDGEN_Pos   (11U)
 Bit 11.
#define RCC_APB1ENR_WWDGEN   ((uint32_t)1U << RCC_APB1ENR_WWDGEN_Pos)
 WWDG clock; required before any WWDG register access.
#define RCC_APB1ENR_USART2EN_Pos   (17U)
 Bit 17.
#define RCC_APB1ENR_USART2EN   ((uint32_t)1U << RCC_APB1ENR_USART2EN_Pos)
 USART2 clock.
#define RCC_APB1ENR_PWREN_Pos   (28U)
 Bit 28.
#define RCC_APB1ENR_PWREN   ((uint32_t)1U << RCC_APB1ENR_PWREN_Pos)
 PWR clock; required before any PWR register access.
APB2RSTR - APB2 peripheral reset (0x24)
#define RCC_APB2RSTR_SYSCFGRST_Pos   (14U)
 Bit 14.
#define RCC_APB2RSTR_SYSCFGRST   ((uint32_t)1U << RCC_APB2RSTR_SYSCFGRST_Pos)
  rw SYSCFG reset.
APB2ENR - APB2 clock enable (0x44)
#define RCC_APB2ENR_SYSCFGEN_Pos   (14U)
 Bit 14.
#define RCC_APB2ENR_SYSCFGEN   ((uint32_t)1U << RCC_APB2ENR_SYSCFGEN_Pos)
  rw SYSCFG clock; required before any SYSCFG register access.
CSR - clock control and status (0x74)

The reset-cause flags stay set until RMVF clears them.

#define RCC_CSR_LSION_Pos   (0U)
 Bit 0.
#define RCC_CSR_LSION   ((uint32_t)1U << RCC_CSR_LSION_Pos)
  rw LSI on.
#define RCC_CSR_LSIRDY_Pos   (1U)
 Bit 1.
#define RCC_CSR_LSIRDY   ((uint32_t)1U << RCC_CSR_LSIRDY_Pos)
  ro LSI ready.
#define RCC_CSR_RMVF_Pos   (24U)
 Bit 24.
#define RCC_CSR_RMVF   ((uint32_t)1U << RCC_CSR_RMVF_Pos)
  rw Write 1 to clear every reset flag below.
#define RCC_CSR_BORRSTF_Pos   (25U)
 Bit 25.
#define RCC_CSR_BORRSTF   ((uint32_t)1U << RCC_CSR_BORRSTF_Pos)
  ro Brown-out reset occurred.
#define RCC_CSR_PINRSTF_Pos   (26U)
 Bit 26.
#define RCC_CSR_PINRSTF   ((uint32_t)1U << RCC_CSR_PINRSTF_Pos)
  ro NRST pin reset occurred.
#define RCC_CSR_PORRSTF_Pos   (27U)
 Bit 27.
#define RCC_CSR_PORRSTF   ((uint32_t)1U << RCC_CSR_PORRSTF_Pos)
  ro Power-on reset occurred.
#define RCC_CSR_SFTRSTF_Pos   (28U)
 Bit 28.
#define RCC_CSR_SFTRSTF   ((uint32_t)1U << RCC_CSR_SFTRSTF_Pos)
  ro Software reset occurred.
#define RCC_CSR_IWDGRSTF_Pos   (29U)
 Bit 29.
#define RCC_CSR_IWDGRSTF   ((uint32_t)1U << RCC_CSR_IWDGRSTF_Pos)
  ro Independent watchdog reset occurred.
#define RCC_CSR_WWDGRSTF_Pos   (30U)
 Bit 30.
#define RCC_CSR_WWDGRSTF   ((uint32_t)1U << RCC_CSR_WWDGRSTF_Pos)
  ro Window watchdog reset occurred.
#define RCC_CSR_LPWRRSTF_Pos   (31U)
 Bit 31.
#define RCC_CSR_LPWRRSTF   ((uint32_t)1U << RCC_CSR_LPWRRSTF_Pos)
  ro Low-power reset occurred.

Typedefs

typedef struct RccRegisters_t RccRegisters_t
 RCC register block.

Detailed Description

RCC registers: oscillators, PLL, bus clocks, peripheral clock gating and reset flags (RM0390 section 6.3).

Modelled: what HSI/HSE-to-PLL bring-up and GPIO/USART2/SYSCFG/PWR clock gating need. Not modelled: PLLQ (the 48 MHz USB/SDIO output) and the CFGR MCO, RTCPRE and I2SSRC fields.

Definition in file rcc_reg.h.