2 *******************************************************************************
3 * Copyright (c) 2019, STMicroelectronics
6 * This software component is licensed by ST under BSD 3-Clause license,
7 * the "License"; You may not use this file except in compliance with the
8 * License. You may obtain a copy of the License at:
9 * opensource.org/licenses/BSD-3-Clause
11 *******************************************************************************
14 #include "pins_arduino.h"
22 // Digital PinName array
23 // This array allows to wrap Arduino pin number(Dx or x)
24 // to STM32 PinName (PX_n)
25 const PinName digitalPin
[] = {
49 PC_13
, //D21 - User Button
76 PA_3
, //D45 - STLink Rx
77 PA_2
, //D46 - STLink Tx
86 // If analog pins are not contiguous in the digitalPin array:
87 // Add the analogInputPin array without defining NUM_ANALOG_FIRST
88 // Analog (Ax) pin number array
89 // where x is the index to retrieve the digital pin number
90 const uint32_t analogInputPin
[] = {
109 // ----------------------------------------------------------------------------
115 extern void SystemCoreClockUpdate(void);
118 * @brief System Clock Configuration
119 * The system Clock is configured as follows :
120 * System Clock source = PLL (MSI)
121 * SYSCLK(Hz) = 80000000
122 * HCLK(Hz) = 80000000
126 * MSI Frequency(Hz) = 4000000
132 * Flash Latency(WS) = 4
136 void SystemClock_Config(void)
139 RCC_ClkInitTypeDef RCC_ClkInitStruct
;
140 RCC_OscInitTypeDef RCC_OscInitStruct
;
141 RCC_PeriphCLKInitTypeDef PeriphClkInit
;
143 /* Enable Power Control clock */
144 __HAL_RCC_PWR_CLK_ENABLE();
146 /* The voltage scaling allows optimizing the power consumption when the device is
147 clocked below the maximum system frequency, to update the voltage scaling value
148 regarding system frequency refer to product datasheet. */
149 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1
);
151 memset(&RCC_OscInitStruct
, 0, sizeof(RCC_OscInitTypeDef
));
152 memset(&RCC_ClkInitStruct
, 0, sizeof(RCC_ClkInitTypeDef
));
153 memset(&PeriphClkInit
, 0, sizeof(RCC_PeriphCLKInitTypeDef
));
155 /* MSI is enabled after System reset, activate PLL with MSI as source */
156 RCC_OscInitStruct
.OscillatorType
= RCC_OSCILLATORTYPE_HSI
;
157 RCC_OscInitStruct
.HSEState
= RCC_HSE_OFF
;
158 RCC_OscInitStruct
.HSIState
= RCC_HSI_ON
;
159 RCC_OscInitStruct
.PLL
.PLLState
= RCC_PLL_ON
;
160 RCC_OscInitStruct
.PLL
.PLLSource
= RCC_PLLSOURCE_HSI
;
161 RCC_OscInitStruct
.PLL
.PLLM
= 1; // 16MHz
162 RCC_OscInitStruct
.PLL
.PLLN
= 10; // 10 * 16MHz
163 RCC_OscInitStruct
.PLL
.PLLR
= RCC_PLLR_DIV2
; // 160MHz / 2
164 RCC_OscInitStruct
.PLL
.PLLP
= RCC_PLLP_DIV7
; // 160MHz / 7
165 RCC_OscInitStruct
.PLL
.PLLQ
= RCC_PLLQ_DIV4
; // 160MHz / 4
166 RCC_OscInitStruct
.HSICalibrationValue
= 0x10;
168 if (HAL_RCC_OscConfig(&RCC_OscInitStruct
) != HAL_OK
) {
169 /* Initialization Error */
173 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
175 RCC_ClkInitStruct
.ClockType
= (RCC_CLOCKTYPE_SYSCLK
| RCC_CLOCKTYPE_HCLK
| RCC_CLOCKTYPE_PCLK1
| RCC_CLOCKTYPE_PCLK2
);
176 RCC_ClkInitStruct
.SYSCLKSource
= RCC_SYSCLKSOURCE_PLLCLK
;
177 RCC_ClkInitStruct
.AHBCLKDivider
= RCC_SYSCLK_DIV1
;
178 RCC_ClkInitStruct
.APB1CLKDivider
= RCC_HCLK_DIV1
;
179 RCC_ClkInitStruct
.APB2CLKDivider
= RCC_HCLK_DIV1
;
180 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct
, FLASH_LATENCY_4
) != HAL_OK
) {
181 /* Initialization Error */
185 PeriphClkInit
.PeriphClockSelection
= RCC_PERIPHCLK_USART1
| RCC_PERIPHCLK_USART2
;
186 PeriphClkInit
.Usart1ClockSelection
= RCC_USART1CLKSOURCE_PCLK2
;
187 PeriphClkInit
.Usart2ClockSelection
= RCC_USART2CLKSOURCE_PCLK1
;
188 if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit
) != HAL_OK
)
193 SystemCoreClockUpdate();