|
1 | 1 | /* |
2 | | - * Copyright (c) 2006-2018, RT-Thread Development Team |
| 2 | + * Copyright (c) 2006-2021, RT-Thread Development Team |
3 | 3 | * |
4 | 4 | * SPDX-License-Identifier: Apache-2.0 |
5 | 5 | * |
|
16 | 16 | */ |
17 | 17 | void SystemClock_Config(void) |
18 | 18 | { |
19 | | - RCC_OscInitTypeDef RCC_OscInitStruct = {0}; |
20 | | - RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; |
21 | | - RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0}; |
| 19 | + RCC_OscInitTypeDef RCC_OscInitStruct = {0}; |
| 20 | + RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; |
| 21 | + RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0}; |
22 | 22 |
|
23 | | - /** Supply configuration update enable |
24 | | - */ |
25 | | - HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY); |
26 | | - /** Configure the main internal regulator output voltage |
27 | | - */ |
28 | | - __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE0); |
| 23 | + /** Supply configuration update enable |
| 24 | + */ |
| 25 | + HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY); |
| 26 | + /** Configure the main internal regulator output voltage |
| 27 | + */ |
| 28 | + __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE0); |
29 | 29 |
|
30 | | - while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {} |
31 | | - /** Initializes the RCC Oscillators according to the specified parameters |
32 | | - * in the RCC_OscInitTypeDef structure. |
33 | | - */ |
34 | | - RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; |
35 | | - RCC_OscInitStruct.HSEState = RCC_HSE_ON; |
36 | | - RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
37 | | - RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; |
38 | | - RCC_OscInitStruct.PLL.PLLM = 5; |
39 | | - RCC_OscInitStruct.PLL.PLLN = 192; |
40 | | - RCC_OscInitStruct.PLL.PLLP = 2; |
41 | | - RCC_OscInitStruct.PLL.PLLQ = 2; |
42 | | - RCC_OscInitStruct.PLL.PLLR = 2; |
43 | | - RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_2; |
44 | | - RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE; |
45 | | - RCC_OscInitStruct.PLL.PLLFRACN = 0; |
46 | | - if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) |
47 | | - { |
48 | | - Error_Handler(); |
49 | | - } |
50 | | - /** Initializes the CPU, AHB and APB buses clocks |
51 | | - */ |
52 | | - RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |
53 | | - |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2 |
54 | | - |RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1; |
55 | | - RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
56 | | - RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1; |
57 | | - RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV2; |
58 | | - RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV2; |
59 | | - RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV2; |
60 | | - RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV2; |
61 | | - RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV2; |
| 30 | + while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {} |
| 31 | + |
| 32 | + /** Initializes the RCC Oscillators according to the specified parameters |
| 33 | + * in the RCC_OscInitTypeDef structure. |
| 34 | + */ |
| 35 | + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; |
| 36 | + RCC_OscInitStruct.HSEState = RCC_HSE_ON; |
| 37 | + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
| 38 | + RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; |
| 39 | + RCC_OscInitStruct.PLL.PLLM = 5; |
| 40 | + RCC_OscInitStruct.PLL.PLLN = 192; |
| 41 | + RCC_OscInitStruct.PLL.PLLP = 2; |
| 42 | + RCC_OscInitStruct.PLL.PLLQ = 2; |
| 43 | + RCC_OscInitStruct.PLL.PLLR = 2; |
| 44 | + RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_2; |
| 45 | + RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE; |
| 46 | + RCC_OscInitStruct.PLL.PLLFRACN = 0; |
| 47 | + |
| 48 | + if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) |
| 49 | + { |
| 50 | + Error_Handler(); |
| 51 | + } |
| 52 | + |
| 53 | + /** Initializes the CPU, AHB and APB buses clocks |
| 54 | + */ |
| 55 | + RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK |
| 56 | + | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2 |
| 57 | + | RCC_CLOCKTYPE_D3PCLK1 | RCC_CLOCKTYPE_D1PCLK1; |
| 58 | + RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
| 59 | + RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1; |
| 60 | + RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV2; |
| 61 | + RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV2; |
| 62 | + RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV2; |
| 63 | + RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV2; |
| 64 | + RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV2; |
| 65 | + |
| 66 | + if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK) |
| 67 | + { |
| 68 | + Error_Handler(); |
| 69 | + } |
| 70 | + |
| 71 | + PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC | RCC_PERIPHCLK_USART3 |
| 72 | + | RCC_PERIPHCLK_UART4 | RCC_PERIPHCLK_SPI4 |
| 73 | + | RCC_PERIPHCLK_SPI1 | RCC_PERIPHCLK_SDMMC |
| 74 | + | RCC_PERIPHCLK_ADC | RCC_PERIPHCLK_USB |
| 75 | + | RCC_PERIPHCLK_LPTIM1 | RCC_PERIPHCLK_FMC; |
| 76 | + PeriphClkInitStruct.PLL2.PLL2M = 2; |
| 77 | + PeriphClkInitStruct.PLL2.PLL2N = 64; |
| 78 | + PeriphClkInitStruct.PLL2.PLL2P = 2; |
| 79 | + PeriphClkInitStruct.PLL2.PLL2Q = 2; |
| 80 | + PeriphClkInitStruct.PLL2.PLL2R = 4; |
| 81 | + PeriphClkInitStruct.PLL2.PLL2RGE = RCC_PLL2VCIRANGE_3; |
| 82 | + PeriphClkInitStruct.PLL2.PLL2VCOSEL = RCC_PLL2VCOWIDE; |
| 83 | + PeriphClkInitStruct.PLL2.PLL2FRACN = 0; |
| 84 | + PeriphClkInitStruct.PLL3.PLL3M = 5; |
| 85 | + PeriphClkInitStruct.PLL3.PLL3N = 160; |
| 86 | + PeriphClkInitStruct.PLL3.PLL3P = 8; |
| 87 | + PeriphClkInitStruct.PLL3.PLL3Q = 8; |
| 88 | + PeriphClkInitStruct.PLL3.PLL3R = 24; |
| 89 | + PeriphClkInitStruct.PLL3.PLL3RGE = RCC_PLL3VCIRANGE_2; |
| 90 | + PeriphClkInitStruct.PLL3.PLL3VCOSEL = RCC_PLL3VCOWIDE; |
| 91 | + PeriphClkInitStruct.PLL3.PLL3FRACN = 0; |
| 92 | + PeriphClkInitStruct.FmcClockSelection = RCC_FMCCLKSOURCE_PLL2; |
| 93 | + PeriphClkInitStruct.SdmmcClockSelection = RCC_SDMMCCLKSOURCE_PLL2; |
| 94 | + PeriphClkInitStruct.Spi123ClockSelection = RCC_SPI123CLKSOURCE_PLL2; |
| 95 | + PeriphClkInitStruct.Spi45ClockSelection = RCC_SPI45CLKSOURCE_PLL3; |
| 96 | + PeriphClkInitStruct.Usart234578ClockSelection = RCC_USART234578CLKSOURCE_D2PCLK1; |
| 97 | + PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_HSI48; |
| 98 | + PeriphClkInitStruct.Lptim1ClockSelection = RCC_LPTIM1CLKSOURCE_LSI; |
| 99 | + PeriphClkInitStruct.AdcClockSelection = RCC_ADCCLKSOURCE_PLL2; |
| 100 | + |
| 101 | + if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) |
| 102 | + { |
| 103 | + Error_Handler(); |
| 104 | + } |
62 | 105 |
|
63 | | - if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK) |
64 | | - { |
65 | | - Error_Handler(); |
66 | | - } |
67 | | - PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USART3|RCC_PERIPHCLK_UART4; |
68 | | - PeriphClkInitStruct.Usart234578ClockSelection = RCC_USART234578CLKSOURCE_D2PCLK1; |
69 | | - if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) |
70 | | - { |
71 | | - Error_Handler(); |
72 | | - } |
| 106 | + /** Enable USB Voltage detector |
| 107 | + */ |
| 108 | + HAL_PWREx_EnableUSBVoltageDetector(); |
73 | 109 | } |
74 | 110 |
|
0 commit comments