From a121769785c1cde6a5599ba3449021b673144d9c Mon Sep 17 00:00:00 2001 From: Michael Aherne Date: Tue, 26 Feb 2013 18:23:31 -0800 Subject: Adding f4-specific rtc functions These should also work with the f2 --- include/libopencm3/stm32/f4/rtc.h | 11 +++++++- lib/stm32/f4/rtc.c | 58 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/include/libopencm3/stm32/f4/rtc.h b/include/libopencm3/stm32/f4/rtc.h index ab8d3ee..55b5b23 100644 --- a/include/libopencm3/stm32/f4/rtc.h +++ b/include/libopencm3/stm32/f4/rtc.h @@ -36,4 +36,13 @@ LGPL License Terms @ref lgpl_license #include #include -#endif \ No newline at end of file +BEGIN_DECLS + +void rtc_enable_wakeup_timer(void); +void rtc_disable_wakeup_timer(void); +void rtc_enable_wakeup_timer_interrupt(void); +void rtc_disable_wakeup_timer_interrupt(void); + +END_DECLS + +#endif diff --git a/lib/stm32/f4/rtc.c b/lib/stm32/f4/rtc.c index 1b301fa..5f6627f 100644 --- a/lib/stm32/f4/rtc.c +++ b/lib/stm32/f4/rtc.c @@ -25,3 +25,61 @@ #include #include + + +/*---------------------------------------------------------------------------*/ +/** @brief Enable the wakeup timer + @warning You must unlock the registers before using this function + +*/ +void rtc_enable_wakeup_timer(void) { + RTC_CR |= RTC_CR_WUTE | (RTC_CR_OSEL_WAKEUP << RTC_CR_OSEL_SHIFT); + rtc_enable_wakeup_timer_interrupt(); +} + +/*---------------------------------------------------------------------------*/ +/** @brief Disable the wakeup timer + @warning You must unlock the registers before using this function + +*/ +void rtc_disable_wakeup_timer(void) { + RTC_CR &= ~RTC_CR_WUTE; + rtc_disable_wakeup_timer_interrupt(); +} + +/*---------------------------------------------------------------------------*/ +/** @brief Enable the wakeup timer interrupt + @warning You must unlock the registers before using this function + +*/ +void rtc_enable_wakeup_timer_interrupt(void) { +// FTFM: +// To enable the RTC Wakeup interrupt, the following sequence is required: +// 1. Configure and enable the EXTI Line 22 in interrupt mode and select the +// rising edge sensitivity. + exti_enable_request(EXTI22); + exti_set_trigger(EXTI22, EXTI_TRIGGER_RISING); + +// 2. Configure and enable the RTC_WKUP IRQ channel in the NVIC. + nvic_enable_irq(NVIC_RTC_WKUP_IRQ); + nvic_set_priority(NVIC_RTC_WKUP_IRQ, 1); + +// 3. Configure the RTC to generate the RTC wakeup timer event. + RTC_CR |= RTC_CR_WUTIE; // Enable the interrupt +} + +/*---------------------------------------------------------------------------*/ +/** @brief Disable the wakeup timer interrupt + @warning You must unlock the registers before using this function + +*/ +void rtc_disable_wakeup_timer_interrupt(void) { +// 1. Disable EXTI Line 22 + exti_disable_request(EXTI22); + +// 2. Disable RTC_WKUP IRQ channel in the NVIC. + nvic_disable_irq(NVIC_RTC_WKUP_IRQ); + +// 3. Disable RTC wakeup timer event. + RTC_CR &= ~RTC_CR_WUTIE; +} -- cgit v1.2.3