variant.cpp 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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 "pins_arduino.h"
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. // Pin number
  35. // This array allows to wrap Arduino pin number(Dx or x)
  36. // to STM32 PinName (PX_n)
  37. const PinName digitalPin[] = {
  38. #if STM32F4X_PIN_NUM >= 64 //64 pins mcu, 51 gpio
  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, //D5 - BOOT1
  45. PB_10, //D6 - 1:SPI2_SCK / I2C2_SCL / USART3_TX / TIM2_CH3
  46. PB_11, //D7 - 1:I2C2_SDA / USART3_RX / TIM2_CH4
  47. PB_12, //D8 - 1:SPI2_NSS / OTG_HS_ID
  48. PB_13, //D9 - 1:SPI2_SCK 2:OTG_HS_VBUS
  49. PB_14, //D10 - 1:SPI2_MISO / TIM12_CH1 / OTG_HS_DM
  50. PB_15, //D11 - SPI2_MOSI / TIM12_CH2 / OTG_HS_DP
  51. PC_6, //D12 - 1:TIM8_CH1 / SDIO_D6 / USART6_TX / TIM3_CH1
  52. PC_7, //D13 - 1:TIM8_CH2 / SDIO_D7 / USART6_RX / TIM3_CH2
  53. PC_8, //D14 - 1:TIM8_CH3 / SDIO_D0 / TIM3_CH3
  54. PC_9, //D15 - 1:TIM8_CH4 / SDIO_D1 / TIM3_CH4
  55. PA_8, //D16 - 1:TIM1_CH1 / I2C3_SCL / OTG_FS_SOF
  56. PA_9, //D17 - 1:USART1_TX / TIM1_CH2 2:OTG_FS_VBUS
  57. PA_10, //D18 - 1:USART1_RX / TIM1_CH3 / OTG_FS_ID
  58. PA_11, //D19 - 1:TIM1_CH4 / OTG_FS_DM
  59. PA_12, //D20 - 1:OTG_FS_DP
  60. PA_13, //D21 - 0:JTMS-SWDIO
  61. PA_14, //D22 - 0:JTCK-SWCLK
  62. PA_15, //D23 - 0:JTDI 1:SPI3_NSS / SPI1_NSS
  63. PC_10, //D24 - 1:UART4_TX / SPI3_SCK / SDIO_D2 / USART3_TX
  64. PC_11, //D25 - 1:UART4_RX / SPI3_MISO / SDIO_D3 / USART3_RX
  65. PC_12, //D26 - 1:UART5_TX / SPI3_MOSI / SDIO_CK
  66. PD_2, //D27 - 1:UART5_RX / SDIO_CMD
  67. PB_3, //D28 - 0:JTDO 1:SPI3_SCK / TIM2_CH2 / SPI1_SCK
  68. PB_4, //D29 - 0:NJTRST 1:SPI3_MISO / TIM3_CH1 / SPI1_MISO
  69. PB_5, //D30 - 1:TIM3_CH2 / SPI1_MOSI / SPI3_MOSI
  70. PB_6, //D31 - 1:I2C1_SCL / TIM4_CH1 / USART1_TX
  71. PB_7, //D32 - 1:I2C1_SDA / TIM4_CH2 / USART1_RX
  72. PB_8, //D33 - 1:I2C1_SCL / TIM4_CH3 / SDIO_D4 / TIM10_CH1
  73. PB_9, //D34 - 1:I2C1_SDA / TIM4_CH4 / SDIO_D5 / TIM11_CH1 / SPI2_NSS
  74. PA_0, //D35/A0 - 1:UART4_TX / TIM5_CH1 2:ADC123_IN0
  75. PA_1, //D36/A1 - 1:UART4_RX / TIM5_CH2 / TIM2_CH2 2:ADC123_IN1
  76. PA_2, //D37/A2 - 1:USART2_TX /TIM5_CH3 / TIM9_CH1 / TIM2_CH3 2:ADC123_IN2
  77. PA_3, //D38/A3 - 1:USART2_RX /TIM5_CH4 / TIM9_CH2 / TIM2_CH4 2:ADC123_IN3
  78. PA_4, //D39/A4 - NOT FT 1:SPI1_NSS / SPI3_NSS / USART2_CK 2:ADC12_IN4 / DAC_OUT1
  79. PA_5, //D40/A5 - NOT FT 1:SPI1_SCK 2:ADC12_IN5 / DAC_OUT2
  80. PA_6, //D41/A6 - 1:SPI1_MISO / TIM13_CH1 / TIM3_CH1 2:ADC12_IN6
  81. PA_7, //D42/A7 - 1:SPI1_MOSI / TIM14_CH1 / TIM3_CH2 2:ADC12_IN7
  82. PB_0, //D43/A8 - 1:TIM3_CH3 2:ADC12_IN8
  83. PB_1, //D44/A9 - 1:TIM3_CH4 2:ADC12_IN9
  84. PC_0, //D45/A10 - 1: 2:ADC123_IN10
  85. PC_1, //D46/A11 - 1: 2:ADC123_IN11
  86. PC_2, //D47/A12 - 1:SPI2_MISO 2:ADC123_IN12
  87. PC_3, //D48/A13 - 1:SPI2_MOSI 2:ADC123_IN13
  88. PC_4, //D49/A14 - 1: 2:ADC12_IN14
  89. PC_5, //D50/A15 - 1: 2:ADC12_IN15
  90. #if STM32F4X_PIN_NUM >= 144
  91. PF_3, //D51/A16 - 1:FSMC_A3 2:ADC3_IN9
  92. PF_4, //D52/A17 - 1:FSMC_A4 2:ADC3_IN14
  93. PF_5, //D53/A18 - 1:FSMC_A5 2:ADC3_IN15
  94. PF_6, //D54/A19 - 1:TIM10_CH1 2:ADC3_IN4
  95. PF_7, //D55/A20 - 1:TIM11_CH1 2:ADC3_IN5
  96. PF_8, //D56/A21 - 1:TIM13_CH1 2:ADC3_IN6
  97. PF_9, //D57/A22 - 1;TIM14_CH1 2:ADC3_IN7
  98. PF_10, //D58/A23 - 2:ADC3_IN8
  99. #endif
  100. #endif
  101. #if STM32F4X_PIN_NUM >= 100 //100 pins mcu, 82 gpio
  102. PE_2, //D59 - 1:FSMC_A23
  103. PE_3, //D60 - 1:FSMC_A19
  104. PE_4, //D61 - 1:FSMC_A20
  105. PE_5, //D62 - 1:FSMC_A21
  106. PE_6, //D63 - 1:FSMC_A22
  107. PE_7, //D64 - 1:FSMC_D4
  108. PE_8, //D65 - 1:FSMC_D5
  109. PE_9, //D66 - 1:FSMC_D6 / TIM1_CH1
  110. PE_10, //D67 - 1:FSMC_D7
  111. PE_11, //D68 - 1:FSMC_D8 / TIM1_CH2
  112. PE_12, //D69 - 1:FSMC_D9
  113. PE_13, //D70 - 1:FSMC_D10 / TIM1_CH3
  114. PE_14, //D71 - 1:FSMC_D11 / TIM1_CH4
  115. PE_15, //D72 - 1:FSMC_D12
  116. PD_8, //D73 - 1:FSMC_D13 / USART3_TX
  117. PD_9, //D74 - 1:FSMC_D14 / USART3_RX
  118. PD_10, //D75 - 1:FSMC_D15
  119. PD_11, //D76 - 1:FSMC_A16
  120. PD_12, //D77 - 1:FSMC_A17 / TIM4_CH1
  121. PD_13, //D78 - 1:FSMC_A18 / TIM4_CH2
  122. PD_14, //D79 - 1:FSMC_D0 / TIM4_CH3
  123. PD_15, //D80 - 1:FSMC_D1 / TIM4_CH4
  124. PD_0, //D81 - 1:FSMC_D2
  125. PD_1, //D82 - 1:FSMC_D3
  126. PD_3, //D83 - 1:FSMC_CLK
  127. PD_4, //D84 - 1:FSMC_NOE
  128. PD_5, //D85 - 1:USART2_TX
  129. PD_6, //D86 - 1:USART2_RX
  130. PD_7, //D87
  131. PE_0, //D88
  132. PE_1, //D89
  133. #endif
  134. #if STM32F4X_PIN_NUM >= 144 //144 pins mcu, 114 gpio
  135. PF_0, //D90 - 1:FSMC_A0 / I2C2_SDA
  136. PF_1, //D91 - 1:FSMC_A1 / I2C2_SCL
  137. PF_2, //D92 - 1:FSMC_A2
  138. PF_11, //D93
  139. PF_12, //D94 - 1:FSMC_A6
  140. PF_13, //D95 - 1:FSMC_A7
  141. PF_14, //D96 - 1:FSMC_A8
  142. PF_15, //D97 - 1:FSMC_A9
  143. PG_0, //D98 - 1:FSMC_A10
  144. PG_1, //D99 - 1:FSMC_A11
  145. PG_2, //D100 - 1:FSMC_A12
  146. PG_3, //D101 - 1:FSMC_A13
  147. PG_4, //D102 - 1:FSMC_A14
  148. PG_5, //D103 - 1:FSMC_A15
  149. PG_6, //D104
  150. PG_7, //D105
  151. PG_8, //D106
  152. PG_9, //D107 - 1:USART6_RX
  153. PG_10, //D108 - 1:FSMC_NE3
  154. PG_11, //D109
  155. PG_12, //D110 - 1:FSMC_NE4
  156. PG_13, //D111 - 1:FSMC_A24
  157. PG_14, //D112 - 1:FSMC_A25 / USART6_TX
  158. PG_15, //D113
  159. #endif
  160. #if STM32F4X_PIN_NUM >= 176 //176 pins mcu, 140 gpio
  161. PI_8, //D114
  162. PI_9, //D115
  163. PI_10, //D116
  164. PI_11, //D117
  165. PH_2, //D118
  166. PH_3, //D119
  167. PH_4, //D120 - 1:I2C2_SCL
  168. PH_5, //D121 - 1:I2C2_SDA
  169. PH_6, //D122 - 1:TIM12_CH1
  170. PH_7, //D123 - 1:I2C3_SCL
  171. PH_8, //D124 - 1:I2C3_SDA
  172. PH_9, //D125 - 1:TIM12_CH2
  173. PH_10, //D126 - 1:TIM5_CH1
  174. PH_11, //D127 - 1:TIM5_CH2
  175. PH_12, //D128 - 1:TIM5_CH3
  176. PH_13, //D129
  177. PH_14, //D130
  178. PH_15, //D131
  179. PI_0, //D132 - 1:TIM5_CH4 / SPI2_NSS
  180. PI_1, //D133 - 1:SPI2_SCK
  181. PI_2, //D134 - 1:TIM8_CH4 /SPI2_MISO
  182. PI_3, //D135 - 1:SPI2_MOS
  183. PI_4, //D136
  184. PI_5, //D137 - 1:TIM8_CH1
  185. PI_6, //D138 - 1:TIM8_CH2
  186. PI_7, //D139 - 1:TIM8_CH3
  187. #endif
  188. };
  189. #ifdef __cplusplus
  190. }
  191. #endif
  192. // ------------------------
  193. #ifdef __cplusplus
  194. extern "C" {
  195. #endif
  196. /**
  197. * @brief System Clock Configuration
  198. * @param None
  199. * @retval None
  200. */
  201. WEAK void SystemClock_Config() {
  202. RCC_OscInitTypeDef RCC_OscInitStruct;
  203. RCC_ClkInitTypeDef RCC_ClkInitStruct;
  204. /**Configure the main internal regulator output voltage
  205. */
  206. __HAL_RCC_PWR_CLK_ENABLE();
  207. __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  208. /**Initializes the CPU, AHB and APB busses clocks
  209. */
  210. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  211. RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  212. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  213. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  214. RCC_OscInitStruct.PLL.PLLM = 8;
  215. RCC_OscInitStruct.PLL.PLLN = 336;
  216. RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  217. RCC_OscInitStruct.PLL.PLLQ = 7;
  218. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
  219. _Error_Handler(__FILE__, __LINE__);
  220. }
  221. /**Initializes the CPU, AHB and APB busses clocks
  222. */
  223. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
  224. | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
  225. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  226. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  227. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  228. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
  229. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK) {
  230. _Error_Handler(__FILE__, __LINE__);
  231. }
  232. /**Configure the Systick interrupt time
  233. */
  234. HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / 1000);
  235. /**Configure the Systick
  236. */
  237. HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
  238. /* SysTick_IRQn interrupt configuration */
  239. HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
  240. }
  241. #ifdef __cplusplus
  242. }
  243. #endif