variant_MARLIN_STM32H743VX.cpp 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /*
  2. *******************************************************************************
  3. * Copyright (c) 2020-2021, STMicroelectronics
  4. * All rights reserved.
  5. *
  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
  10. *
  11. *******************************************************************************
  12. */
  13. #ifdef STM32H743xx
  14. #include "pins_arduino.h"
  15. // Digital PinName array
  16. const PinName digitalPin[] = {
  17. PA_0, // D0/A0
  18. PA_1, // D1/A1
  19. PA_2, // D2/A2
  20. PA_3, // D3/A3
  21. PA_4, // D4/A4
  22. PA_5, // D5/A5
  23. PA_6, // D6/A6
  24. PA_7, // D7/A7
  25. PA_8, // D8
  26. PA_9, // D9
  27. PA_10, // D10
  28. PA_11, // D11
  29. PA_12, // D12
  30. PA_13, // D13
  31. PA_14, // D14
  32. PA_15, // D15
  33. PB_0, // D16/A8
  34. PB_1, // D17/A9
  35. PB_2, // D18
  36. PB_3, // D19
  37. PB_4, // D20
  38. PB_5, // D21
  39. PB_6, // D22
  40. PB_7, // D23
  41. PB_8, // D24
  42. PB_9, // D25
  43. PB_10, // D26
  44. PB_11, // D27
  45. PB_12, // D28
  46. PB_13, // D29
  47. PB_14, // D30
  48. PB_15, // D31
  49. PC_0, // D32/A10
  50. PC_1, // D33/A11
  51. PC_4, // D34/A12
  52. PC_5, // D35/A13
  53. PC_6, // D36
  54. PC_7, // D37
  55. PC_8, // D38
  56. PC_9, // D39
  57. PC_10, // D40
  58. PC_11, // D41
  59. PC_12, // D42
  60. PC_13, // D43
  61. PC_14, // D44
  62. PC_15, // D45
  63. PD_0, // D46
  64. PD_1, // D47
  65. PD_2, // D48
  66. PD_3, // D49
  67. PD_4, // D50
  68. PD_5, // D51
  69. PD_6, // D52
  70. PD_7, // D53
  71. PD_8, // D54
  72. PD_9, // D55
  73. PD_10, // D56
  74. PD_11, // D57
  75. PD_12, // D58
  76. PD_13, // D59
  77. PD_14, // D60
  78. PD_15, // D61
  79. PE_0, // D62
  80. PE_1, // D63
  81. PE_2, // D64
  82. PE_3, // D65
  83. PE_4, // D66
  84. PE_5, // D67
  85. PE_6, // D68
  86. PE_7, // D69
  87. PE_8, // D70
  88. PE_9, // D71
  89. PE_10, // D72
  90. PE_11, // D73
  91. PE_12, // D74
  92. PE_13, // D75
  93. PE_14, // D76
  94. PE_15, // D77
  95. PH_0, // D78
  96. PH_1, // D79
  97. PC_2_C, // D80/A14
  98. PC_3_C // D81/A15
  99. };
  100. // Analog (Ax) pin number array
  101. const uint32_t analogInputPin[] = {
  102. 0, // A0, PA0
  103. 1, // A1, PA1
  104. 2, // A2, PA2
  105. 3, // A3, PA3
  106. 4, // A4, PA4
  107. 5, // A5, PA5
  108. 6, // A6, PA6
  109. 7, // A7, PA7
  110. 16, // A8, PB0
  111. 17, // A9, PB1
  112. 32, // A10, PC0
  113. 33, // A11, PC1
  114. 34, // A12, PC4
  115. 35, // A13, PC5
  116. 80, // A14, PC2_C
  117. 81 // A15, PC3_C
  118. };
  119. /*
  120. * @brief System Clock Configuration
  121. * @param None
  122. * @retval None
  123. */
  124. WEAK void SystemClock_Config(void)
  125. {
  126. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  127. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  128. RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {};
  129. /** Supply configuration update enable
  130. */
  131. HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);
  132. /** Configure the main internal regulator output voltage
  133. */
  134. __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE0);
  135. while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
  136. /** Initializes the RCC Oscillators according to the specified parameters
  137. * in the RCC_OscInitTypeDef structure.
  138. */
  139. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  140. RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  141. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  142. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  143. RCC_OscInitStruct.PLL.PLLM = 5; // 25Mhz / 5 = 5Mhz
  144. RCC_OscInitStruct.PLL.PLLN = 192; // 25Mhz / 5 * 192 = 960Mhz
  145. RCC_OscInitStruct.PLL.PLLP = 2; // 960Mhz / 2 = 480Mhz
  146. RCC_OscInitStruct.PLL.PLLQ = 20; // 960Mhz / 20 = 48Mhz for USB
  147. RCC_OscInitStruct.PLL.PLLR = 20; // unused
  148. RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_2;
  149. RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
  150. RCC_OscInitStruct.PLL.PLLFRACN = 0;
  151. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  152. {
  153. Error_Handler();
  154. }
  155. /** Initializes the CPU, AHB and APB buses clocks
  156. */
  157. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  158. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
  159. |RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;
  160. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  161. RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
  162. RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV2;
  163. RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV2;
  164. RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV2;
  165. RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV2;
  166. RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV2;
  167. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
  168. {
  169. Error_Handler();
  170. }
  171. PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USB | RCC_PERIPHCLK_QSPI
  172. | RCC_PERIPHCLK_SDMMC | RCC_PERIPHCLK_ADC
  173. | RCC_PERIPHCLK_LPUART1 | RCC_PERIPHCLK_USART16
  174. | RCC_PERIPHCLK_USART234578 | RCC_PERIPHCLK_I2C123
  175. | RCC_PERIPHCLK_I2C4 | RCC_PERIPHCLK_SPI123
  176. | RCC_PERIPHCLK_SPI45 | RCC_PERIPHCLK_SPI6;
  177. /* PLL1 qclk used for USB 48 Mhz */
  178. /* PLL1 qclk also used for FMC, QUADSPI, SDMMC, RNG, SAI */
  179. /* PLL2 pclk is needed for adc max 80 Mhz (p,q,r same) */
  180. /* PLL2 pclk also used for LP timers 2,3,4,5, SPI 1,2,3 */
  181. /* PLL2 qclk is needed for uart, can, spi4,5,6 80 Mhz */
  182. /* PLL3 r clk is needed for i2c 80 Mhz (p,q,r same) */
  183. PeriphClkInitStruct.PLL2.PLL2M = 15; // M DIV 15 vco 25 / 15 ~ 1.667 Mhz
  184. PeriphClkInitStruct.PLL2.PLL2N = 96; // N MUL 96
  185. PeriphClkInitStruct.PLL2.PLL2P = 2; // P div 2
  186. PeriphClkInitStruct.PLL2.PLL2Q = 2; // Q div 2
  187. PeriphClkInitStruct.PLL2.PLL2R = 2; // R div 2
  188. // RCC_PLL1VCIRANGE_0 Clock range frequency between 1 and 2 MHz
  189. PeriphClkInitStruct.PLL2.PLL2RGE = RCC_PLL2VCIRANGE_0;
  190. PeriphClkInitStruct.PLL2.PLL2VCOSEL = RCC_PLL2VCOMEDIUM;
  191. PeriphClkInitStruct.PLL2.PLL2FRACN = 0;
  192. PeriphClkInitStruct.PLL3.PLL3M = 15; // M DIV 15 vco 25 / 15 ~ 1.667 Mhz
  193. PeriphClkInitStruct.PLL3.PLL3N = 96; // N MUL 96
  194. PeriphClkInitStruct.PLL3.PLL3P = 2; // P div 2
  195. PeriphClkInitStruct.PLL3.PLL3Q = 2; // Q div 2
  196. PeriphClkInitStruct.PLL3.PLL3R = 2; // R div 2
  197. // RCC_PLL1VCIRANGE_0 Clock range frequency between 1 and 2 MHz
  198. PeriphClkInitStruct.PLL3.PLL3RGE = RCC_PLL3VCIRANGE_0;
  199. PeriphClkInitStruct.PLL3.PLL3VCOSEL = RCC_PLL3VCOMEDIUM;
  200. PeriphClkInitStruct.PLL3.PLL3FRACN = 0;
  201. // ADC from PLL2 pclk
  202. PeriphClkInitStruct.AdcClockSelection = RCC_ADCCLKSOURCE_PLL2;
  203. // USB from PLL1 qclk
  204. PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_PLL;
  205. // QSPI from PLL1 qclk
  206. PeriphClkInitStruct.QspiClockSelection = RCC_QSPICLKSOURCE_PLL;
  207. // SDMMC from PLL1 qclk
  208. PeriphClkInitStruct.SdmmcClockSelection = 0;
  209. //PeriphClkInitStruct.SdmmcClockSelection = RCC_SDMMCCLKSOURCE_PLL;
  210. // LPUART from PLL2 qclk
  211. PeriphClkInitStruct.Lpuart1ClockSelection = 0;
  212. //PeriphClkInitStruct.Lpuart1ClockSelection = RCC_LPUART1CLKSOURCE_PLL2;
  213. // USART from PLL2 qclk
  214. PeriphClkInitStruct.Usart16ClockSelection = RCC_USART16CLKSOURCE_PLL2;
  215. // USART from PLL2 qclk
  216. PeriphClkInitStruct.Usart234578ClockSelection = 0;
  217. //PeriphClkInitStruct.Usart234578ClockSelection = RCC_USART234578CLKSOURCE_PLL2;
  218. // I2C123 from PLL3 rclk
  219. PeriphClkInitStruct.I2c123ClockSelection = RCC_I2C123CLKSOURCE_PLL3;
  220. // I2C4 from PLL3 rclk
  221. PeriphClkInitStruct.I2c4ClockSelection = 0;
  222. //PeriphClkInitStruct.I2c4ClockSelection = RCC_I2C4CLKSOURCE_PLL3;
  223. // SPI123 from PLL2 pclk
  224. PeriphClkInitStruct.Spi123ClockSelection = RCC_SPI123CLKSOURCE_PLL2;
  225. // SPI45 from PLL2 qclk
  226. PeriphClkInitStruct.Spi45ClockSelection = 0;
  227. //PeriphClkInitStruct.Spi45ClockSelection = RCC_SPI45CLKSOURCE_PLL2;
  228. // SPI6 from PLL2 qclk
  229. PeriphClkInitStruct.Spi6ClockSelection = 0;
  230. //PeriphClkInitStruct.Spi6ClockSelection = RCC_SPI6CLKSOURCE_PLL2;
  231. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) {
  232. Error_Handler();
  233. }
  234. }
  235. #endif /* ARDUINO_GENERIC_* */