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

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

Classes

struct  PllConfig
 

Public Types

enum  LseDrive : uint8_t { Low = 0b00, MediumLow = 0b01, MediumHigh = 0b10, High = 0b11 }
 
enum  PllSource : uint8_t { PllSource::HsiDiv2 = 0b00, PllSource::Hse = 0b01, PllSource::Hsi48 = 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 : uint32_t { Hsi = 0b00, Hse = 0b01, Pll = 0b10, Hsi48 = 0b11 }
 
enum  RealTimeClockSource : uint32_t { Disabled = 0, Lse = 0b01 << RCC_BDCR_RTCSEL_Pos, Lsi = 0b10 << RCC_BDCR_RTCSEL_Pos, Hse = 0b11 << RCC_BDCR_RTCSEL_Pos }
 
enum  UsartClockSource : uint8_t { Bus = 0b00, SysClk = 0b01, Lse = 0b10, Hsi = 0b11 }
 
enum  I2cClockSource : uint8_t { Hsi = 0b0, Sysclk = 0b1 }
 
enum  UsbClockSource : uint8_t { Hsi48 = 0b0, Pll = 0b1 }
 
enum  McoClockSource : uint32_t {
  Disabled = 0b0000 << RCC_CFGR_MCO_Pos, Hsi14 = 0b0001 << RCC_CFGR_MCO_Pos, Lsi = 0b0010 << RCC_CFGR_MCO_Pos, Lse = 0b0011 << RCC_CFGR_MCO_Pos,
  SysClk = 0b0100 << RCC_CFGR_MCO_Pos, Hsi = 0b0101 << RCC_CFGR_MCO_Pos, Hse = 0b0110 << RCC_CFGR_MCO_Pos, Pll = (0b0111 << RCC_CFGR_MCO_Pos) | RCC_CFGR_PLLNODIV,
  PllDiv2 = (0b0111 << RCC_CFGR_MCO_Pos), Hsi48 = 0b1000 << RCC_CFGR_MCO_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 (uint32_t waitLoops=0x10000)
 
static bool enableHsi14Clock (uint32_t waitLoops=0x10000)
 
static bool enableHsi48Clock (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 src, const PllConfig &cfg, uint32_t waitLoops=0x10000)
 Configure and enable the 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 (UsartClockSource src)
 
static void setI2c1ClockSource (I2cClockSource src)
 
static void setUsbClockSource (UsbClockSource src)
 
static void setMcoClockSource (McoClockSource src)
 

Static Public Attributes

static constexpr uint32_t LsiFrequency = 40'000
 
static constexpr uint32_t HsiFrequency = 8'000'000
 
static constexpr uint32_t BootFrequency = HsiFrequency
 
static constexpr uint32_t MaxFrequency = 48'000'000
 

Detailed Description

Reset and Clock Control for STM32F0 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 Enumeration Documentation

enum modm::platform::Rcc::PllSource : uint8_t
strong
Enum ValuesDocumentation
HsiDiv2 

HSI divided by 2.

Hse 

HSE divided by PREDIV.

Hsi48 

HSI48 divided by PREDIV.

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: