Skip to content

Commit d85e756

Browse files
Use repeating intervals in terms of seconds for the RTC WAKEUP timer
1 parent eb00dbe commit d85e756

File tree

5 files changed

+13
-17
lines changed

5 files changed

+13
-17
lines changed

system/STM32L0xx/Include/stm32l0_rtc.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ typedef struct _stm32l0_rtc_timer_t {
9393
#define STM32L0_RTC_PREDIV_A 16
9494

9595
#define STM32L0_RTC_ALRMSSR_MASKSS (RTC_ALRMBSSR_MASKSS_3 | RTC_ALRMBSSR_MASKSS_1 | RTC_ALRMBSSR_MASKSS_0)
96-
#define STM32L0_RTC_CR_WUCKSEL (0)
9796

9897
#define STM32L0_RTC_CLOCK_TICKS_PER_SECOND STM32L0_RTC_PREDIV_S
9998

@@ -165,7 +164,7 @@ extern void stm32l0_rtc_timer_start(stm32l0_rtc_timer_t *timer, uint64_t clock,
165164
extern void stm32l0_rtc_timer_stop(stm32l0_rtc_timer_t *timer);
166165
extern bool stm32l0_rtc_timer_done(stm32l0_rtc_timer_t *timer);
167166

168-
extern void stm32l0_rtc_wakeup_start(uint32_t ticks, stm32l0_rtc_wakeup_callback_t callback, void *context);
167+
extern void stm32l0_rtc_wakeup_start(uint32_t seconds, stm32l0_rtc_wakeup_callback_t callback, void *context);
169168
extern void stm32l0_rtc_wakeup_stop();
170169
extern bool stm32l0_rtc_wakeup_done();
171170

system/STM32L0xx/Lib/libstm32l052xx.a

-84 Bytes
Binary file not shown.

system/STM32L0xx/Lib/libstm32l072xx.a

-84 Bytes
Binary file not shown.

system/STM32L0xx/Lib/libstm32l082xx.a

-84 Bytes
Binary file not shown.

system/STM32L0xx/Source/stm32l0_rtc.c

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ void __stm32l0_rtc_initialize(void)
239239
stm32l0_rtc_device.timer_active = STM32L0_RTC_TIMER_TAIL;
240240
stm32l0_rtc_device.timer_modify = STM32L0_RTC_TIMER_TAIL;
241241

242-
RTC->CR = (RTC->CR & ~RTC_CR_WUCKSEL) | STM32L0_RTC_CR_WUCKSEL;
242+
RTC->CR = (RTC->CR & ~RTC_CR_WUCKSEL) | RTC_CR_WUCKSEL_2;
243243
}
244244

245245
void stm32l0_rtc_configure(unsigned int priority)
@@ -1422,8 +1422,13 @@ bool stm32l0_rtc_timer_done(stm32l0_rtc_timer_t *timer)
14221422
return (timer->next == STM32L0_RTC_TIMER_NULL);
14231423
}
14241424

1425-
void stm32l0_rtc_wakeup_start(uint32_t ticks, stm32l0_rtc_wakeup_callback_t callback, void *context)
1425+
void stm32l0_rtc_wakeup_start(uint32_t seconds, stm32l0_rtc_wakeup_callback_t callback, void *context)
14261426
{
1427+
if (seconds > 65536)
1428+
{
1429+
return false;
1430+
}
1431+
14271432
if (stm32l0_rtc_device.wakeup_busy)
14281433
{
14291434
armv6m_atomic_and(&RTC->CR, ~(RTC_CR_WUTIE | RTC_CR_WUTE));
@@ -1451,13 +1456,15 @@ void stm32l0_rtc_wakeup_start(uint32_t ticks, stm32l0_rtc_wakeup_callback_t call
14511456
__NOP();
14521457
}
14531458

1454-
RTC->WUTR = ticks -1;
1459+
RTC->WUTR = seconds -1;
14551460

14561461
stm32l0_system_lock(STM32L0_SYSTEM_LOCK_DEEPSLEEP);
14571462

14581463
stm32l0_rtc_device.wakeup_busy = 1;
14591464

14601465
armv6m_atomic_or(&RTC->CR, RTC_CR_WUTIE | RTC_CR_WUTE);
1466+
1467+
return true;
14611468
}
14621469

14631470
void stm32l0_rtc_wakeup_stop()
@@ -1848,27 +1855,17 @@ void RTC_IRQHandler(void)
18481855

18491856
if (RTC->ISR & RTC_ISR_WUTF)
18501857
{
1858+
RTC->ISR = ~(RTC_ISR_WUTF | RTC_ISR_INIT);
1859+
18511860
if (stm32l0_rtc_device.wakeup_busy)
18521861
{
1853-
armv6m_atomic_and(&RTC->CR, ~(RTC_CR_WUTIE | RTC_CR_WUTE));
1854-
1855-
RTC->ISR = ~(RTC_ISR_WUTF | RTC_ISR_INIT);
1856-
1857-
stm32l0_system_unlock(STM32L0_SYSTEM_LOCK_DEEPSLEEP);
1858-
1859-
stm32l0_rtc_device.wakeup_busy = 0;
1860-
18611862
callback = stm32l0_rtc_device.wakeup_callback;
18621863

18631864
if (callback)
18641865
{
18651866
(*callback)(stm32l0_rtc_device.wakeup_context);
18661867
}
18671868
}
1868-
else
1869-
{
1870-
RTC->ISR = ~(RTC_ISR_WUTF | RTC_ISR_INIT);
1871-
}
18721869
}
18731870
}
18741871

0 commit comments

Comments
 (0)