Skip to content

Commit c1e0663

Browse files
author
Erwan GOURIOU
committed
[STM32F0xx] 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 5cd7317 commit c1e0663

File tree

7 files changed

+91
-32
lines changed

7 files changed

+91
-32
lines changed

hal/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F030R8/hal_tick.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,21 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) {
143143
return HAL_OK;
144144
}
145145

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

hal/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F031K6/hal_tick.c

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

111+
void HAL_SuspendTick(void)
112+
{
113+
TimMasterHandle.Instance = TIM_MST;
114+
115+
// Disable HAL tick
116+
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2);
117+
}
118+
119+
void HAL_ResumeTick(void)
120+
{
121+
TimMasterHandle.Instance = TIM_MST;
122+
123+
// Enable HAL tick
124+
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2);
125+
}
111126
/**
112127
* @}
113128
*/

hal/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F042K6/hal_tick.c

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

111+
void HAL_SuspendTick(void)
112+
{
113+
TimMasterHandle.Instance = TIM_MST;
114+
115+
// Disable HAL tick
116+
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2);
117+
}
118+
119+
void HAL_ResumeTick(void)
120+
{
121+
TimMasterHandle.Instance = TIM_MST;
122+
123+
// Enable HAL tick
124+
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2);
125+
}
111126
/**
112127
* @}
113128
*/

hal/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F070RB/hal_tick.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,21 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) {
155155
return HAL_OK;
156156
}
157157

158+
void HAL_SuspendTick(void)
159+
{
160+
TimMasterHandle.Instance = TIM_MST;
161+
162+
// Disable HAL tick and us_ticker update interrupts (used for 32 bit counter)
163+
__HAL_TIM_DISABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE));
164+
}
165+
166+
void HAL_ResumeTick(void)
167+
{
168+
TimMasterHandle.Instance = TIM_MST;
169+
170+
// Enable HAL tick and us_ticker update interrupts (used for 32 bit counter)
171+
__HAL_TIM_ENABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE));
172+
}
158173
/**
159174
* @}
160175
*/

hal/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F072RB/hal_tick.c

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

112+
void HAL_SuspendTick(void)
113+
{
114+
TimMasterHandle.Instance = TIM_MST;
115+
116+
// Disable HAL tick
117+
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2);
118+
}
119+
120+
void HAL_ResumeTick(void)
121+
{
122+
TimMasterHandle.Instance = TIM_MST;
123+
124+
// Enable HAL tick
125+
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2);
126+
}
112127
/**
113128
* @}
114129
*/

hal/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F091RC/hal_tick.c

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

112+
void HAL_SuspendTick(void)
113+
{
114+
TimMasterHandle.Instance = TIM_MST;
115+
116+
// Disable HAL tick
117+
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2);
118+
}
119+
120+
void HAL_ResumeTick(void)
121+
{
122+
TimMasterHandle.Instance = TIM_MST;
123+
124+
// Enable HAL tick
125+
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2);
126+
}
112127
/**
113128
* @}
114129
*/

hal/targets/hal/TARGET_STM/TARGET_STM32F0/sleep.c

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,12 @@
2929
*/
3030
#include "sleep_api.h"
3131

32+
3233
#if DEVICE_SLEEP
3334

3435
#include "cmsis.h"
3536

36-
#if defined(TARGET_STM32F070RB)
37-
void sleep(void) {
38-
TIM_HandleTypeDef TimMasterHandle;
39-
40-
TimMasterHandle.Instance = TIM1;
41-
42-
// Disable HAL tick and us_ticker update interrupts
43-
__HAL_TIM_DISABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE));
44-
45-
// Request to enter SLEEP mode
46-
HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
4737

48-
// Enable HAL tick and us_ticker update interrupts
49-
__HAL_TIM_ENABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE));
50-
}
51-
52-
#elif defined(TARGET_STM32F030R8) || defined (TARGET_STM32F051R8)
5338
void sleep(void) {
5439
// Stop HAL systick
5540
HAL_SuspendTick();
@@ -59,22 +44,6 @@ void sleep(void) {
5944
HAL_ResumeTick();
6045
}
6146

62-
#else
63-
static TIM_HandleTypeDef TimMasterHandle;
64-
65-
void sleep(void) {
66-
TimMasterHandle.Instance = TIM2;
67-
68-
// Disable HAL tick interrupt
69-
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2);
70-
71-
// Request to enter SLEEP mode
72-
HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
73-
74-
// Enable HAL tick interrupt
75-
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2);
76-
}
77-
#endif
7847

7948
#if defined(TARGET_STM32F030R8) || defined (TARGET_STM32F051R8)
8049
void deepsleep(void) {

0 commit comments

Comments
 (0)