Skip to content

Commit 3f26f9b

Browse files
authored
Merge pull request #58 from fpistm/genericity
drivers: use register definition instead of serie name
2 parents 648be8e + 2eda8a5 commit 3f26f9b

File tree

1 file changed

+23
-33
lines changed

1 file changed

+23
-33
lines changed

src/low_power.c

Lines changed: 23 additions & 33 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
@@ -94,7 +78,7 @@ void LowPower_EnableWakeUpPin(uint32_t pin, uint32_t mode)
9478
#if !defined(PWR_WAKEUP_PIN1_HIGH)
9579
UNUSED(mode);
9680
#endif
97-
uint32_t wkup_pin;
81+
uint32_t wkup_pin = 0;
9882
PinName p = digitalPinToPinName(pin);
9983
if (p != NC) {
10084
#ifdef PWR_WAKEUP_PIN1
@@ -167,7 +151,9 @@ void LowPower_EnableWakeUpPin(uint32_t pin, uint32_t mode)
167151
wkup_pin = PWR_WAKEUP_PIN8;
168152
}
169153
#endif /* PWR_WAKEUP_PIN8 */
170-
HAL_PWR_EnableWakeUpPin(wkup_pin);
154+
if (IS_PWR_WAKEUP_PIN(wkup_pin)) {
155+
HAL_PWR_EnableWakeUpPin(wkup_pin);
156+
}
171157
}
172158
}
173159

@@ -211,10 +197,11 @@ void LowPower_stop(serial_t *obj)
211197
}
212198
#endif
213199

214-
#if defined(STM32L0xx) || defined(STM32L1xx)
200+
#if defined(PWR_CR_ULP)
215201
/* Enable Ultra low power mode */
216202
HAL_PWREx_EnableUltraLowPower();
217-
203+
#endif
204+
#if defined(PWR_CR_FWU)
218205
/* Enable the fast wake up from Ultra low power mode */
219206
HAL_PWREx_EnableFastWakeUp();
220207
#endif
@@ -228,7 +215,9 @@ void LowPower_stop(serial_t *obj)
228215
#endif
229216

230217
/* Enter Stop mode */
231-
#if defined(STM32L4xx) || defined(STM32L5xx)
218+
#if defined(PWR_CPUCR_RETDS_CD) || defined(PWR_CR1_LPMS_STOP2) ||\
219+
defined(PWR_LOWPOWERMODE_STOP2)
220+
232221
if ((WakeUpUart == NULL) || (WakeUpUart->Instance == (USART_TypeDef *)LPUART1_BASE)) {
233222
// STM32L4xx supports STOP2 mode which halves consumption
234223
HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);
@@ -267,10 +256,11 @@ void LowPower_standby()
267256
{
268257
__disable_irq();
269258

270-
#if defined(STM32L0xx) || defined(STM32L1xx)
259+
#if defined(PWR_CR_ULP)
271260
/* Enable Ultra low power mode */
272261
HAL_PWREx_EnableUltraLowPower();
273-
262+
#endif
263+
#if defined(PWR_CR_FWU)
274264
/* Enable the fast wake up from Ultra low power mode */
275265
HAL_PWREx_EnableFastWakeUp();
276266
#endif
@@ -287,7 +277,7 @@ void LowPower_standby()
287277
void LowPower_shutdown()
288278
{
289279
__disable_irq();
290-
#if defined(STM32L4xx) || defined(STM32L5xx)
280+
#if defined(PWR_LOWPOWERMODE_SHUTDOWN) || defined(PWR_CR1_LPMS_SHUTDOWN)
291281
/* LSE must be on to use shutdown mode */
292282
if (__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == SET) {
293283
HAL_PWREx_EnterSHUTDOWNMode();
@@ -329,7 +319,7 @@ void LowPower_EnableWakeUpUart(serial_t *serial, void (*FuncPtr)(void))
329319
WakeUpSelection.WakeUpEvent = UART_WAKEUP_ON_READDATA_NONEMPTY;
330320
HAL_UARTEx_StopModeWakeUpSourceConfig(WakeUpUart, WakeUpSelection);
331321

332-
/* Enable the UART Wake UP from STOP1 mode Interrupt */
322+
/* Enable the UART Wake UP from STOPx mode Interrupt */
333323
__HAL_UART_ENABLE_IT(WakeUpUart, UART_IT_WUF);
334324
#else
335325
UNUSED(serial);

0 commit comments

Comments
 (0)