variant.cpp 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /*
  2. *******************************************************************************
  3. * Copyright (c) 2017, STMicroelectronics
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice,
  10. * this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  15. * may be used to endorse or promote products derived from this software
  16. * without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  22. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  23. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  24. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  25. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  26. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *******************************************************************************
  29. */
  30. #include "variant.h"
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. #include "pins_arduino.h"
  35. // Pin number
  36. // This array allows to wrap Arduino pin number(Dx or x)
  37. // to STM32 PinName (PX_n)
  38. const PinName digitalPin[] = {
  39. PC_13, //D0
  40. PC_14, //D1 - OSC32_IN
  41. PC_15, //D2 - OSC32_OUT
  42. PH_0, //D3 - OSC_IN
  43. PH_1, //D4 - OSC_OUT
  44. PB_2, //D21 - BOOT1
  45. PB_10, //D22 - 1:SPI2_SCK / I2C2_SCL / USART3_TX / TIM2_CH3
  46. PB_11, //D23 - 1:I2C2_SDA / USART3_RX / TIM2_CH4
  47. PB_12, //D24 - 1:SPI2_NSS / OTG_HS_ID
  48. PB_13, //D25 - 1:SPI2_SCK 2:OTG_HS_VBUS
  49. PB_14, //D26 - 1:SPI2_MISO / TIM12_CH1 / OTG_HS_DM
  50. PB_15, //D27 - SPI2_MOSI / TIM12_CH2 / OTG_HS_DP
  51. PC_6, //D28 - 1:TIM8_CH1 / SDIO_D6 / USART6_TX / TIM3_CH1
  52. PC_7, //D29 - 1:TIM8_CH2 / SDIO_D7 / USART6_RX / TIM3_CH2
  53. PC_8, //D30 - 1:TIM8_CH3 / SDIO_D0 / TIM3_CH3
  54. PC_9, //D31 - 1:TIM8_CH4 / SDIO_D1 / TIM3_CH4
  55. PA_8, //D32 - 1:TIM1_CH1 / I2C3_SCL / OTG_FS_SOF
  56. PA_9, //D33 - 1:USART1_TX / TIM1_CH2 2:OTG_FS_VBUS
  57. PA_10, //34 - 1:USART1_RX / TIM1_CH3 / OTG_FS_ID
  58. PA_11, //D35 - 1:TIM1_CH4 / OTG_FS_DM
  59. PA_12, //D36 - 1:OTG_FS_DP
  60. PA_13, //D37 - 0:JTMS-SWDIO
  61. PA_14, //D38 - 0:JTCK-SWCLK
  62. PA_15, //D39 - 0:JTDI 1:SPI3_NSS / SPI1_NSS
  63. PC_10, //D40 - 1:UART4_TX / SPI3_SCK / SDIO_D2 / USART3_TX
  64. PC_11, //D41 - 1:UART4_RX / SPI3_MISO / SDIO_D3 / USART3_RX
  65. PC_12, //D42 - 1:UART5_TX / SPI3_MOSI / SDIO_CK
  66. PD_2, //D43 - 1:UART5_RX / SDIO_CMD
  67. PB_3, //D44 - 0:JTDO 1:SPI3_SCK / TIM2_CH2 / SPI1_SCK
  68. PB_4, //D45 - 0:NJTRST 1:SPI3_MISO / TIM3_CH1 / SPI1_MISO
  69. PB_5, //D45 - 1:TIM3_CH2 / SPI1_MOSI / SPI3_MOSI
  70. PB_6, //D47 - 1:I2C1_SCL / TIM4_CH1 / USART1_TX
  71. PB_7, //D48 - 1:I2C1_SDA / TIM4_CH2 / USART1_RX
  72. PB_8, //D49 - 1:I2C1_SCL / TIM4_CH3 / SDIO_D4 / TIM10_CH1
  73. PB_9, //D50 - 1:I2C1_SDA / TIM4_CH4 / SDIO_D5 / TIM11_CH1 / SPI2_NSS
  74. PE_2, //D51 - 1:FSMC_A23
  75. PE_3, //D52 - 1:FSMC_A19
  76. PE_4, //D53 - 1:FSMC_A20
  77. PE_5, //D54 - 1:FSMC_A21
  78. PE_6, //D55 - 1:FSMC_A22
  79. PE_7, //D56 - 1:FSMC_D4
  80. PE_8, //D57 - 1:FSMC_D5
  81. PE_9, //D58 - 1:FSMC_D6 / TIM1_CH1
  82. PE_10, //D59 - 1:FSMC_D7
  83. PE_11, //D60 - 1:FSMC_D8 / TIM1_CH2
  84. PE_12, //D61 - 1:FSMC_D9
  85. PE_13, //D62 - 1:FSMC_D10 / TIM1_CH3
  86. PE_14, //D63 - 1:FSMC_D11 / TIM1_CH4
  87. PE_15, //D64 - 1:FSMC_D12
  88. PD_8, //D65 - 1:FSMC_D13 / USART3_TX
  89. PD_9, //D66 - 1:FSMC_D14 / USART3_RX
  90. PD_10, //D67 - 1:FSMC_D15
  91. PD_11, //D68 - 1:FSMC_A16
  92. PD_12, //D69 - 1:FSMC_A17 / TIM4_CH1
  93. PD_13, //D70 - 1:FSMC_A18 / TIM4_CH2
  94. PD_14, //D71 - 1:FSMC_D0 / TIM4_CH3
  95. PD_15, //D72 - 1:FSMC_D1 / TIM4_CH4
  96. PD_0, //D73 - 1:FSMC_D2
  97. PD_1, //D74 - 1:FSMC_D3
  98. PD_3, //D75 - 1:FSMC_CLK
  99. PD_4, //D76 - 1:FSMC_NOE
  100. PD_5, //D77 - 1:USART2_TX
  101. PD_6, //D78 - 1:USART2_RX
  102. PD_7, //D79
  103. PE_0, //D80
  104. PE_1, //D81
  105. PF_0, //D82 - 1:FSMC_A0 / I2C2_SDA
  106. PF_1, //D83 - 1:FSMC_A1 / I2C2_SCL
  107. PF_2, //D84 - 1:FSMC_A2
  108. PF_11, //D93
  109. PF_12, //D94 - 1:FSMC_A6
  110. PF_13, //D95 - 1:FSMC_A7
  111. PF_14, //D96 - 1:FSMC_A8
  112. PF_15, //D97 - 1:FSMC_A9
  113. PG_0, //D98 - 1:FSMC_A10
  114. PG_1, //D99 - 1:FSMC_A11
  115. PG_2, //D100 - 1:FSMC_A12
  116. PG_3, //D101 - 1:FSMC_A13
  117. PG_4, //D102 - 1:FSMC_A14
  118. PG_5, //D103 - 1:FSMC_A15
  119. PG_6, //D104
  120. PG_7, //D105
  121. PG_8, //D106
  122. PG_9, //D107 - 1:USART6_RX
  123. PG_10, //D108 - 1:FSMC_NE3
  124. PG_11, //D109
  125. PG_12, //D110 - 1:FSMC_NE4
  126. PG_13, //D111 - 1:FSMC_A24
  127. PG_14, //D112 - 1:FSMC_A25 / USART6_TX
  128. PG_15, //D113
  129. PA_0, //D140/A0 = D9 - 1:UART4_TX / TIM5_CH1 2:ADC123_IN0
  130. PA_1, //D141/A1 = D10 - 1:UART4_RX / TIM5_CH2 / TIM2_CH2 2:ADC123_IN1
  131. PA_2, //D142/A2 = D11 - 1:USART2_TX /TIM5_CH3 / TIM9_CH1 / TIM2_CH3 2:ADC123_IN2
  132. PA_3, //D143/A3 = D12 - 1:USART2_RX /TIM5_CH4 / TIM9_CH2 / TIM2_CH4 2:ADC123_IN3
  133. PA_4, //D144/A4 = D13 - NOT FT 1:SPI1_NSS / SPI3_NSS / USART2_CK 2:ADC12_IN4 / DAC_OUT1
  134. PA_5, //D145/A5 = D14 - NOT FT 1:SPI1_SCK 2:ADC12_IN5 / DAC_OUT2
  135. PA_6, //D146/A6 = D15 - 1:SPI1_MISO / TIM13_CH1 / TIM3_CH1 2:ADC12_IN6
  136. PA_7, //D147/A7 = D16 - 1:SPI1_MOSI / TIM14_CH1 / TIM3_CH2 2:ADC12_IN7
  137. PB_0, //D148/A8 = D19 - 1:TIM3_CH3 2:ADC12_IN8
  138. PB_1, //D149/A9 = D20 - 1:TIM3_CH4 2:ADC12_IN9
  139. PC_0, //D150/A10 = D5 - 1: 2:ADC123_IN10
  140. PC_1, //D151/A11 = D6 - 1: 2:ADC123_IN11
  141. PC_2, //D152/A12 = D7 - 1:SPI2_MISO 2:ADC123_IN12
  142. PC_3, //D153/A13 = D8 - 1:SPI2_MOSI 2:ADC123_IN13
  143. PC_4, //D154/A14 = D17 - 1: 2:ADC12_IN14
  144. PC_5, //D155/A15 = D18 - 1: 2:ADC12_IN15
  145. PF_3, //D156/A16 = D85 - 1:FSMC_A3 2:ADC3_IN9
  146. PF_4, //D157/A17 = D86 - 1:FSMC_A4 2:ADC3_IN14
  147. PF_5, //D158/A18 = D87 - 1:FSMC_A5 2:ADC3_IN15
  148. PF_6, //D159/A19 = D88 - 1:TIM10_CH1 2:ADC3_IN4
  149. PF_7, //D160/A20 = D89 - 1:TIM11_CH1 2:ADC3_IN5
  150. PF_8, //D161/A21 = D90 - 1:TIM13_CH1 2:ADC3_IN6
  151. PF_9, //D162/A22 = D91 - 1;TIM14_CH1 2:ADC3_IN7
  152. PF_10, //D163/A23 = D92 - 2:ADC3_IN8
  153. };
  154. #ifdef __cplusplus
  155. }
  156. #endif
  157. // ------------------------
  158. #ifdef __cplusplus
  159. extern "C" {
  160. #endif
  161. /**
  162. * @brief System Clock Configuration
  163. * @param None
  164. * @retval None
  165. */
  166. WEAK void SystemClock_Config(void)
  167. {
  168. RCC_OscInitTypeDef RCC_OscInitStruct;
  169. RCC_ClkInitTypeDef RCC_ClkInitStruct;
  170. /**Configure the main internal regulator output voltage
  171. */
  172. __HAL_RCC_PWR_CLK_ENABLE();
  173. __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  174. /**Initializes the CPU, AHB and APB busses clocks
  175. */
  176. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  177. RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  178. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  179. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  180. RCC_OscInitStruct.PLL.PLLM = 8;
  181. RCC_OscInitStruct.PLL.PLLN = 336;
  182. RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  183. RCC_OscInitStruct.PLL.PLLQ = 7;
  184. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
  185. _Error_Handler(__FILE__, __LINE__);
  186. }
  187. /**Initializes the CPU, AHB and APB busses clocks
  188. */
  189. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
  190. | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
  191. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  192. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  193. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  194. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
  195. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK) {
  196. _Error_Handler(__FILE__, __LINE__);
  197. }
  198. /**Configure the Systick interrupt time
  199. */
  200. HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / 1000);
  201. /**Configure the Systick
  202. */
  203. HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
  204. /* SysTick_IRQn interrupt configuration */
  205. HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
  206. }
  207. #ifdef __cplusplus
  208. }
  209. #endif