Skip to content

Commit a227a94

Browse files
author
Erwan GOURIOU
committed
[STM32F1xx] 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 c1e0663 commit a227a94

File tree

3 files changed

+35
-12
lines changed
  • hal/targets

3 files changed

+35
-12
lines changed

hal/targets/cmsis/TARGET_STM/TARGET_STM32F1/TARGET_DISCO_F100RB/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_STM32F1/TARGET_NUCLEO_F103RB/hal_tick.c

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

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

hal/targets/hal/TARGET_STM/TARGET_STM32F1/sleep.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,13 @@
3434
#include "cmsis.h"
3535
#include "hal_tick.h"
3636

37-
static TIM_HandleTypeDef TimMasterHandle;
38-
39-
void sleep(void)
40-
{
41-
TimMasterHandle.Instance = TIM_MST;
42-
43-
// Disable HAL tick and us_ticker update interrupts
44-
__HAL_TIM_DISABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE));
45-
37+
void sleep(void) {
38+
// Stop HAL systick
39+
HAL_SuspendTick();
4640
// Request to enter SLEEP mode
4741
HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
48-
49-
// Enable HAL tick and us_ticker update interrupts
50-
__HAL_TIM_ENABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE));
42+
// Restart HAL systick
43+
HAL_ResumeTick();
5144
}
5245

5346
void deepsleep(void)

0 commit comments

Comments
 (0)