|
53 | 53 | //--------------------------------------------------------------------+ |
54 | 54 | // RCC Clock |
55 | 55 | //--------------------------------------------------------------------+ |
56 | | -static inline void board_stm32h7_clock_init(void) |
57 | | -{ |
58 | | - RCC_ClkInitTypeDef RCC_ClkInitStruct = { 0 }; |
59 | | - RCC_OscInitTypeDef RCC_OscInitStruct = { 0 }; |
| 56 | +static inline void SystemClock_Config(void) { |
| 57 | + RCC_OscInitTypeDef RCC_OscInitStruct = {0}; |
| 58 | + RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; |
| 59 | + |
| 60 | + /** Supply configuration update enable |
| 61 | + */ |
| 62 | + HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY); |
60 | 63 |
|
61 | | - /* The PWR block is always enabled on the H7 series- there is no clock |
62 | | - enable. For now, use the default VOS3 scale mode (lowest) and limit clock |
63 | | - frequencies to avoid potential current draw problems from bus |
64 | | - power when using the max clock speeds throughout the chip. */ |
| 64 | + /** Configure the main internal regulator output voltage |
| 65 | + */ |
| 66 | + __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); |
65 | 67 |
|
66 | | - /* Enable HSE Oscillator and activate PLL1 with HSE as source */ |
| 68 | + while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {} |
| 69 | + |
| 70 | + /** Initializes the RCC Oscillators according to the specified parameters |
| 71 | + * in the RCC_OscInitTypeDef structure. |
| 72 | + */ |
67 | 73 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; |
68 | | - RCC_OscInitStruct.HSEState = RCC_HSE_ON; |
69 | | - RCC_OscInitStruct.HSIState = RCC_HSI_OFF; |
70 | | - RCC_OscInitStruct.CSIState = RCC_CSI_OFF; |
| 74 | + RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS; |
71 | 75 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
72 | 76 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; |
73 | | - RCC_OscInitStruct.PLL.PLLM = HSE_VALUE/1000000; |
74 | | - RCC_OscInitStruct.PLL.PLLN = 336; |
| 77 | + RCC_OscInitStruct.PLL.PLLM = 1; |
| 78 | + RCC_OscInitStruct.PLL.PLLN = 100; |
75 | 79 | RCC_OscInitStruct.PLL.PLLP = 2; |
76 | | - RCC_OscInitStruct.PLL.PLLQ = 7; |
77 | | - RCC_OscInitStruct.PLL.PLLR = 2; /* Unused */ |
78 | | - RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_0; |
79 | | - RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOMEDIUM; |
| 80 | + RCC_OscInitStruct.PLL.PLLQ = 4; |
| 81 | + RCC_OscInitStruct.PLL.PLLR = 2; |
| 82 | + RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_3; |
| 83 | + RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE; |
80 | 84 | RCC_OscInitStruct.PLL.PLLFRACN = 0; |
81 | | - HAL_RCC_OscConfig(&RCC_OscInitStruct); |
82 | | - |
83 | | - RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | \ |
84 | | - RCC_CLOCKTYPE_D1PCLK1 | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2 | \ |
85 | | - RCC_CLOCKTYPE_D3PCLK1); |
| 85 | + if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) |
| 86 | + { |
| 87 | + Error_Handler(); |
| 88 | + } |
| 89 | + |
| 90 | + /** Initializes the CPU, AHB and APB buses clocks |
| 91 | + */ |
| 92 | + RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |
| 93 | + |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2 |
| 94 | + |RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1; |
86 | 95 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
87 | 96 | RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1; |
88 | | - RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV1; |
89 | | - |
90 | | - /* Unlike on the STM32F4 family, it appears the maximum APB frequencies are |
91 | | - device-dependent- 120 MHz for this board according to Figure 2 of |
92 | | - the datasheet. Dividing by half will be safe for now. */ |
| 97 | + RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV2; |
93 | 98 | RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV2; |
94 | 99 | RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV2; |
95 | 100 | RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV2; |
96 | 101 | RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV2; |
97 | 102 |
|
98 | | - /* 4 wait states required for 168MHz and VOS3. */ |
99 | | - HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4); |
100 | | - |
101 | | - /* Like on F4, on H7, USB's actual peripheral clock and bus clock are |
102 | | - separate. However, the main system PLL (PLL1) doesn't have a direct |
103 | | - connection to the USB peripheral clock to generate 48 MHz, so we do this |
104 | | - dance. This will connect PLL1's Q output to the USB peripheral clock. */ |
105 | | - RCC_PeriphCLKInitTypeDef RCC_PeriphCLKInitStruct = { 0 }; |
106 | | - |
107 | | - RCC_PeriphCLKInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USB; |
108 | | - RCC_PeriphCLKInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_PLL; |
109 | | - HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphCLKInitStruct); |
| 103 | + if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) |
| 104 | + { |
| 105 | + Error_Handler(); |
| 106 | + } |
| 107 | + |
| 108 | + // Initialize USB clock |
| 109 | + RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = { 0 }; |
| 110 | + PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USB; |
| 111 | + PeriphClkInitStruct.PLL3.PLL3M = 1; |
| 112 | + PeriphClkInitStruct.PLL3.PLL3N = 24; |
| 113 | + PeriphClkInitStruct.PLL3.PLL3P = 2; |
| 114 | + PeriphClkInitStruct.PLL3.PLL3Q = 4; |
| 115 | + PeriphClkInitStruct.PLL3.PLL3R = 2; |
| 116 | + PeriphClkInitStruct.PLL3.PLL3RGE = RCC_PLL3VCIRANGE_3; |
| 117 | + PeriphClkInitStruct.PLL3.PLL3FRACN = 0; |
| 118 | + PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_PLL3; |
| 119 | + if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) |
| 120 | + { |
| 121 | + Error_Handler(); |
| 122 | + } |
110 | 123 | } |
111 | 124 |
|
112 | 125 | static inline void board_stm32h7_post_init(void) |
|
0 commit comments