modm API documentation
modm::platform::Rcc Class Reference

#include <modm/platform/clock/rcc.hpp>

Classes

struct  PllConfig
 

Public Types

enum  HsiPrescaler : uint8_t {
  Div1 = 0b000, Div2 = 0b001, Div4 = 0b010, Div8 = 0b011,
  Div16 = 0b100, Div32 = 0b101, Div64 = 0b110, Div128 = 0b111
}
 
enum  LseDrive : uint8_t { Low = 0b00, MediumLow = 0b01, MediumHigh = 0b10, High = 0b11 }
 
enum  PllSource : uint8_t { Disabled = 0b00, Hsi16 = 0b10, Hse = 0b11 }
 
enum  AhbPrescaler : uint8_t {
  Div1 = 0b0000, Div2 = 0b1000, Div4 = 0b1001, Div8 = 0b1010,
  Div16 = 0b1011, Div64 = 0b1100, Div128 = 0b1101, Div256 = 0b1110,
  Div512 = 0b1111
}
 
enum  ApbPrescaler : uint8_t {
  Div1 = 0b000, Div2 = 0b100, Div4 = 0b101, Div8 = 0b110,
  Div16 = 0b111
}
 
enum  SystemClockSource : uint8_t {
  HsiSys = 0b000, Hse = 0b001, PllR = 0b010, Lsi = 0b011,
  Lse = 0b100
}
 
enum  RealTimeClockSource : uint32_t { Disabled = 0, Lse = 0b01 << RCC_BDCR_RTCSEL_Pos, Lsi = 0b10 << RCC_BDCR_RTCSEL_Pos, HseDiv32 = 0b11 << RCC_BDCR_RTCSEL_Pos }
 
enum  UartClockSource : uint8_t { Bus = 0b00, SysClk = 0b01, Hsi16 = 0b10, Lse = 0b11 }
 
enum  I2cClockSource : uint8_t { Bus = 0b00, SysClk = 0b01, Hsi16 = 0b10 }
 
enum  LpTimerClockSource : uint8_t { Bus = 0b00, Lsi = 0b01, Hsi16 = 0b10, Lse = 0b11 }
 
enum  TimerClockSource : uint8_t { Bus = 0b0, PllQ = 0b1 }
 
enum  AdcClockSource : uint32_t { SysClk = 0, PllP = 0b01u << RCC_CCIPR_ADCSEL_Pos, Hsi16 = 0b10u << RCC_CCIPR_ADCSEL_Pos }
 
enum  McoPrescaler : uint8_t {
  Div1 = 0b0000, Div2 = 0b0001, Div4 = 0b0010, Div8 = 0b0011,
  Div16 = 0b0100, Div32 = 0b0101, Div64 = 0b0110, Div128 = 0b0111
}
 
enum  McoClockSource : uint8_t {
  Disabled = 0b0000, SysClk = 0b0001, Hsi16 = 0b0011, Hse = 0b0100,
  PllR = 0b0101, Lsi = 0b0110, Lse = 0b0111
}
 
enum  VoltageScaling : uint32_t { Range1 = 0b01 << PWR_CR1_VOS_Pos, Range2 = 0b10 << PWR_CR1_VOS_Pos }
 

Static Public Member Functions

template<class... Signals>
static void connect ()
 Connect GPIO signals like MCO to the clock tree.
 
template<Peripheral peripheral>
static void enable ()
 Enable the clock for a peripheral.
 
template<Peripheral peripheral>
static bool isEnabled ()
 Check if a peripheral clock is enabled.
 
template<Peripheral peripheral>
static void disable ()
 Disable the clock for a peripheral.
 
template<uint32_t Core_Hz, uint16_t Core_mV = 3300>
static uint32_t setFlashLatency ()
 
template<uint32_t Core_Hz>
static void updateCoreFrequency ()
 Update the SystemCoreClock and delay variables.
 
static bool enableHsiClock (HsiPrescaler div=HsiPrescaler::Div1, uint32_t waitLoops=0x10000)
 
static bool enableHseClock (uint32_t waitLoops=0x10000)
 
static bool enableHseCrystal (uint32_t waitLoops=0x10000)
 
static bool enableLsiClock (uint32_t waitLoops=0x10000)
 
static bool enableLseClock (uint32_t waitLoops=0x10000)
 
static bool enableLseCrystal (LseDrive drive=LseDrive::Low, uint32_t waitLoops=0x10000)
 
static bool enablePll (PllSource source, const PllConfig &cfg, uint32_t waitLoops=0x10000)
 Configure and enable PLL.
 
static bool disablePll (uint32_t waitLoops=0x10000)
 Disable PLL.
 
static void setAhbPrescaler (AhbPrescaler prescaler)
 
static void setApbPrescaler (ApbPrescaler prescaler)
 
static bool enableSystemClock (SystemClockSource src, uint32_t waitLoops=0x10000)
 
static void setRealTimeClockSource (RealTimeClockSource src)
 
static void setUsart1ClockSource (UartClockSource src)
 
static void setUsart2ClockSource (UartClockSource src)
 
static void setLpUart1ClockSource (UartClockSource src)
 
static void setI2c1ClockSource (I2cClockSource src)
 
static void setI2c2ClockSource (I2cClockSource src)
 
static void setLpTimer1ClockSource (LpTimerClockSource src)
 
static void setLpTimer2ClockSource (LpTimerClockSource src)
 
static void setTimer1ClockSource (TimerClockSource src)
 
static void setAdcClockSource (AdcClockSource src)
 
static void setMcoClockSource (McoClockSource src, McoPrescaler div)
 
static bool setVoltageScaling (VoltageScaling voltage, uint32_t waitLoops=0x10000)
 

Static Public Attributes

static constexpr uint32_t LsiFrequency = 32'000
 
static constexpr uint32_t HsiFrequency = 16'000'000
 
static constexpr uint32_t BootFrequency = HsiFrequency
 
static constexpr uint32_t MaxFrequency = 64'000'000
 

Detailed Description

Reset and Clock Control for STM32G0 devices.

This class abstracts access to clock settings on the STM32. You need to use this class to enable internal and external clock sources & outputs, set PLL parameters and AHB & APB prescalers. Don't forget to set the flash latencies.

Author
Niklas Hauser

Member Function Documentation

template<uint32_t Core_Hz, uint16_t Core_mV = 3300>
static uint32_t modm::platform::Rcc::setFlashLatency ( )
static

Set flash latency for CPU frequency and voltage. Does nothing if CPU frequency is too high for the available voltage.

Returns
maximum CPU frequency for voltage.
Return Values
<=CPU_Frequencyflash latency has been set correctly.
>CPU_Frequencyrequested frequency too high for voltage.

The documentation for this class was generated from the following file: