Skip to content

Commit 671b3c8

Browse files
author
Cruz Monrreal
authored
Merge pull request #7507 from jeromecoutant/PR_LPTIM
STM32 LPTICKER with LPTIM minor update
2 parents 56dd4bf + 8a0b832 commit 671b3c8

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

targets/TARGET_STM/lp_ticker.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,11 @@ static void (*irq_handler)(void);
6060

6161
void lp_ticker_init(void)
6262
{
63-
NVIC_DisableIRQ(LPTIM1_IRQn);
64-
6563
/* Check if LPTIM is already configured */
66-
#if (TARGET_STM32L0)
67-
if (READ_BIT(RCC->APB1ENR, RCC_APB1ENR_LPTIM1EN) != RESET) {
68-
return;
69-
}
70-
#else
7164
if (__HAL_RCC_LPTIM1_IS_CLK_ENABLED()) {
65+
lp_ticker_disable_interrupt();
7266
return;
7367
}
74-
#endif
7568

7669
RCC_PeriphCLKInitTypeDef RCC_PeriphCLKInitStruct = {0};
7770
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
@@ -153,6 +146,7 @@ void lp_ticker_init(void)
153146
__HAL_LPTIM_ENABLE_IT(&LptimHandle, LPTIM_IT_CMPM);
154147
HAL_LPTIM_Counter_Start(&LptimHandle, 0xFFFF);
155148

149+
/* Need to write a compare value in order to get LPTIM_FLAG_CMPOK in set_interrupt */
156150
__HAL_LPTIM_COMPARE_SET(&LptimHandle, 0);
157151
}
158152

@@ -201,7 +195,7 @@ void lp_ticker_set_interrupt(timestamp_t timestamp)
201195
irq_handler = (void (*)(void))lp_ticker_irq_handler;
202196

203197
/* CMPOK is set by hardware to inform application that the APB bus write operation to the LPTIM_CMP register has been successfully completed */
204-
/* Any successive write before respectively the ARROK flag or the CMPOK flag be set, will lead to unpredictable results */
198+
/* Any successive write before the CMPOK flag be set, will lead to unpredictable results */
205199
while (__HAL_LPTIM_GET_FLAG(&LptimHandle, LPTIM_FLAG_CMPOK) == RESET) {
206200
}
207201

@@ -221,8 +215,11 @@ void lp_ticker_fire_interrupt(void)
221215

222216
void lp_ticker_disable_interrupt(void)
223217
{
224-
LptimHandle.Instance = LPTIM1;
225218
NVIC_DisableIRQ(LPTIM1_IRQn);
219+
LptimHandle.Instance = LPTIM1;
220+
/* Waiting last write operation completion */
221+
while (__HAL_LPTIM_GET_FLAG(&LptimHandle, LPTIM_FLAG_CMPOK) == RESET) {
222+
}
226223
}
227224

228225
void lp_ticker_clear_interrupt(void)

0 commit comments

Comments
 (0)