7
7
******************************************************************************
8
8
* @attention
9
9
*
10
- * <h2><center>© COPYRIGHT(c) 2020 STMicroelectronics</center></h2>
10
+ * Copyright (c) 2020-2021, STMicroelectronics
11
+ * All rights reserved.
11
12
*
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
33
17
*
34
18
******************************************************************************
35
19
*/
@@ -51,7 +35,7 @@ static UART_HandleTypeDef *WakeUpUart = NULL;
51
35
/* Save callback pointer */
52
36
static void (* WakeUpUartCb )(void ) = NULL ;
53
37
54
- #ifdef STM32G0xx
38
+ #if defined( PWR_FLAG_WUF )
55
39
#define PWR_FLAG_WU PWR_FLAG_WUF
56
40
#endif
57
41
@@ -62,7 +46,7 @@ static void (*WakeUpUartCb)(void) = NULL;
62
46
*/
63
47
void LowPower_init ()
64
48
{
65
- #if ! defined(STM32H7xx ) && !defined( STM32MP1xx ) && !defined( STM32WBxx )
49
+ #if defined(__HAL_RCC_PWR_CLK_ENABLE )
66
50
/* Enable Power Clock */
67
51
__HAL_RCC_PWR_CLK_ENABLE ();
68
52
#endif
@@ -211,10 +195,11 @@ void LowPower_stop(serial_t *obj)
211
195
}
212
196
#endif
213
197
214
- #if defined(STM32L0xx ) || defined( STM32L1xx )
198
+ #if defined(PWR_CR_ULP )
215
199
/* Enable Ultra low power mode */
216
200
HAL_PWREx_EnableUltraLowPower ();
217
-
201
+ #endif
202
+ #if defined(PWR_CR_FWU )
218
203
/* Enable the fast wake up from Ultra low power mode */
219
204
HAL_PWREx_EnableFastWakeUp ();
220
205
#endif
@@ -228,7 +213,9 @@ void LowPower_stop(serial_t *obj)
228
213
#endif
229
214
230
215
/* 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
+
232
219
if ((WakeUpUart == NULL ) || (WakeUpUart -> Instance == (USART_TypeDef * )LPUART1_BASE )) {
233
220
// STM32L4xx supports STOP2 mode which halves consumption
234
221
HAL_PWREx_EnterSTOP2Mode (PWR_STOPENTRY_WFI );
@@ -267,10 +254,11 @@ void LowPower_standby()
267
254
{
268
255
__disable_irq ();
269
256
270
- #if defined(STM32L0xx ) || defined( STM32L1xx )
257
+ #if defined(PWR_CR_ULP )
271
258
/* Enable Ultra low power mode */
272
259
HAL_PWREx_EnableUltraLowPower ();
273
-
260
+ #endif
261
+ #if defined(PWR_CR_FWU )
274
262
/* Enable the fast wake up from Ultra low power mode */
275
263
HAL_PWREx_EnableFastWakeUp ();
276
264
#endif
@@ -287,7 +275,7 @@ void LowPower_standby()
287
275
void LowPower_shutdown ()
288
276
{
289
277
__disable_irq ();
290
- #if defined(STM32L4xx ) || defined(STM32L5xx )
278
+ #if defined(PWR_LOWPOWERMODE_SHUTDOWN ) || defined(PWR_CR1_LPMS_SHUTDOWN )
291
279
/* LSE must be on to use shutdown mode */
292
280
if (__HAL_RCC_GET_FLAG (RCC_FLAG_LSERDY ) == SET ) {
293
281
HAL_PWREx_EnterSHUTDOWNMode ();
0 commit comments