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
@@ -94,7 +78,7 @@ void LowPower_EnableWakeUpPin(uint32_t pin, uint32_t mode)
94
78
#if !defined(PWR_WAKEUP_PIN1_HIGH )
95
79
UNUSED (mode );
96
80
#endif
97
- uint32_t wkup_pin ;
81
+ uint32_t wkup_pin = 0 ;
98
82
PinName p = digitalPinToPinName (pin );
99
83
if (p != NC ) {
100
84
#ifdef PWR_WAKEUP_PIN1
@@ -167,7 +151,9 @@ void LowPower_EnableWakeUpPin(uint32_t pin, uint32_t mode)
167
151
wkup_pin = PWR_WAKEUP_PIN8 ;
168
152
}
169
153
#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
+ }
171
157
}
172
158
}
173
159
@@ -211,10 +197,11 @@ void LowPower_stop(serial_t *obj)
211
197
}
212
198
#endif
213
199
214
- #if defined(STM32L0xx ) || defined( STM32L1xx )
200
+ #if defined(PWR_CR_ULP )
215
201
/* Enable Ultra low power mode */
216
202
HAL_PWREx_EnableUltraLowPower ();
217
-
203
+ #endif
204
+ #if defined(PWR_CR_FWU )
218
205
/* Enable the fast wake up from Ultra low power mode */
219
206
HAL_PWREx_EnableFastWakeUp ();
220
207
#endif
@@ -228,7 +215,9 @@ void LowPower_stop(serial_t *obj)
228
215
#endif
229
216
230
217
/* 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
+
232
221
if ((WakeUpUart == NULL ) || (WakeUpUart -> Instance == (USART_TypeDef * )LPUART1_BASE )) {
233
222
// STM32L4xx supports STOP2 mode which halves consumption
234
223
HAL_PWREx_EnterSTOP2Mode (PWR_STOPENTRY_WFI );
@@ -267,10 +256,11 @@ void LowPower_standby()
267
256
{
268
257
__disable_irq ();
269
258
270
- #if defined(STM32L0xx ) || defined( STM32L1xx )
259
+ #if defined(PWR_CR_ULP )
271
260
/* Enable Ultra low power mode */
272
261
HAL_PWREx_EnableUltraLowPower ();
273
-
262
+ #endif
263
+ #if defined(PWR_CR_FWU )
274
264
/* Enable the fast wake up from Ultra low power mode */
275
265
HAL_PWREx_EnableFastWakeUp ();
276
266
#endif
@@ -287,7 +277,7 @@ void LowPower_standby()
287
277
void LowPower_shutdown ()
288
278
{
289
279
__disable_irq ();
290
- #if defined(STM32L4xx ) || defined(STM32L5xx )
280
+ #if defined(PWR_LOWPOWERMODE_SHUTDOWN ) || defined(PWR_CR1_LPMS_SHUTDOWN )
291
281
/* LSE must be on to use shutdown mode */
292
282
if (__HAL_RCC_GET_FLAG (RCC_FLAG_LSERDY ) == SET ) {
293
283
HAL_PWREx_EnterSHUTDOWNMode ();
@@ -329,7 +319,7 @@ void LowPower_EnableWakeUpUart(serial_t *serial, void (*FuncPtr)(void))
329
319
WakeUpSelection .WakeUpEvent = UART_WAKEUP_ON_READDATA_NONEMPTY ;
330
320
HAL_UARTEx_StopModeWakeUpSourceConfig (WakeUpUart , WakeUpSelection );
331
321
332
- /* Enable the UART Wake UP from STOP1 mode Interrupt */
322
+ /* Enable the UART Wake UP from STOPx mode Interrupt */
333
323
__HAL_UART_ENABLE_IT (WakeUpUart , UART_IT_WUF );
334
324
#else
335
325
UNUSED (serial );
0 commit comments