Skip to content

Commit 8f6090d

Browse files
author
Erwan GOURIOU
committed
[STM32F7xx] 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 3ab5697 commit 8f6090d

File tree

3 files changed

+35
-12
lines changed
  • hal/targets

3 files changed

+35
-12
lines changed

hal/targets/cmsis/TARGET_STM/TARGET_STM32F7/TARGET_DISCO_F746NG/hal_tick.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,21 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) {
126126
return HAL_OK;
127127
}
128128

129+
__INLINE void HAL_SuspendTick(void)
130+
{
131+
TimMasterHandle.Instance = TIM_MST;
132+
133+
// Disable HAL tick and us_ticker update interrupts (used for 32 bit counter)
134+
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2);
135+
}
136+
137+
__INLINE void HAL_ResumeTick(void)
138+
{
139+
TimMasterHandle.Instance = TIM_MST;
140+
141+
// Enable HAL tick and us_ticker update interrupts (used for 32 bit counter)
142+
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2);
143+
}
129144
/**
130145
* @}
131146
*/

hal/targets/cmsis/TARGET_STM/TARGET_STM32F7/TARGET_NUCLEO_F746ZG/hal_tick.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,21 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) {
126126
return HAL_OK;
127127
}
128128

129+
__INLINE void HAL_SuspendTick(void)
130+
{
131+
TimMasterHandle.Instance = TIM_MST;
132+
133+
// Disable HAL tick and us_ticker update interrupts (used for 32 bit counter)
134+
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2);
135+
}
136+
137+
__INLINE void HAL_ResumeTick(void)
138+
{
139+
TimMasterHandle.Instance = TIM_MST;
140+
141+
// Enable HAL tick and us_ticker update interrupts (used for 32 bit counter)
142+
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2);
143+
}
129144
/**
130145
* @}
131146
*/

hal/targets/hal/TARGET_STM/TARGET_STM32F7/sleep.c

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

3434
#include "cmsis.h"
3535

36-
static TIM_HandleTypeDef TimMasterHandle;
37-
38-
void sleep(void)
39-
{
40-
TimMasterHandle.Instance = TIM5;
41-
42-
// Disable HAL tick interrupt
43-
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2);
44-
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)

0 commit comments

Comments
 (0)