variant_MARLIN_STM32H723VX.cpp 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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 STM32H723xx
  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. void MPU_Config(void)
  120. {
  121. MPU_Region_InitTypeDef MPU_InitStruct = {0};
  122. /* Disables the MPU */
  123. HAL_MPU_Disable();
  124. /** Initializes and configures the Region and the memory to be protected
  125. */
  126. MPU_InitStruct.Enable = MPU_REGION_ENABLE;
  127. MPU_InitStruct.Number = MPU_REGION_NUMBER0;
  128. MPU_InitStruct.BaseAddress = 0x0;
  129. MPU_InitStruct.Size = MPU_REGION_SIZE_4GB;
  130. MPU_InitStruct.SubRegionDisable = 0x87;
  131. MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
  132. MPU_InitStruct.AccessPermission = MPU_REGION_NO_ACCESS;
  133. MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_DISABLE;
  134. MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
  135. MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
  136. MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
  137. HAL_MPU_ConfigRegion(&MPU_InitStruct);
  138. /* Enables the MPU */
  139. HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
  140. }
  141. /*
  142. * @brief System Clock Configuration
  143. * @param None
  144. * @retval None
  145. */
  146. WEAK void SystemClock_Config(void)
  147. {
  148. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  149. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  150. RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {};
  151. MPU_Config();
  152. /** Supply configuration update enable
  153. */
  154. HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);
  155. /** Configure the main internal regulator output voltage
  156. */
  157. __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE0);
  158. while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
  159. /** Initializes the RCC Oscillators according to the specified parameters
  160. * in the RCC_OscInitTypeDef structure.
  161. */
  162. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48 | RCC_OSCILLATORTYPE_HSE;
  163. RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  164. RCC_OscInitStruct.HSI48State = RCC_HSI48_ON; // 48Mhz for USB
  165. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  166. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  167. RCC_OscInitStruct.PLL.PLLM = 5; // 25Mhz / 5 = 5Mhz
  168. RCC_OscInitStruct.PLL.PLLN = 110; // 25Mhz / 5 * 110 = 550Mhz
  169. RCC_OscInitStruct.PLL.PLLP = 1; // 550Mhz / 1 = 550Mhz
  170. RCC_OscInitStruct.PLL.PLLQ = 10; // 550Mhz / 10 = 55Mhz
  171. RCC_OscInitStruct.PLL.PLLR = 10; // unused
  172. RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_2;
  173. RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
  174. RCC_OscInitStruct.PLL.PLLFRACN = 0;
  175. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  176. {
  177. Error_Handler();
  178. }
  179. /** Initializes the CPU, AHB and APB buses clocks
  180. */
  181. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  182. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
  183. |RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;
  184. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  185. RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
  186. RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV2;
  187. RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV2;
  188. RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV2;
  189. RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV2;
  190. RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV2;
  191. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
  192. {
  193. Error_Handler();
  194. }
  195. PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USB
  196. | RCC_PERIPHCLK_SDMMC | RCC_PERIPHCLK_ADC
  197. | RCC_PERIPHCLK_LPUART1 | RCC_PERIPHCLK_USART16
  198. | RCC_PERIPHCLK_USART234578 | RCC_PERIPHCLK_I2C123
  199. | RCC_PERIPHCLK_I2C4 | RCC_PERIPHCLK_SPI123
  200. | RCC_PERIPHCLK_SPI45 | RCC_PERIPHCLK_SPI6;
  201. /* HSI48 used for USB 48 Mhz */
  202. /* PLL1 qclk also used for FMC, SDMMC, RNG, SAI */
  203. /* PLL2 pclk is needed for adc max 80 Mhz (p,q,r same) */
  204. /* PLL2 pclk also used for LP timers 2,3,4,5, SPI 1,2,3 */
  205. /* PLL2 qclk is needed for uart, can, spi4,5,6 80 Mhz */
  206. /* PLL3 r clk is needed for i2c 80 Mhz (p,q,r same) */
  207. PeriphClkInitStruct.PLL2.PLL2M = 15; // M DIV 15 vco 25 / 15 ~ 1.667 Mhz
  208. PeriphClkInitStruct.PLL2.PLL2N = 96; // N MUL 96
  209. PeriphClkInitStruct.PLL2.PLL2P = 2; // P div 2
  210. PeriphClkInitStruct.PLL2.PLL2Q = 2; // Q div 2
  211. PeriphClkInitStruct.PLL2.PLL2R = 2; // R div 2
  212. // RCC_PLL1VCIRANGE_0 Clock range frequency between 1 and 2 MHz
  213. PeriphClkInitStruct.PLL2.PLL2RGE = RCC_PLL2VCIRANGE_0;
  214. PeriphClkInitStruct.PLL2.PLL2VCOSEL = RCC_PLL2VCOMEDIUM;
  215. PeriphClkInitStruct.PLL2.PLL2FRACN = 0;
  216. PeriphClkInitStruct.PLL3.PLL3M = 15; // M DIV 15 vco 25 / 15 ~ 1.667 Mhz
  217. PeriphClkInitStruct.PLL3.PLL3N = 96; // N MUL 96
  218. PeriphClkInitStruct.PLL3.PLL3P = 2; // P div 2
  219. PeriphClkInitStruct.PLL3.PLL3Q = 2; // Q div 2
  220. PeriphClkInitStruct.PLL3.PLL3R = 2; // R div 2
  221. // RCC_PLL1VCIRANGE_0 Clock range frequency between 1 and 2 MHz
  222. PeriphClkInitStruct.PLL3.PLL3RGE = RCC_PLL3VCIRANGE_0;
  223. PeriphClkInitStruct.PLL3.PLL3VCOSEL = RCC_PLL3VCOMEDIUM;
  224. PeriphClkInitStruct.PLL3.PLL3FRACN = 0;
  225. // ADC from PLL2 pclk
  226. PeriphClkInitStruct.AdcClockSelection = RCC_ADCCLKSOURCE_PLL2;
  227. // USB from HSI48
  228. PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_HSI48;
  229. // SDMMC from PLL1 qclk
  230. PeriphClkInitStruct.SdmmcClockSelection = 0;
  231. //PeriphClkInitStruct.SdmmcClockSelection = RCC_SDMMCCLKSOURCE_PLL;
  232. // LPUART from PLL2 qclk
  233. PeriphClkInitStruct.Lpuart1ClockSelection = 0;
  234. //PeriphClkInitStruct.Lpuart1ClockSelection = RCC_LPUART1CLKSOURCE_PLL2;
  235. // USART from PLL2 qclk
  236. PeriphClkInitStruct.Usart16ClockSelection = RCC_USART16CLKSOURCE_PLL2;
  237. // USART from PLL2 qclk
  238. PeriphClkInitStruct.Usart234578ClockSelection = 0;
  239. //PeriphClkInitStruct.Usart234578ClockSelection = RCC_USART234578CLKSOURCE_PLL2;
  240. // I2C123 from PLL3 rclk
  241. PeriphClkInitStruct.I2c123ClockSelection = RCC_I2C123CLKSOURCE_PLL3;
  242. // I2C4 from PLL3 rclk
  243. PeriphClkInitStruct.I2c4ClockSelection = 0;
  244. //PeriphClkInitStruct.I2c4ClockSelection = RCC_I2C4CLKSOURCE_PLL3;
  245. // SPI123 from PLL2 pclk
  246. PeriphClkInitStruct.Spi123ClockSelection = RCC_SPI123CLKSOURCE_PLL2;
  247. // SPI45 from PLL2 qclk
  248. PeriphClkInitStruct.Spi45ClockSelection = 0;
  249. //PeriphClkInitStruct.Spi45ClockSelection = RCC_SPI45CLKSOURCE_PLL2;
  250. // SPI6 from PLL2 qclk
  251. PeriphClkInitStruct.Spi6ClockSelection = 0;
  252. //PeriphClkInitStruct.Spi6ClockSelection = RCC_SPI6CLKSOURCE_PLL2;
  253. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) {
  254. Error_Handler();
  255. }
  256. }
  257. #endif /* ARDUINO_GENERIC_* */