Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/thirdpin/libopencm3.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Randolf <br1@einfach.org>2018-01-05 16:36:59 +0300
committerKarl Palsson <karlp@tweak.net.au>2019-06-03 01:18:05 +0300
commitb8424263e8e13a2c6a225a76f242f6af042dab73 (patch)
tree312fa5f9564baaccb06c69cb6b84541744fe3642
parent2c1823f7bbae19f9322770e855555da08f8bcea8 (diff)
stm32:l4: rcc: Add RTC clock functions
-rw-r--r--include/libopencm3/stm32/l4/rcc.h4
-rw-r--r--lib/stm32/l4/rcc.c36
2 files changed, 40 insertions, 0 deletions
diff --git a/include/libopencm3/stm32/l4/rcc.h b/include/libopencm3/stm32/l4/rcc.h
index 01c34e26..8bad910b 100644
--- a/include/libopencm3/stm32/l4/rcc.h
+++ b/include/libopencm3/stm32/l4/rcc.h
@@ -964,6 +964,10 @@ void rcc_set_msi_range(uint32_t msi_range);
void rcc_set_msi_range_standby(uint32_t msi_range);
void rcc_pll_output_enable(uint32_t pllout);
void rcc_set_clock48_source(uint32_t clksel);
+void rcc_clock_setup_pll(const struct rcc_clock_scale *clock);
+void rcc_enable_rtc_clock(void);
+void rcc_disable_rtc_clock(void);
+void rcc_set_rtc_clock_source(enum rcc_osc clk);
END_DECLS
diff --git a/lib/stm32/l4/rcc.c b/lib/stm32/l4/rcc.c
index 86631254..f44cfca1 100644
--- a/lib/stm32/l4/rcc.c
+++ b/lib/stm32/l4/rcc.c
@@ -398,4 +398,40 @@ void rcc_set_clock48_source(uint32_t clksel)
RCC_CCIPR |= (clksel << RCC_CCIPR_CLK48SEL_SHIFT);
}
+
+/** Enable the RTC clock */
+void rcc_enable_rtc_clock(void)
+{
+ RCC_BDCR |= RCC_BDCR_RTCEN;
+}
+
+/** Disable the RTC clock */
+void rcc_disable_rtc_clock(void)
+{
+ RCC_BDCR &= ~RCC_BDCR_RTCEN;
+}
+
+/** Set the source for the RTC clock
+ * @param[in] clk ::rcc_osc. RTC clock source. Only HSE/32, LSE and LSI.
+ */
+void rcc_set_rtc_clock_source(enum rcc_osc clk)
+{
+ RCC_BDCR &= ~(RCC_BDCR_RTCSEL_MASK << RCC_BDCR_RTCSEL_SHIFT);
+
+ switch (clk) {
+ case RCC_HSE:
+ RCC_BDCR |= (RCC_BDCR_RTCSEL_HSEDIV32 << RCC_BDCR_RTCSEL_SHIFT);
+ break;
+ case RCC_LSE:
+ RCC_BDCR |= (RCC_BDCR_RTCSEL_LSE << RCC_BDCR_RTCSEL_SHIFT);
+ break;
+ case RCC_LSI:
+ RCC_BDCR |= (RCC_BDCR_RTCSEL_LSI << RCC_BDCR_RTCSEL_SHIFT);
+ break;
+ default:
+ /* none selected */
+ break;
+ }
+}
+
/**@}*/