2 Copyright (c) 2011 Arduino. All right reserved.
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 See the GNU Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #include "pins_arduino.h"
28 const PinName digitalPin
[] = {
36 PC_14
, //D7 - By default, SB6 open PF0/PC14 not connected to D7
37 PC_15
, //D8 - By default, SB8 open PF1/PC15 not connected to D8
50 PA_2
, //D21/A7 - STLink Tx
51 PA_15
//D22 - STLink Rx
54 // If analog pins are not contiguous in the digitalPin array:
55 // Add the analogInputPin array without defining NUM_ANALOG_FIRST
56 // Analog (Ax) pin number array
57 // where x is the index to retrieve the digital pin number
58 const uint32_t analogInputPin
[] = {
72 // ----------------------------------------------------------------------------
79 * @brief System Clock Configuration
80 * The system Clock is configured as follows :
81 * System Clock source = PLL (MSI)
82 * SYSCLK(Hz) = 80000000
87 * MSI Frequency(Hz) = 4000000
93 * Flash Latency(WS) = 4
97 WEAK
void SystemClock_Config(void)
99 RCC_ClkInitTypeDef RCC_ClkInitStruct
= {};
100 RCC_OscInitTypeDef RCC_OscInitStruct
= {};
103 RCC_PeriphCLKInitTypeDef PeriphClkInit
= {};
105 memset(&RCC_OscInitStruct
, 0, sizeof(RCC_OscInitTypeDef
));
106 memset(&RCC_ClkInitStruct
, 0, sizeof(RCC_ClkInitTypeDef
));
107 memset(&PeriphClkInit
, 0, sizeof(RCC_PeriphCLKInitTypeDef
));
109 /* Enable Power Control clock */
110 __HAL_RCC_PWR_CLK_ENABLE();
112 /* The voltage scaling allows optimizing the power consumption when the device is
113 clocked below the maximum system frequency, to update the voltage scaling value
114 regarding system frequency refer to product datasheet. */
115 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1
);
117 /* Enable HSI Oscillator and activate PLL with HSI as source */
118 RCC_OscInitStruct
.OscillatorType
= RCC_OSCILLATORTYPE_HSI
;
119 RCC_OscInitStruct
.HSEState
= RCC_HSE_OFF
;
120 RCC_OscInitStruct
.HSIState
= RCC_HSI_ON
;
121 RCC_OscInitStruct
.PLL
.PLLState
= RCC_PLL_ON
;
122 RCC_OscInitStruct
.PLL
.PLLSource
= RCC_PLLSOURCE_HSI
;
123 RCC_OscInitStruct
.PLL
.PLLM
= 1; // 16MHz
124 RCC_OscInitStruct
.PLL
.PLLN
= 10; // 10 * 16MHz
125 RCC_OscInitStruct
.PLL
.PLLR
= RCC_PLLR_DIV2
; // 160MHz / 2
126 RCC_OscInitStruct
.PLL
.PLLP
= RCC_PLLP_DIV7
; // 160MHz / 7
127 RCC_OscInitStruct
.PLL
.PLLQ
= RCC_PLLQ_DIV4
; // 160MHz / 4
128 RCC_OscInitStruct
.HSICalibrationValue
= 0x10;
129 if (HAL_RCC_OscConfig(&RCC_OscInitStruct
) != HAL_OK
)
133 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
135 RCC_ClkInitStruct
.ClockType
= (RCC_CLOCKTYPE_SYSCLK
| RCC_CLOCKTYPE_HCLK
| RCC_CLOCKTYPE_PCLK1
| RCC_CLOCKTYPE_PCLK2
);
136 RCC_ClkInitStruct
.SYSCLKSource
= RCC_SYSCLKSOURCE_PLLCLK
;
137 RCC_ClkInitStruct
.AHBCLKDivider
= RCC_SYSCLK_DIV1
;
138 RCC_ClkInitStruct
.APB1CLKDivider
= RCC_HCLK_DIV1
;
139 RCC_ClkInitStruct
.APB2CLKDivider
= RCC_HCLK_DIV1
;
140 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct
, FLASH_LATENCY_4
) != HAL_OK
)
144 PeriphClkInit
.PeriphClockSelection
= RCC_PERIPHCLK_USART1
| RCC_PERIPHCLK_USART2
;
145 PeriphClkInit
.Usart1ClockSelection
= RCC_USART1CLKSOURCE_PCLK2
;
146 PeriphClkInit
.Usart2ClockSelection
= RCC_USART2CLKSOURCE_PCLK1
;
147 if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit
) != HAL_OK
)
156 /* MSI is enabled after System reset, activate PLL with MSI as source */
157 RCC_OscInitStruct
.OscillatorType
= RCC_OSCILLATORTYPE_MSI
;
158 RCC_OscInitStruct
.MSIState
= RCC_MSI_ON
;
160 RCC_OscInitStruct
.MSIClockRange
= RCC_MSIRANGE_6
;
161 RCC_OscInitStruct
.MSICalibrationValue
= RCC_MSICALIBRATION_DEFAULT
;
162 RCC_OscInitStruct
.PLL
.PLLState
= RCC_PLL_ON
;
163 RCC_OscInitStruct
.PLL
.PLLSource
= RCC_PLLSOURCE_MSI
;
164 RCC_OscInitStruct
.PLL
.PLLM
= 1;
165 RCC_OscInitStruct
.PLL
.PLLN
= 40;
166 RCC_OscInitStruct
.PLL
.PLLR
= 2;
167 RCC_OscInitStruct
.PLL
.PLLP
= 7;
168 RCC_OscInitStruct
.PLL
.PLLQ
= 4;
170 if (HAL_RCC_OscConfig(&RCC_OscInitStruct
) != HAL_OK
) {
171 /* Initialization Error */
175 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
177 RCC_ClkInitStruct
.ClockType
= (RCC_CLOCKTYPE_SYSCLK
| RCC_CLOCKTYPE_HCLK
| RCC_CLOCKTYPE_PCLK1
| RCC_CLOCKTYPE_PCLK2
);
178 RCC_ClkInitStruct
.SYSCLKSource
= RCC_SYSCLKSOURCE_PLLCLK
;
179 RCC_ClkInitStruct
.AHBCLKDivider
= RCC_SYSCLK_DIV1
;
180 RCC_ClkInitStruct
.APB1CLKDivider
= RCC_HCLK_DIV1
;
181 RCC_ClkInitStruct
.APB2CLKDivider
= RCC_HCLK_DIV1
;
182 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct
, FLASH_LATENCY_4
) != HAL_OK
) {
183 /* Initialization Error */