Skip to content

Commit 41b038a

Browse files
committed
TARGET_STM: rework hal_sleep management to be compatible with all STM32 families
1 parent e83a8ab commit 41b038a

File tree

12 files changed

+27
-3
lines changed

12 files changed

+27
-3
lines changed

targets/TARGET_STM/TARGET_STM32F0/common_objects.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "PinNames.h"
3737
#include "stm32f0xx_ll_usart.h"
3838
#include "stm32f0xx_ll_tim.h"
39+
#include "stm32f0xx_ll_pwr.h"
3940

4041
#ifdef __cplusplus
4142
extern "C" {
@@ -119,6 +120,13 @@ struct analogin_s {
119120
uint8_t channel;
120121
};
121122

123+
124+
#ifdef CRC_PROG_POLYNOMIAL_SUPPORT
125+
#define HAL_CRC_IS_SUPPORTED(polynomial, width) ((width) == 7 || (width) == 8 || (width) == 16 || (width) == 32)
126+
#else
127+
#define HAL_CRC_IS_SUPPORTED(polynomial, width) ((width) == 32 && (polynomial) == 0x04C11DB7)
128+
#endif
129+
122130
#include "gpio_object.h"
123131

124132
#if DEVICE_ANALOGOUT

targets/TARGET_STM/TARGET_STM32F1/common_objects.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "PinNames.h"
3737
#include "stm32f1xx_ll_usart.h"
3838
#include "stm32f1xx_ll_tim.h"
39+
#include "stm32f1xx_ll_pwr.h"
3940

4041
#ifdef __cplusplus
4142
extern "C" {

targets/TARGET_STM/TARGET_STM32F2/objects.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "PinNames.h"
3737
#include "stm32f2xx_ll_usart.h"
3838
#include "stm32f2xx_ll_tim.h"
39+
#include "stm32f2xx_ll_pwr.h"
3940

4041
#ifdef __cplusplus
4142
extern "C" {

targets/TARGET_STM/TARGET_STM32F3/common_objects.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "PinNames.h"
3737
#include "stm32f3xx_ll_usart.h"
3838
#include "stm32f3xx_ll_tim.h"
39+
#include "stm32f3xx_ll_pwr.h"
3940

4041
#ifdef __cplusplus
4142
extern "C" {

targets/TARGET_STM/TARGET_STM32F4/common_objects.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "PinNames.h"
3737
#include "stm32f4xx_ll_usart.h"
3838
#include "stm32f4xx_ll_tim.h"
39+
#include "stm32f4xx_ll_pwr.h"
3940

4041
#ifdef __cplusplus
4142
extern "C" {

targets/TARGET_STM/TARGET_STM32F7/common_objects.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "stm32f7xx_ll_tim.h"
3939
#include "stm32f7xx_ll_adc.h"
4040
#include "stm32f7xx_ll_rtc.h"
41+
#include "stm32f7xx_ll_pwr.h"
4142

4243
#ifdef __cplusplus
4344
extern "C" {

targets/TARGET_STM/TARGET_STM32H7/objects.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040
#if defined(DUAL_CORE)
4141
#include "stm32h7xx_ll_hsem.h"
4242
#include "stm32h7xx_ll_rcc.h"
43-
#include "stm32h7xx_ll_pwr.h"
4443
#include "stm32h7xx_ll_cortex.h"
4544
#endif /* CONFIG_STM32H7_DUAL_CORE */
45+
#include "stm32h7xx_ll_pwr.h"
4646

4747
#ifdef __cplusplus
4848
extern "C" {

targets/TARGET_STM/TARGET_STM32L0/common_objects.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "PinNames.h"
3737
#include "stm32l0xx_ll_usart.h"
3838
#include "stm32l0xx_ll_tim.h"
39+
#include "stm32l0xx_ll_pwr.h"
3940

4041
#ifdef __cplusplus
4142
extern "C" {

targets/TARGET_STM/TARGET_STM32L1/common_objects.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "PinNames.h"
3737
#include "stm32l1xx_ll_usart.h"
3838
#include "stm32l1xx_ll_tim.h"
39+
#include "stm32l1xx_ll_pwr.h"
3940

4041
#ifdef __cplusplus
4142
extern "C" {

targets/TARGET_STM/TARGET_STM32L4/common_objects.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "stm32l4xx_ll_lpuart.h"
3939
#include "stm32l4xx_ll_tim.h"
4040
#include "stm32l4xx_ll_rtc.h"
41+
#include "stm32l4xx_ll_pwr.h"
4142

4243
#ifdef __cplusplus
4344
extern "C" {

targets/TARGET_STM/TARGET_STM32WB/common_objects.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "PinNames.h"
3939
#include "stm32wbxx_ll_usart.h"
4040
#include "stm32wbxx_ll_tim.h"
41+
#include "stm32wbxx_ll_pwr.h"
4142

4243
#ifdef __cplusplus
4344
extern "C" {

targets/TARGET_STM/sleep.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ void hal_sleep(void)
135135
core_util_critical_section_enter();
136136

137137
// Request to enter SLEEP mode
138-
#ifdef PWR_CR1_LPR
138+
#if defined(PWR_CR1_LPR)
139139
// State Transitions (see 5.3 Low-power modes, Fig. 13):
140140
// * (opt): Low Power Run (LPR) Mode -> Run Mode
141141
// * Run Mode -> Sleep
@@ -145,7 +145,14 @@ void hal_sleep(void)
145145

146146
// [5.4.1 Power control register 1 (PWR_CR1)]
147147
// LPR: When this bit is set, the regulator is switched from main mode (MR) to low-power mode (LPR).
148-
int lowPowerMode = PWR->CR1 & PWR_CR1_LPR;
148+
uint32_t lowPowerMode = LL_PWR_IsEnabledLowPowerRunMode();
149+
if (lowPowerMode) {
150+
HAL_PWR_EnterSLEEPMode(PWR_LOWPOWERREGULATOR_ON, PWR_SLEEPENTRY_WFI);
151+
} else {
152+
HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
153+
}
154+
#elif defined(PWR_CR_LPDS) || defined(PWR_CR1_LPDS)
155+
uint32_t lowPowerMode = LL_PWR_GetRegulModeDS();
149156
if (lowPowerMode) {
150157
HAL_PWR_EnterSLEEPMode(PWR_LOWPOWERREGULATOR_ON, PWR_SLEEPENTRY_WFI);
151158
} else {

0 commit comments

Comments
 (0)