Skip to content

Commit f712041

Browse files
author
Erwan GOURIOU
committed
[STM32L4xx] Sleep API factorization
In order to enable sleep API factorization, HAL_Suspend/ResumeTick functions have been implemented in hal_tick.c for each platform.
1 parent 75bbc0a commit f712041

File tree

3 files changed

+39
-17
lines changed
  • hal/targets

3 files changed

+39
-17
lines changed

hal/targets/cmsis/TARGET_STM/TARGET_STM32L4/TARGET_DISCO_L476VG/hal_tick.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,21 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) {
107107
return HAL_OK;
108108
}
109109

110+
void HAL_SuspendTick(void)
111+
{
112+
TimMasterHandle.Instance = TIM_MST;
113+
114+
// Disable HAL tick and us_ticker update interrupts (used for 32 bit counter)
115+
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2);
116+
}
117+
118+
void HAL_ResumeTick(void)
119+
{
120+
TimMasterHandle.Instance = TIM_MST;
121+
122+
// Enable HAL tick and us_ticker update interrupts (used for 32 bit counter)
123+
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2);
124+
}
110125
/**
111126
* @}
112127
*/

hal/targets/cmsis/TARGET_STM/TARGET_STM32L4/TARGET_NUCLEO_L476RG/hal_tick.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,21 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) {
107107
return HAL_OK;
108108
}
109109

110+
void HAL_SuspendTick(void)
111+
{
112+
TimMasterHandle.Instance = TIM_MST;
113+
114+
// Disable HAL tick and us_ticker update interrupts (used for 32 bit counter)
115+
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2);
116+
}
117+
118+
void HAL_ResumeTick(void)
119+
{
120+
TimMasterHandle.Instance = TIM_MST;
121+
122+
// Enable HAL tick and us_ticker update interrupts (used for 32 bit counter)
123+
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2);
124+
}
110125
/**
111126
* @}
112127
*/

hal/targets/hal/TARGET_STM/TARGET_STM32L4/sleep.c

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,37 +32,29 @@
3232
#if DEVICE_SLEEP
3333

3434
#include "cmsis.h"
35-
#include "hal_tick.h"
36-
37-
static TIM_HandleTypeDef TimMasterHandle;
38-
39-
void sleep(void)
40-
{
41-
// Disable HAL tick interrupt
42-
TimMasterHandle.Instance = TIM_MST;
43-
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2);
4435

36+
void sleep(void) {
37+
// Stop HAL systick
38+
HAL_SuspendTick();
4539
// Request to enter SLEEP mode
4640
HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
47-
48-
// Enable HAL tick interrupt
49-
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2);
41+
// Restart HAL systick
42+
HAL_ResumeTick();
5043
}
5144

5245
void deepsleep(void)
5346
{
54-
// Disable HAL tick interrupt
55-
TimMasterHandle.Instance = TIM_MST;
56-
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2);
47+
// Stop HAL systick
48+
HAL_SuspendTick();
5749

5850
// Request to enter STOP mode with regulator in low power mode
5951
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
6052

6153
// After wake-up from STOP reconfigure the PLL
6254
SetSysClock();
6355

64-
// Enable HAL tick interrupt
65-
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2);
56+
// Restart HAL systick
57+
HAL_ResumeTick();
6658
}
6759

6860
#endif

0 commit comments

Comments
 (0)