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
58 // ----------------------------------------------------------------------------
65 * @brief System Clock Configuration
66 * The system Clock is configured as follows :
67 * System Clock source = PLL (MSI)
68 * SYSCLK(Hz) = 80000000
73 * MSI Frequency(Hz) = 4000000
79 * Flash Latency(WS) = 4
83 WEAK
void SystemClock_Config(void)
85 RCC_ClkInitTypeDef RCC_ClkInitStruct
= {};
86 RCC_OscInitTypeDef RCC_OscInitStruct
= {};
89 RCC_PeriphCLKInitTypeDef PeriphClkInit
= {};
91 memset(&RCC_OscInitStruct
, 0, sizeof(RCC_OscInitTypeDef
));
92 memset(&RCC_ClkInitStruct
, 0, sizeof(RCC_ClkInitTypeDef
));
93 memset(&PeriphClkInit
, 0, sizeof(RCC_PeriphCLKInitTypeDef
));
95 /* Enable Power Control clock */
96 __HAL_RCC_PWR_CLK_ENABLE();
98 /* The voltage scaling allows optimizing the power consumption when the device is
99 clocked below the maximum system frequency, to update the voltage scaling value
100 regarding system frequency refer to product datasheet. */
101 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1
);
103 /* Enable HSI Oscillator and activate PLL with HSI as source */
104 RCC_OscInitStruct
.OscillatorType
= RCC_OSCILLATORTYPE_HSI
;
105 RCC_OscInitStruct
.HSEState
= RCC_HSE_OFF
;
106 RCC_OscInitStruct
.HSIState
= RCC_HSI_ON
;
107 RCC_OscInitStruct
.PLL
.PLLState
= RCC_PLL_ON
;
108 RCC_OscInitStruct
.PLL
.PLLSource
= RCC_PLLSOURCE_HSI
;
109 RCC_OscInitStruct
.PLL
.PLLM
= 1; // 16MHz
110 RCC_OscInitStruct
.PLL
.PLLN
= 10; // 10 * 16MHz
111 RCC_OscInitStruct
.PLL
.PLLR
= RCC_PLLR_DIV2
; // 160MHz / 2
112 RCC_OscInitStruct
.PLL
.PLLP
= RCC_PLLP_DIV7
; // 160MHz / 7
113 RCC_OscInitStruct
.PLL
.PLLQ
= RCC_PLLQ_DIV4
; // 160MHz / 4
114 RCC_OscInitStruct
.HSICalibrationValue
= 0x10;
115 if (HAL_RCC_OscConfig(&RCC_OscInitStruct
) != HAL_OK
)
119 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
121 RCC_ClkInitStruct
.ClockType
= (RCC_CLOCKTYPE_SYSCLK
| RCC_CLOCKTYPE_HCLK
| RCC_CLOCKTYPE_PCLK1
| RCC_CLOCKTYPE_PCLK2
);
122 RCC_ClkInitStruct
.SYSCLKSource
= RCC_SYSCLKSOURCE_PLLCLK
;
123 RCC_ClkInitStruct
.AHBCLKDivider
= RCC_SYSCLK_DIV1
;
124 RCC_ClkInitStruct
.APB1CLKDivider
= RCC_HCLK_DIV1
;
125 RCC_ClkInitStruct
.APB2CLKDivider
= RCC_HCLK_DIV1
;
126 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct
, FLASH_LATENCY_4
) != HAL_OK
)
130 PeriphClkInit
.PeriphClockSelection
= RCC_PERIPHCLK_USART1
| RCC_PERIPHCLK_USART2
;
131 PeriphClkInit
.Usart1ClockSelection
= RCC_USART1CLKSOURCE_PCLK2
;
132 PeriphClkInit
.Usart2ClockSelection
= RCC_USART2CLKSOURCE_PCLK1
;
133 if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit
) != HAL_OK
)
142 /* MSI is enabled after System reset, activate PLL with MSI as source */
143 RCC_OscInitStruct
.OscillatorType
= RCC_OSCILLATORTYPE_MSI
;
144 RCC_OscInitStruct
.MSIState
= RCC_MSI_ON
;
146 RCC_OscInitStruct
.MSIClockRange
= RCC_MSIRANGE_6
;
147 RCC_OscInitStruct
.MSICalibrationValue
= RCC_MSICALIBRATION_DEFAULT
;
148 RCC_OscInitStruct
.PLL
.PLLState
= RCC_PLL_ON
;
149 RCC_OscInitStruct
.PLL
.PLLSource
= RCC_PLLSOURCE_MSI
;
150 RCC_OscInitStruct
.PLL
.PLLM
= 1;
151 RCC_OscInitStruct
.PLL
.PLLN
= 40;
152 RCC_OscInitStruct
.PLL
.PLLR
= 2;
153 RCC_OscInitStruct
.PLL
.PLLP
= 7;
154 RCC_OscInitStruct
.PLL
.PLLQ
= 4;
156 if (HAL_RCC_OscConfig(&RCC_OscInitStruct
) != HAL_OK
) {
157 /* Initialization Error */
161 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
163 RCC_ClkInitStruct
.ClockType
= (RCC_CLOCKTYPE_SYSCLK
| RCC_CLOCKTYPE_HCLK
| RCC_CLOCKTYPE_PCLK1
| RCC_CLOCKTYPE_PCLK2
);
164 RCC_ClkInitStruct
.SYSCLKSource
= RCC_SYSCLKSOURCE_PLLCLK
;
165 RCC_ClkInitStruct
.AHBCLKDivider
= RCC_SYSCLK_DIV1
;
166 RCC_ClkInitStruct
.APB1CLKDivider
= RCC_HCLK_DIV1
;
167 RCC_ClkInitStruct
.APB2CLKDivider
= RCC_HCLK_DIV1
;
168 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct
, FLASH_LATENCY_4
) != HAL_OK
) {
169 /* Initialization Error */
176 void initVariant(void)
178 /* Reset vector location which is set wrongly by SystemInit */
179 extern uint32_t g_pfnVectors
;
180 SCB
->VTOR
= (uint32_t) &g_pfnVectors
;