Select one of the symbols to view example projects that use it.
 
Outline
Includes
#include "main.h"
#define KEY_PRESSED
#define KEY_NOT_PRESSED
#define TIM_ARR
#define TIM_CCR
#define CURSOR_STEP
#define ABS
#define MAX_AB
Private variables
UserButtonPressed
DemoEnterCondition
X_Offset
Y_Offset
Buffer
ThreadholdAcceleroLow
ThreadholdAcceleroHigh
hUSBDDevice
PrescalerValue
htim4
sConfigTim4
Counter
MaxAcceleration
Private function prototypes
main()
Demo_Exec()
Demo_USBConfig()
TIM4_Config()
HAL_SYSTICK_Callback()
HAL_GPIO_EXTI_Callback(uint16_t)
USBD_HID_GetPos()
Error_Handler()
SystemClock_Config()
Files
loading...
CodeScopeSTM32 Libraries and SamplesDemonstrationsSrc/main.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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
80
81
82
83
84
85
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
111
112
113
114
115
116
117
118
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
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
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file Demonstrations/Src/main.c * @author MCD Application Team * @brief This demo describes how to use accelerometer to control mouse on * PC. ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** *//* ... */ /* Includes ------------------------------------------------------------------*/ #include "main.h" /** @addtogroup STM32F4xx_HAL_Demonstrations * @{ *//* ... */ /** @addtogroup Demo * @{ *//* ... */ Includes /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ #define KEY_PRESSED 0x01 #define KEY_NOT_PRESSED 0x00 /* TIM4 Autoreload and Capture Compare register values */ #define TIM_ARR (uint16_t)1999 #define TIM_CCR (uint16_t)1000 #define CURSOR_STEP 7 /* Private macro -------------------------------------------------------------*/ #define ABS(x) (x < 0) ? (-x) : x #define MAX_AB(a,b) (a < b) ? (b) : a 7 defines /* Private variables ---------------------------------------------------------*/ __IO uint8_t UserButtonPressed = 0x00; __IO uint8_t DemoEnterCondition = 0x00; /* Variables used for accelerometer */ __IO int16_t X_Offset, Y_Offset; int16_t Buffer[3]; /* MEMS thresholds {Low/High} */ static int16_t ThreadholdAcceleroLow = -1500, ThreadholdAcceleroHigh = 1500; /* Variables used for USB */ USBD_HandleTypeDef hUSBDDevice; /* Variables used for timer */ uint16_t PrescalerValue = 0; TIM_HandleTypeDef htim4; TIM_OC_InitTypeDef sConfigTim4; /* Variables used during Systick ISR */ uint8_t Counter = 0x00; __IO uint16_t MaxAcceleration = 0; Private variables /* Private function prototypes -----------------------------------------------*/ static uint32_t Demo_USBConfig(void); static void TIM4_Config(void); static void Demo_Exec(void); static uint8_t *USBD_HID_GetPos(void); static void SystemClock_Config(void); static void Error_Handler(void); Private function prototypes /* Private functions ---------------------------------------------------------*/ /** * @brief Main program * @param None * @retval None *//* ... */ int main(void) { /* STM32F4xx HAL library initialization: - Configure the Flash prefetch, instruction and Data caches - Configure the Systick to generate an interrupt each 1 msec - Set NVIC Group Priority to 4 - Global MSP (MCU Support Package) initialization *//* ... */ HAL_Init(); /* Configure LED4, LED3, LED5 and LED6 */ BSP_LED_Init(LED4); BSP_LED_Init(LED3); BSP_LED_Init(LED5); BSP_LED_Init(LED6); /* Configure the system clock to 84 MHz */ SystemClock_Config(); /* Initialize User_Button */ BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_EXTI); /* Execute Demo application */ Demo_Exec(); /* Infinite loop */ while (1) { }while (1) { ... } }{ ... } /** * @brief Execute the demo application. * @param None * @retval None *//* ... */ static void Demo_Exec(void) { uint8_t togglecounter = 0x00; /* Initialize Accelerometer MEMS*/ if(BSP_ACCELERO_Init() != HAL_OK) { /* Initialization Error */ Error_Handler(); }if (BSP_ACCELERO_Init() != HAL_OK) { ... } while(1) { DemoEnterCondition = 0x00; /* Reset UserButton_Pressed variable */ UserButtonPressed = 0x00; /* Configure LEDs to be managed by GPIO */ BSP_LED_Init(LED3); BSP_LED_Init(LED4); BSP_LED_Init(LED5); BSP_LED_Init(LED6); /* SysTick end of count event each 10ms */ SystemCoreClock = HAL_RCC_GetHCLKFreq(); SysTick_Config(SystemCoreClock / 100); /* Turn OFF all LEDs */ BSP_LED_Off(LED4); BSP_LED_Off(LED3); BSP_LED_Off(LED5); BSP_LED_Off(LED6); /* Waiting User Button is pressed */ while (UserButtonPressed == 0x00) { /* Toggle LED4 */ BSP_LED_Toggle(LED4); HAL_Delay(10); /* Toggle LED4 */ BSP_LED_Toggle(LED3); HAL_Delay(10); /* Toggle LED4 */ BSP_LED_Toggle(LED5); HAL_Delay(10); /* Toggle LED4 */ BSP_LED_Toggle(LED6); HAL_Delay(10); togglecounter ++; if (togglecounter == 0x10) { togglecounter = 0x00; while (togglecounter < 0x10) { BSP_LED_Toggle(LED4); BSP_LED_Toggle(LED3); BSP_LED_Toggle(LED5); BSP_LED_Toggle(LED6); HAL_Delay(10); togglecounter ++; }while (togglecounter < 0x10) { ... } togglecounter = 0x00; }if (togglecounter == 0x10) { ... } }while (UserButtonPressed == 0x00) { ... } /* Waiting User Button is Released */ while (BSP_PB_GetState(BUTTON_KEY) != KEY_NOT_PRESSED) {}while (BSP_PB_GetState(BUTTON_KEY) != KEY_NOT_PRESSED) { ... } UserButtonPressed = 0x00; /* TIM4 channels configuration */ TIM4_Config(); DemoEnterCondition = 0x01; /* USB configuration */ Demo_USBConfig(); /* Waiting User Button is pressed */ while (UserButtonPressed == 0x00) {}while (UserButtonPressed == 0x00) { ... } /* Waiting User Button is Released */ while (BSP_PB_GetState(BUTTON_KEY) != KEY_NOT_PRESSED) {}while (BSP_PB_GetState(BUTTON_KEY) != KEY_NOT_PRESSED) { ... } /* Disconnect the USB device */ USBD_Stop(&hUSBDDevice); USBD_DeInit(&hUSBDDevice); if(HAL_TIM_PWM_DeInit(&htim4) != HAL_OK) { /* Initialization Error */ Error_Handler(); }if (HAL_TIM_PWM_DeInit(&htim4) != HAL_OK) { ... } }while (1) { ... } }{ ... } /** * @brief Initializes the USB for the demonstration application. * @param None * @retval None *//* ... */ static uint32_t Demo_USBConfig(void) { /* Init Device Library */ USBD_Init(&hUSBDDevice, &HID_Desc, 0); /* Add Supported Class */ USBD_RegisterClass(&hUSBDDevice, USBD_HID_CLASS); /* Start Device Process */ USBD_Start(&hUSBDDevice); return 0; }{ ... } /** * @brief Configures the TIM Peripheral. * @param None * @retval None *//* ... */ static void TIM4_Config(void) { /* ----------------------------------------------------------------------- TIM4 Configuration: Output Compare Timing Mode: In this example TIM4 input clock (TIM4CLK) is set to 2 * APB1 clock (PCLK1), since APB1 prescaler is different from 1 (APB1 Prescaler = 4, see system_stm32f4xx.c file). TIM4CLK = 2 * PCLK1 PCLK1 = HCLK / 4 => TIM4CLK = 2*(HCLK / 4) = HCLK/2 = SystemCoreClock/2 To get TIM4 counter clock at 2 KHz, the prescaler is computed as follows: Prescaler = (TIM4CLK / TIM4 counter clock) - 1 Prescaler = (84 MHz/(2 * 2 KHz)) - 1 = 41999 To get TIM4 output clock at 1 Hz, the period (ARR)) is computed as follows: ARR = (TIM4 counter clock / TIM4 output clock) - 1 = 1999 TIM4 Channel1 duty cycle = (TIM4_CCR1/ TIM4_ARR)* 100 = 50% TIM4 Channel2 duty cycle = (TIM4_CCR2/ TIM4_ARR)* 100 = 50% TIM4 Channel3 duty cycle = (TIM4_CCR3/ TIM4_ARR)* 100 = 50% TIM4 Channel4 duty cycle = (TIM4_CCR4/ TIM4_ARR)* 100 = 50% ==> TIM4_CCRx = TIM4_ARR/2 = 1000 (where x = 1, 2, 3 and 4). ----------------------------------------------------------------------- *//* ... */ /* Compute the prescaler value */ PrescalerValue = (uint16_t) ((SystemCoreClock /2) / 2000) - 1; /* Time base configuration */ htim4.Instance = TIM4; htim4.Init.Period = TIM_ARR; htim4.Init.Prescaler = PrescalerValue; htim4.Init.ClockDivision = 0; htim4.Init.CounterMode = TIM_COUNTERMODE_UP; if(HAL_TIM_PWM_Init(&htim4) != HAL_OK) { /* Initialization Error */ Error_Handler(); }if (HAL_TIM_PWM_Init(&htim4) != HAL_OK) { ... } /* TIM PWM1 Mode configuration: Channel */ /* Output Compare Timing Mode configuration: Channel1 */ sConfigTim4.OCMode = TIM_OCMODE_PWM1; sConfigTim4.OCIdleState = TIM_CCx_ENABLE; sConfigTim4.Pulse = TIM_CCR; sConfigTim4.OCPolarity = TIM_OCPOLARITY_HIGH; /* Output Compare PWM1 Mode configuration: Channel1 */ if(HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigTim4, TIM_CHANNEL_1) != HAL_OK) { /* Initialization Error */ Error_Handler(); }if (HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigTim4, TIM_CHANNEL_1) != HAL_OK) { ... } /* Output Compare PWM1 Mode configuration: Channel2 */ if(HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigTim4, TIM_CHANNEL_2) != HAL_OK) { /* Initialization Error */ Error_Handler(); }if (HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigTim4, TIM_CHANNEL_2) != HAL_OK) { ... } /* Output Compare PWM1 Mode configuration: Channel3 */ if(HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigTim4, TIM_CHANNEL_3) != HAL_OK) { /* Initialization Error */ Error_Handler(); }if (HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigTim4, TIM_CHANNEL_3) != HAL_OK) { ... } /* Output Compare PWM1 Mode configuration: Channel4 */ if(HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigTim4, TIM_CHANNEL_4) != HAL_OK) { /* Initialization Error */ Error_Handler(); }if (HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigTim4, TIM_CHANNEL_4) != HAL_OK) { ... } }{ ... } /** * @brief SYSTICK callback. * @param None * @retval None *//* ... */ void HAL_SYSTICK_Callback(void) { uint8_t *buf; uint16_t Temp_X, Temp_Y = 0x00; uint16_t NewARR_X, NewARR_Y = 0x00; if (DemoEnterCondition != 0x00) { buf = USBD_HID_GetPos(); if((buf[1] != 0) ||(buf[2] != 0)) { USBD_HID_SendReport (&hUSBDDevice, buf, 4); }if ((buf[1] != 0) ||(buf[2] != 0)) { ... } Counter ++; if (Counter == 10) { /* Reset Buffer used to get accelerometer values */ Buffer[0] = 0; Buffer[1] = 0; /* Disable All TIM4 Capture Compare Channels */ HAL_TIM_PWM_Stop(&htim4, TIM_CHANNEL_1); HAL_TIM_PWM_Stop(&htim4, TIM_CHANNEL_2); HAL_TIM_PWM_Stop(&htim4, TIM_CHANNEL_3); HAL_TIM_PWM_Stop(&htim4, TIM_CHANNEL_4); /* Read Acceleration*/ BSP_ACCELERO_GetXYZ(Buffer); /* Set X and Y positions */ X_Offset = Buffer[0]; Y_Offset = Buffer[1]; /* Update New autoreload value in case of X or Y acceleration*/ /* Basic acceleration X_Offset and Y_Offset are divide by 40 to fir with ARR range */ NewARR_X = TIM_ARR - ABS(X_Offset/40); NewARR_Y = TIM_ARR - ABS(Y_Offset/40); /* Calculation of Max acceleration detected on X or Y axis */ Temp_X = ABS(X_Offset/40); Temp_Y = ABS(Y_Offset/40); MaxAcceleration = MAX_AB(Temp_X, Temp_Y); if(MaxAcceleration != 0) { /* Reset CNT to a lowest value (equal to min CCRx of all Channels) */ __HAL_TIM_SET_COUNTER(&htim4,(TIM_ARR-MaxAcceleration)/2); if (X_Offset < ThreadholdAcceleroLow) { /* Sets the TIM4 Capture Compare for Channel1 Register value */ /* Equal to NewARR_X/2 to have duty cycle equal to 50% */ __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_1, NewARR_X/2); /* Time base configuration */ __HAL_TIM_SET_AUTORELOAD(&htim4, NewARR_X); /* Enable TIM4 Capture Compare Channel1 */ HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_1); }if (X_Offset < ThreadholdAcceleroLow) { ... } else if (X_Offset > ThreadholdAcceleroHigh) { /* Sets the TIM4 Capture Compare for Channel3 Register value */ /* Equal to NewARR_X/2 to have duty cycle equal to 50% */ __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_3, NewARR_X/2); /* Time base configuration */ __HAL_TIM_SET_AUTORELOAD(&htim4, NewARR_X); /* Enable TIM4 Capture Compare Channel3 */ HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_3); }else if (X_Offset > ThreadholdAcceleroHigh) { ... } if (Y_Offset > ThreadholdAcceleroHigh) { /* Sets the TIM4 Capture Compare for Channel4 Register value */ /* Equal to NewARR_Y/2 to have duty cycle equal to 50% */ __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_4,NewARR_Y/2); /* Time base configuration */ __HAL_TIM_SET_AUTORELOAD(&htim4, NewARR_Y); /* Enable TIM4 Capture Compare Channel4 */ HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_4); }if (Y_Offset > ThreadholdAcceleroHigh) { ... } else if (Y_Offset < ThreadholdAcceleroLow) { /* Sets the TIM4 Capture Compare for Channel2 Register value */ /* Equal to NewARR_Y/2 to have duty cycle equal to 50% */ __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_2, NewARR_Y/2); /* Time base configuration */ __HAL_TIM_SET_AUTORELOAD(&htim4, NewARR_Y); /* Enable TIM4 Capture Compare Channel2 */ HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_2); }else if (Y_Offset < ThreadholdAcceleroLow) { ... } }if (MaxAcceleration != 0) { ... } Counter = 0x00; }if (Counter == 10) { ... } }if (DemoEnterCondition != 0x00) { ... } }{ ... } /** * @brief EXTI line detection callbacks. * @param GPIO_Pin: Specifies the pins connected EXTI line * @retval None *//* ... */ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { if(GPIO_Pin == KEY_BUTTON_PIN) { UserButtonPressed = 0x01; }if (GPIO_Pin == KEY_BUTTON_PIN) { ... } }{ ... } /** * @brief USBD_HID_GetPos * @param None * @retval Pointer to report *//* ... */ static uint8_t *USBD_HID_GetPos(void) { static uint8_t HID_Buffer[4] = {0}; HID_Buffer[1] = 0; HID_Buffer[2] = 0; /* LEFT Direction */ if((X_Offset) < ThreadholdAcceleroLow) { HID_Buffer[1] -= CURSOR_STEP; }if ((X_Offset) < ThreadholdAcceleroLow) { ... } /* RIGHT Direction */ if((X_Offset) > ThreadholdAcceleroHigh) { HID_Buffer[1] += CURSOR_STEP; }if ((X_Offset) > ThreadholdAcceleroHigh) { ... } /* DOWN Direction */ if((Y_Offset) < ThreadholdAcceleroLow) { HID_Buffer[2] += CURSOR_STEP; }if ((Y_Offset) < ThreadholdAcceleroLow) { ... } /* UP Direction */ if((Y_Offset) > ThreadholdAcceleroHigh) { HID_Buffer[2] -= CURSOR_STEP; }if ((Y_Offset) > ThreadholdAcceleroHigh) { ... } return HID_Buffer; }{ ... } /** * @brief This function is executed in case of error occurrence. * @param None * @retval None *//* ... */ static void Error_Handler(void) { /* Turn LED4 on */ BSP_LED_On(LED4); while(1) { }while (1) { ... } }{ ... } /** * @brief System Clock Configuration * The system Clock is configured as follow : * System Clock source = PLL (HSE) * SYSCLK(Hz) = 84000000 * HCLK(Hz) = 84000000 * AHB Prescaler = 1 * APB1 Prescaler = 2 * APB2 Prescaler = 1 * HSE Frequency(Hz) = 8000000 * PLL_M = 8 * PLL_N = 336 * PLL_P = 4 * PLL_Q = 7 * VDD(V) = 3.3 * Main regulator output voltage = Scale2 mode * Flash Latency(WS) = 2 * @param None * @retval None *//* ... */ static void SystemClock_Config(void) { RCC_ClkInitTypeDef RCC_ClkInitStruct; RCC_OscInitTypeDef RCC_OscInitStruct; /* Enable Power Control clock */ __HAL_RCC_PWR_CLK_ENABLE(); /* The voltage scaling allows optimizing the power consumption when the device is clocked below the maximum system frequency, to update the voltage scaling value regarding system frequency refer to product datasheet. *//* ... */ __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2); /* Enable HSE Oscillator and activate PLL with HSE as source */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; RCC_OscInitStruct.HSEState = RCC_HSE_ON; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; RCC_OscInitStruct.PLL.PLLM = 8; RCC_OscInitStruct.PLL.PLLN = 336; RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; RCC_OscInitStruct.PLL.PLLQ = 7; HAL_RCC_OscConfig(&RCC_OscInitStruct); /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers *//* ... */ RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2); }{ ... } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None *//* ... */ void assert_failed(uint8_t* file, uint32_t line) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) *//* ... */ /* Infinite loop */ while (1) { }while (1) { ... } }assert_failed (uint8_t* file, uint32_t line) { ... } /* ... */#endif /** * @} *//* ... */ /** * @} *//* ... */