1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
31
32
36
37
40
48
49
50
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
79
80
81
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
158
162
163
164
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
192
193
194
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
258
259
260
261
262
263
264
265
268
269
270
271
272
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
295
302
303
304
323
326
327
/* ... */
#include "main.h"
/* ... */
/* ... */
Includes
#define BUTTON_MODE_GPIO 0
#define BUTTON_MODE_EXTI 1
Private define
uint32_t LedSpeed = LED_BLINK_FAST;
Private variables
void SystemClock_Config(void);
void Configure_PWR(void);
void LED_Init(void);
void LED_Blinking(uint32_t Period);
void UserButton_Init(uint32_t Button_Mode);
uint32_t UserButton_GetState(void);
void EnterStandbyMode(void);Private function prototypes
/* ... */
int main(void)
{
SystemClock_Config();
LED_Init();
UserButton_Init(BUTTON_MODE_GPIO);
Configure_PWR();
UserButton_Init(BUTTON_MODE_EXTI);
LED_Blinking(LedSpeed);
while (1)
{
}while (1) { ... }
}{ ... }
/* ... */
void LED_Init(void)
{
LED2_GPIO_CLK_ENABLE();
LL_GPIO_SetPinMode(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_MODE_OUTPUT);
}{ ... }
/* ... */
void LED_Blinking(uint32_t Period)
{
while (1)
{
LL_GPIO_TogglePin(LED2_GPIO_PORT, LED2_PIN);
LL_mDelay(Period);
}while (1) { ... }
}{ ... }
/* ... */
void UserButton_Init(uint32_t Button_Mode)
{
USER_BUTTON_GPIO_CLK_ENABLE();
LL_GPIO_SetPinMode(USER_BUTTON_GPIO_PORT, USER_BUTTON_PIN, LL_GPIO_MODE_INPUT);
LL_GPIO_SetPinPull(USER_BUTTON_GPIO_PORT, USER_BUTTON_PIN, LL_GPIO_PULL_NO);
if(Button_Mode == BUTTON_MODE_EXTI)
{
USER_BUTTON_SYSCFG_SET_EXTI();
USER_BUTTON_EXTI_LINE_ENABLE();
USER_BUTTON_EXTI_RISING_TRIG_ENABLE();
NVIC_EnableIRQ(USER_BUTTON_EXTI_IRQn);
NVIC_SetPriority(USER_BUTTON_EXTI_IRQn,0x03);
}if (Button_Mode == BUTTON_MODE_EXTI) { ... }
}{ ... }
/* ... */
uint32_t UserButton_GetState(void)
{
return LL_GPIO_IsInputPinSet(USER_BUTTON_GPIO_PORT, USER_BUTTON_PIN);
}{ ... }
/* ... */
void Configure_PWR(void)
{
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR);
if (LL_PWR_IsActiveFlag_SB() != 0)
{
LL_PWR_ClearFlag_SB();
LedSpeed = LED_BLINK_SLOW;
while(UserButton_GetState() == 0){}
}if (LL_PWR_IsActiveFlag_SB() != 0) { ... }
if (LL_PWR_IsActiveFlag_WU() != 0)
{
LL_PWR_ClearFlag_WU();
}if (LL_PWR_IsActiveFlag_WU() != 0) { ... }
}{ ... }
/* ... */
void EnterStandbyMode(void)
{
while(UserButton_GetState() == 0){}
LL_PWR_DisableWakeUpPin(LL_PWR_WAKEUP_PIN1);
LL_PWR_ClearFlag_WU();
LL_PWR_EnableWakeUpPin(LL_PWR_WAKEUP_PIN1);
/* ... */
LL_PWR_SetPowerMode(LL_PWR_MODE_STANDBY);
LL_LPM_EnableDeepSleep();
#if defined ( __CC_ARM)
__force_stores();
#endif
__WFI();
}{ ... }
/* ... */
void SystemClock_Config(void)
{
LL_RCC_HSE_EnableBypass();
LL_RCC_HSE_Enable();
while(LL_RCC_HSE_IsReady() != 1)
{
}while (LL_RCC_HSE_IsReady() != 1) { ... };
LL_FLASH_SetLatency(LL_FLASH_LATENCY_3);
LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE, LL_RCC_PLLM_DIV_8, 400, LL_RCC_PLLP_DIV_4);
LL_RCC_PLL_Enable();
while(LL_RCC_PLL_IsReady() != 1)
{
}while (LL_RCC_PLL_IsReady() != 1) { ... };
LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL);
while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL)
{
}while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) { ... };
LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_2);
LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1);
SysTick_Config(100000000 / 1000);
SystemCoreClock = 100000000;
}{ ... }
/* ... */
void UserButton_Callback(void)
{
EnterStandbyMode();
}{ ... }
#ifdef USE_FULL_ASSERT
/* ... */
void assert_failed(uint8_t *file, uint32_t line)
{
/* ... */
while (1)
{
}while (1) { ... }
}assert_failed (uint8_t *file, uint32_t line) { ... }
/* ... */#endif
/* ... */
/* ... */