1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
32
33
34
35
36
37
45
46
47
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
81
82
83
84
85
86
91
92
93
94
95
96
97
98
99
100
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
119
120
121
122
127
128
129
130
131
132
133
134
135
136
137
140
141
142
143
144
145
146
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
171
176
177
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
228
229
230
231
232
233
234
235
238
239
240
241
242
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
264
268
269
270
289
290
291
292
295
296
/* ... */
#include "main.h"
/* ... */
/* ... */
Includes
static __IO uint8_t ubKeyPressed = 0;
void SystemClock_Config(void);
void Check_IWDG_Reset(void);
void Configure_IWDG(void);
void LED_Init(void);
void LED_On(void);
void UserButton_Init(void);
Private function prototypes
/* ... */
int main(void)
{
SystemClock_Config();
LED_Init();
UserButton_Init();
Check_IWDG_Reset();
Configure_IWDG();
while (1)
{
if (1 != ubKeyPressed)
{
LL_IWDG_ReloadCounter(IWDG);
LL_GPIO_TogglePin(LED2_GPIO_PORT, LED2_PIN);
/* ... */
LL_mDelay(LED_BLINK_FAST);
}if (1 != ubKeyPressed) { ... }
}while (1) { ... }
}{ ... }
/* ... */
void Configure_IWDG(void)
{
LL_RCC_LSI_Enable();
while (LL_RCC_LSI_IsReady() != 1)
{
}while (LL_RCC_LSI_IsReady() != 1) { ... }
LL_IWDG_Enable(IWDG);
LL_IWDG_EnableWriteAccess(IWDG);
LL_IWDG_SetPrescaler(IWDG, LL_IWDG_PRESCALER_4);
LL_IWDG_SetReloadCounter(IWDG, 0xFEE);
while (LL_IWDG_IsReady(IWDG) != 1)
{
...}
LL_IWDG_ReloadCounter(IWDG);
}{ ... }
/* ... */
void Check_IWDG_Reset(void)
{
if (LL_RCC_IsActiveFlag_IWDGRST())
{
LL_RCC_ClearResetFlags();
LED_On();
while(ubKeyPressed != 1)
{
}while (ubKeyPressed != 1) { ... }
ubKeyPressed = 0;
}if (LL_RCC_IsActiveFlag_IWDGRST()) { ... }
}{ ... }
/* ... */
void LED_Init(void)
{
LED2_GPIO_CLK_ENABLE();
LL_GPIO_SetPinMode(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_MODE_OUTPUT);
}{ ... }
/* ... */
void LED_On(void)
{
LL_GPIO_SetOutputPin(LED2_GPIO_PORT, LED2_PIN);
}{ ... }
/* ... */
void UserButton_Init(void)
{
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);
USER_BUTTON_SYSCFG_SET_EXTI();
USER_BUTTON_EXTI_LINE_ENABLE();
USER_BUTTON_EXTI_FALLING_TRIG_ENABLE();
NVIC_SetPriority(USER_BUTTON_EXTI_IRQn,0x03);
NVIC_EnableIRQ(USER_BUTTON_EXTI_IRQn);
}{ ... }
/* ... */
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)
{
ubKeyPressed = 1;
}{ ... }
#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
/* ... */
/* ... */