Skip to content

Commit 34c37c8

Browse files
author
Erwan GOURIOU
committed
[STM32L0xx] 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 8f6090d commit 34c37c8

File tree

6 files changed

+80
-11
lines changed

6 files changed

+80
-11
lines changed

hal/targets/cmsis/TARGET_STM/TARGET_STM32L0/TARGET_DISCO_L053C8/hal_tick.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,21 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) {
131131
return HAL_OK;
132132
}
133133

134+
void HAL_SuspendTick(void)
135+
{
136+
TimMasterHandle.Instance = TIM_MST;
137+
138+
// Disable HAL tick and us_ticker update interrupts (used for 32 bit counter)
139+
__HAL_TIM_DISABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE));
140+
}
141+
142+
void HAL_ResumeTick(void)
143+
{
144+
TimMasterHandle.Instance = TIM_MST;
145+
146+
// Enable HAL tick and us_ticker update interrupts (used for 32 bit counter)
147+
__HAL_TIM_ENABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE));
148+
}
134149
/**
135150
* @}
136151
*/

hal/targets/cmsis/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L011K4/hal_tick.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,21 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) {
140140
return HAL_OK;
141141
}
142142

143+
void HAL_SuspendTick(void)
144+
{
145+
TimMasterHandle.Instance = TIM_MST;
146+
147+
// Disable HAL tick and us_ticker update interrupts (used for 32 bit counter)
148+
__HAL_TIM_DISABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE));
149+
}
150+
151+
void HAL_ResumeTick(void)
152+
{
153+
TimMasterHandle.Instance = TIM_MST;
154+
155+
// Enable HAL tick and us_ticker update interrupts (used for 32 bit counter)
156+
__HAL_TIM_ENABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE));
157+
}
143158
/**
144159
* @}
145160
*/

hal/targets/cmsis/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L031K6/hal_tick.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,21 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) {
131131
return HAL_OK;
132132
}
133133

134+
void HAL_SuspendTick(void)
135+
{
136+
TimMasterHandle.Instance = TIM_MST;
137+
138+
// Disable HAL tick and us_ticker update interrupts (used for 32 bit counter)
139+
__HAL_TIM_DISABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE));
140+
}
141+
142+
void HAL_ResumeTick(void)
143+
{
144+
TimMasterHandle.Instance = TIM_MST;
145+
146+
// Enable HAL tick and us_ticker update interrupts (used for 32 bit counter)
147+
__HAL_TIM_ENABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE));
148+
}
134149
/**
135150
* @}
136151
*/

hal/targets/cmsis/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L053R8/hal_tick.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,21 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) {
131131
return HAL_OK;
132132
}
133133

134+
void HAL_SuspendTick(void)
135+
{
136+
TimMasterHandle.Instance = TIM_MST;
137+
138+
// Disable HAL tick and us_ticker update interrupts (used for 32 bit counter)
139+
__HAL_TIM_DISABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE));
140+
}
141+
142+
void HAL_ResumeTick(void)
143+
{
144+
TimMasterHandle.Instance = TIM_MST;
145+
146+
// Enable HAL tick and us_ticker update interrupts (used for 32 bit counter)
147+
__HAL_TIM_ENABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE));
148+
}
134149
/**
135150
* @}
136151
*/

hal/targets/cmsis/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L073RZ/hal_tick.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,21 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) {
131131
return HAL_OK;
132132
}
133133

134+
void HAL_SuspendTick(void)
135+
{
136+
TimMasterHandle.Instance = TIM_MST;
137+
138+
// Disable HAL tick and us_ticker update interrupts (used for 32 bit counter)
139+
__HAL_TIM_DISABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE));
140+
}
141+
142+
void HAL_ResumeTick(void)
143+
{
144+
TimMasterHandle.Instance = TIM_MST;
145+
146+
// Enable HAL tick and us_ticker update interrupts (used for 32 bit counter)
147+
__HAL_TIM_ENABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE));
148+
}
134149
/**
135150
* @}
136151
*/

hal/targets/hal/TARGET_STM/TARGET_STM32L0/sleep.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,14 @@
3333

3434
#include "cmsis.h"
3535

36-
static TIM_HandleTypeDef TimMasterHandle;
37-
38-
void sleep(void)
39-
{
40-
TimMasterHandle.Instance = TIM21;
41-
42-
// Disable HAL tick interrupt
43-
__HAL_TIM_DISABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE));
4436

37+
void sleep(void) {
38+
// Stop HAL systick
39+
HAL_SuspendTick();
4540
// Request to enter SLEEP mode
4641
HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
47-
48-
// Enable HAL tick interrupt
49-
__HAL_TIM_ENABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE));
42+
// Restart HAL systick
43+
HAL_ResumeTick();
5044
}
5145

5246
void deepsleep(void)

0 commit comments

Comments
 (0)