Skip to content

Commit 5acd39b

Browse files
committed
drivers: use register definition instead of serie name
This will make future serie additions easier. Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent 648be8e commit 5acd39b

File tree

1 file changed

+18
-30
lines changed

1 file changed

+18
-30
lines changed

src/low_power.c

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,13 @@
77
******************************************************************************
88
* @attention
99
*
10-
* <h2><center>&copy; COPYRIGHT(c) 2020 STMicroelectronics</center></h2>
10+
* Copyright (c) 2020-2021, STMicroelectronics
11+
* All rights reserved.
1112
*
12-
* Redistribution and use in source and binary forms, with or without modification,
13-
* are permitted provided that the following conditions are met:
14-
* 1. Redistributions of source code must retain the above copyright notice,
15-
* this list of conditions and the following disclaimer.
16-
* 2. Redistributions in binary form must reproduce the above copyright notice,
17-
* this list of conditions and the following disclaimer in the documentation
18-
* and/or other materials provided with the distribution.
19-
* 3. Neither the name of STMicroelectronics nor the names of its contributors
20-
* may be used to endorse or promote products derived from this software
21-
* without specific prior written permission.
22-
*
23-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
27-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31-
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13+
* This software component is licensed by ST under BSD 3-Clause license,
14+
* the "License"; You may not use this file except in compliance with the
15+
* License. You may obtain a copy of the License at:
16+
* opensource.org/licenses/BSD-3-Clause
3317
*
3418
******************************************************************************
3519
*/
@@ -51,7 +35,7 @@ static UART_HandleTypeDef *WakeUpUart = NULL;
5135
/* Save callback pointer */
5236
static void (*WakeUpUartCb)(void) = NULL;
5337

54-
#ifdef STM32G0xx
38+
#if defined(PWR_FLAG_WUF)
5539
#define PWR_FLAG_WU PWR_FLAG_WUF
5640
#endif
5741

@@ -62,7 +46,7 @@ static void (*WakeUpUartCb)(void) = NULL;
6246
*/
6347
void LowPower_init()
6448
{
65-
#if !defined(STM32H7xx) && !defined(STM32MP1xx) && !defined(STM32WBxx)
49+
#if defined(__HAL_RCC_PWR_CLK_ENABLE)
6650
/* Enable Power Clock */
6751
__HAL_RCC_PWR_CLK_ENABLE();
6852
#endif
@@ -211,10 +195,11 @@ void LowPower_stop(serial_t *obj)
211195
}
212196
#endif
213197

214-
#if defined(STM32L0xx) || defined(STM32L1xx)
198+
#if defined(PWR_CR_ULP)
215199
/* Enable Ultra low power mode */
216200
HAL_PWREx_EnableUltraLowPower();
217-
201+
#endif
202+
#if defined(PWR_CR_FWU)
218203
/* Enable the fast wake up from Ultra low power mode */
219204
HAL_PWREx_EnableFastWakeUp();
220205
#endif
@@ -228,7 +213,9 @@ void LowPower_stop(serial_t *obj)
228213
#endif
229214

230215
/* Enter Stop mode */
231-
#if defined(STM32L4xx) || defined(STM32L5xx)
216+
#if defined(PWR_CPUCR_RETDS_CD) || defined(PWR_CR1_LPMS_STOP2) ||\
217+
defined(PWR_LOWPOWERMODE_STOP2)
218+
232219
if ((WakeUpUart == NULL) || (WakeUpUart->Instance == (USART_TypeDef *)LPUART1_BASE)) {
233220
// STM32L4xx supports STOP2 mode which halves consumption
234221
HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);
@@ -267,10 +254,11 @@ void LowPower_standby()
267254
{
268255
__disable_irq();
269256

270-
#if defined(STM32L0xx) || defined(STM32L1xx)
257+
#if defined(PWR_CR_ULP)
271258
/* Enable Ultra low power mode */
272259
HAL_PWREx_EnableUltraLowPower();
273-
260+
#endif
261+
#if defined(PWR_CR_FWU)
274262
/* Enable the fast wake up from Ultra low power mode */
275263
HAL_PWREx_EnableFastWakeUp();
276264
#endif
@@ -287,7 +275,7 @@ void LowPower_standby()
287275
void LowPower_shutdown()
288276
{
289277
__disable_irq();
290-
#if defined(STM32L4xx) || defined(STM32L5xx)
278+
#if defined(PWR_LOWPOWERMODE_SHUTDOWN) || defined(PWR_CR1_LPMS_SHUTDOWN)
291279
/* LSE must be on to use shutdown mode */
292280
if (__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == SET) {
293281
HAL_PWREx_EnterSHUTDOWNMode();

0 commit comments

Comments
 (0)