variant_MARLIN_STM32H723ZX.cpp 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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. #if defined(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. PF_0, // D78
  96. PF_1, // D79
  97. PF_2, // D80
  98. PF_3, // D81/A14
  99. PF_4, // D82/A15
  100. PF_5, // D83/A16
  101. PF_6, // D84/A17
  102. PF_7, // D85/A18
  103. PF_8, // D86/A19
  104. PF_9, // D87/A20
  105. PF_10, // D88/A21
  106. PF_11, // D89/A22
  107. PF_12, // D90/A23
  108. PF_13, // D91/A24
  109. PF_14, // D92/A25
  110. PF_15, // D93
  111. PG_0, // D94
  112. PG_1, // D95
  113. PG_2, // D96
  114. PG_3, // D97
  115. PG_4, // D98
  116. PG_5, // D99
  117. PG_6, // D100
  118. PG_7, // D101
  119. PG_8, // D102
  120. PG_9, // D103
  121. PG_10, // D104
  122. PG_11, // D105
  123. PG_12, // D106
  124. PG_13, // D107
  125. PG_14, // D108
  126. PG_15, // D109
  127. PH_0, // D110
  128. PH_1, // D111
  129. PC_2_C, // D112/A26
  130. PC_3_C // D113/A27
  131. };
  132. // Analog (Ax) pin number array
  133. const uint32_t analogInputPin[] = {
  134. 0, // A0, PA0
  135. 1, // A1, PA1
  136. 2, // A2, PA2
  137. 3, // A3, PA3
  138. 4, // A4, PA4
  139. 5, // A5, PA5
  140. 6, // A6, PA6
  141. 7, // A7, PA7
  142. 16, // A8, PB0
  143. 17, // A9, PB1
  144. 32, // A10, PC0
  145. 33, // A11, PC1
  146. 34, // A12, PC4
  147. 35, // A13, PC5
  148. 81, // A14, PF3
  149. 82, // A15, PF4
  150. 83, // A16, PF5
  151. 84, // A17, PF6
  152. 85, // A18, PF7
  153. 86, // A19, PF8
  154. 87, // A20, PF9
  155. 88, // A21, PF10
  156. 89, // A22, PF11
  157. 90, // A23, PF12
  158. 91, // A24, PF13
  159. 92, // A25, PF14
  160. 112, // A26, PC2_C
  161. 113 // A27, PC3_C
  162. };
  163. void MPU_Config(void)
  164. {
  165. MPU_Region_InitTypeDef MPU_InitStruct = {0};
  166. /* Disables the MPU */
  167. HAL_MPU_Disable();
  168. /** Initializes and configures the Region and the memory to be protected
  169. */
  170. MPU_InitStruct.Enable = MPU_REGION_ENABLE;
  171. MPU_InitStruct.Number = MPU_REGION_NUMBER0;
  172. MPU_InitStruct.BaseAddress = 0x0;
  173. MPU_InitStruct.Size = MPU_REGION_SIZE_4GB;
  174. MPU_InitStruct.SubRegionDisable = 0x87;
  175. MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
  176. MPU_InitStruct.AccessPermission = MPU_REGION_NO_ACCESS;
  177. MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_DISABLE;
  178. MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
  179. MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
  180. MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
  181. HAL_MPU_ConfigRegion(&MPU_InitStruct);
  182. /* Enables the MPU */
  183. HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
  184. }
  185. /*
  186. * @brief System Clock Configuration
  187. * @param None
  188. * @retval None
  189. */
  190. WEAK void SystemClock_Config(void)
  191. {
  192. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  193. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  194. RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {};
  195. MPU_Config();
  196. /** Supply configuration update enable
  197. */
  198. HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);
  199. /** Configure the main internal regulator output voltage
  200. */
  201. __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE0);
  202. while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
  203. /** Initializes the RCC Oscillators according to the specified parameters
  204. * in the RCC_OscInitTypeDef structure.
  205. */
  206. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48 | RCC_OSCILLATORTYPE_HSE;
  207. RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  208. RCC_OscInitStruct.HSI48State = RCC_HSI48_ON; // 48Mhz for USB
  209. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  210. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  211. RCC_OscInitStruct.PLL.PLLM = 5; // 25Mhz / 5 = 5Mhz
  212. RCC_OscInitStruct.PLL.PLLN = 110; // 25Mhz / 5 * 110 = 550Mhz
  213. RCC_OscInitStruct.PLL.PLLP = 1; // 550Mhz / 1 = 550Mhz
  214. RCC_OscInitStruct.PLL.PLLQ = 10; // 550Mhz / 10 = 55Mhz
  215. RCC_OscInitStruct.PLL.PLLR = 10; // unused
  216. RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_2;
  217. RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
  218. RCC_OscInitStruct.PLL.PLLFRACN = 0;
  219. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  220. {
  221. Error_Handler();
  222. }
  223. /** Initializes the CPU, AHB and APB buses clocks
  224. */
  225. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  226. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
  227. |RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;
  228. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  229. RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
  230. RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV2;
  231. RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV2;
  232. RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV2;
  233. RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV2;
  234. RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV2;
  235. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
  236. {
  237. Error_Handler();
  238. }
  239. PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USB
  240. | RCC_PERIPHCLK_SDMMC | RCC_PERIPHCLK_ADC
  241. | RCC_PERIPHCLK_LPUART1 | RCC_PERIPHCLK_USART16
  242. | RCC_PERIPHCLK_USART234578 | RCC_PERIPHCLK_I2C123
  243. | RCC_PERIPHCLK_I2C4 | RCC_PERIPHCLK_SPI123
  244. | RCC_PERIPHCLK_SPI45 | RCC_PERIPHCLK_SPI6;
  245. /* HSI48 used for USB 48 Mhz */
  246. /* PLL1 qclk also used for FMC, SDMMC, RNG, SAI */
  247. /* PLL2 pclk is needed for adc max 80 Mhz (p,q,r same) */
  248. /* PLL2 pclk also used for LP timers 2,3,4,5, SPI 1,2,3 */
  249. /* PLL2 qclk is needed for uart, can, spi4,5,6 80 Mhz */
  250. /* PLL3 r clk is needed for i2c 80 Mhz (p,q,r same) */
  251. PeriphClkInitStruct.PLL2.PLL2M = 15; // M DIV 15 vco 25 / 15 ~ 1.667 Mhz
  252. PeriphClkInitStruct.PLL2.PLL2N = 96; // N MUL 96
  253. PeriphClkInitStruct.PLL2.PLL2P = 2; // P div 2
  254. PeriphClkInitStruct.PLL2.PLL2Q = 2; // Q div 2
  255. PeriphClkInitStruct.PLL2.PLL2R = 2; // R div 2
  256. // RCC_PLL1VCIRANGE_0 Clock range frequency between 1 and 2 MHz
  257. PeriphClkInitStruct.PLL2.PLL2RGE = RCC_PLL2VCIRANGE_0;
  258. PeriphClkInitStruct.PLL2.PLL2VCOSEL = RCC_PLL2VCOMEDIUM;
  259. PeriphClkInitStruct.PLL2.PLL2FRACN = 0;
  260. PeriphClkInitStruct.PLL3.PLL3M = 15; // M DIV 15 vco 25 / 15 ~ 1.667 Mhz
  261. PeriphClkInitStruct.PLL3.PLL3N = 96; // N MUL 96
  262. PeriphClkInitStruct.PLL3.PLL3P = 2; // P div 2
  263. PeriphClkInitStruct.PLL3.PLL3Q = 2; // Q div 2
  264. PeriphClkInitStruct.PLL3.PLL3R = 2; // R div 2
  265. // RCC_PLL1VCIRANGE_0 Clock range frequency between 1 and 2 MHz
  266. PeriphClkInitStruct.PLL3.PLL3RGE = RCC_PLL3VCIRANGE_0;
  267. PeriphClkInitStruct.PLL3.PLL3VCOSEL = RCC_PLL3VCOMEDIUM;
  268. PeriphClkInitStruct.PLL3.PLL3FRACN = 0;
  269. // ADC from PLL2 pclk
  270. PeriphClkInitStruct.AdcClockSelection = RCC_ADCCLKSOURCE_PLL2;
  271. // USB from HSI48
  272. PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_HSI48;
  273. // SDMMC from PLL1 qclk
  274. PeriphClkInitStruct.SdmmcClockSelection = 0;
  275. //PeriphClkInitStruct.SdmmcClockSelection = RCC_SDMMCCLKSOURCE_PLL;
  276. // LPUART from PLL2 qclk
  277. PeriphClkInitStruct.Lpuart1ClockSelection = 0;
  278. //PeriphClkInitStruct.Lpuart1ClockSelection = RCC_LPUART1CLKSOURCE_PLL2;
  279. // USART from PLL2 qclk
  280. PeriphClkInitStruct.Usart16ClockSelection = RCC_USART16CLKSOURCE_PLL2;
  281. // USART from PLL2 qclk
  282. PeriphClkInitStruct.Usart234578ClockSelection = 0;
  283. //PeriphClkInitStruct.Usart234578ClockSelection = RCC_USART234578CLKSOURCE_PLL2;
  284. // I2C123 from PLL3 rclk
  285. PeriphClkInitStruct.I2c123ClockSelection = RCC_I2C123CLKSOURCE_PLL3;
  286. // I2C4 from PLL3 rclk
  287. PeriphClkInitStruct.I2c4ClockSelection = 0;
  288. //PeriphClkInitStruct.I2c4ClockSelection = RCC_I2C4CLKSOURCE_PLL3;
  289. // SPI123 from PLL2 pclk
  290. PeriphClkInitStruct.Spi123ClockSelection = RCC_SPI123CLKSOURCE_PLL2;
  291. // SPI45 from PLL2 qclk
  292. PeriphClkInitStruct.Spi45ClockSelection = 0;
  293. //PeriphClkInitStruct.Spi45ClockSelection = RCC_SPI45CLKSOURCE_PLL2;
  294. // SPI6 from PLL2 qclk
  295. PeriphClkInitStruct.Spi6ClockSelection = 0;
  296. //PeriphClkInitStruct.Spi6ClockSelection = RCC_SPI6CLKSOURCE_PLL2;
  297. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) {
  298. Error_Handler();
  299. }
  300. }
  301. #endif /* ARDUINO_GENERIC_* */