diff --git a/drv/rcc.c b/drv/rcc.c index 56adbbc..c229c45 100644 --- a/drv/rcc.c +++ b/drv/rcc.c @@ -66,10 +66,16 @@ void rcc_configure_lsi(bool enable) //ensure LSI is enabled if (enable) { - while (regs->CSR.LSIRDY != 0x1); + while (regs->CSR.LSIRDY != 0x1) {} } } +void rcc_configure_rtc(bool enable, enum RccRtcClockSrc clock_src) +{ + regs->BDCR.RTCSEL = clock_src; + regs->BDCR.RTCEN = enable; +} + void rcc_enable(enum RccAhb ahb_mask, enum RccApb1 apb1_mask, enum RccApb2 apb2_mask) { diff --git a/drv/rcc.h b/drv/rcc.h index f26ba01..b437ecb 100644 --- a/drv/rcc.h +++ b/drv/rcc.h @@ -95,6 +95,13 @@ enum RccApb2 { RCC_APB2_TIM11 = (0x1 << 21), }; +enum RccRtcClockSrc { + RCC_RTC_CLOCK_SRC_NONE = 0x0, + RCC_RTC_CLOCK_SRC_LSE = 0x1, + RCC_RTC_CLOCK_SRC_LSI = 0x2, + RCC_RTC_CLOCK_SRC_HSE = 0x3, +}; + struct RccClocks { uint32_t ahb_freq; uint32_t apb1_freq; @@ -118,6 +125,8 @@ void rcc_configure(enum RccPreset preset); */ void rcc_configure_lsi(bool enable); +void rcc_configure_rtc(bool enable, enum RccRtcClockSrc clock_src); + /** * Enables peripherals on the different buses. The enums values can used as * masks to enable multiple peripherals at the same time. Invalid values will be