Skip to content

Commit 75bbc0a

Browse files
author
Erwan GOURIOU
committed
[STM32L1xx] 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 34c37c8 commit 75bbc0a

File tree

4 files changed

+56
-14
lines changed

4 files changed

+56
-14
lines changed

hal/targets/cmsis/TARGET_STM/TARGET_STM32L1/TARGET_MOTE_L152RC/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_STM32L1/TARGET_NUCLEO_L152RE/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_STM32L1/TARGET_NZ32_SC151/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_STM32L1/sleep.c

100755100644
Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,35 +28,32 @@
2828
*******************************************************************************
2929
*/
3030
#include "sleep_api.h"
31+
#include "hal_tick.h"
3132

3233
#if DEVICE_SLEEP
3334

3435
#include "cmsis.h"
3536

3637
static TIM_HandleTypeDef TimMasterHandle;
3738

38-
void sleep(void)
39-
{
40-
// Disable HAL tick interrupt
41-
TimMasterHandle.Instance = TIM5;
42-
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2);
43-
39+
void sleep(void) {
40+
// Stop HAL systick
41+
HAL_SuspendTick();
4442
// Request to enter SLEEP mode
4543
HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
46-
47-
// Enable HAL tick interrupt
48-
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2);
44+
// Restart HAL systick
45+
HAL_ResumeTick();
4946
}
5047

48+
5149
void deepsleep(void)
5250
{
5351
#if defined(TARGET_MOTE_L152RC)
5452
int8_t STOPEntry = PWR_STOPENTRY_WFI;
5553
#endif
5654

57-
// Disable HAL tick interrupt
58-
TimMasterHandle.Instance = TIM5;
59-
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2);
55+
// Stop HAL systick
56+
TimMasterHandle.Instance = TIM_MST;
6057

6158
#if defined(TARGET_MOTE_L152RC)
6259
/* Select the regulator state in Stop mode: Set PDDS and LPSDSR bit according to PWR_Regulator value */
@@ -91,8 +88,8 @@ void deepsleep(void)
9188
// After wake-up from STOP reconfigure the PLL
9289
SetSysClock();
9390

94-
// Enable HAL tick interrupt
95-
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2);
91+
// Restart HAL systick
92+
HAL_ResumeTick();
9693
}
9794

9895
#endif

0 commit comments

Comments
 (0)