My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /*
  2. *******************************************************************************
  3. * Copyright (c) 2019, 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. #include "pins_arduino.h"
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. // Digital PinName array
  18. const PinName digitalPin[] = {
  19. PA_0, //D0
  20. PA_1, //D1
  21. PA_2, //D2
  22. PA_3, //D3
  23. PA_4, //D4
  24. PA_5, //D5
  25. PA_6, //D6
  26. PA_7, //D7
  27. PA_8, //D8
  28. PA_9, //D9
  29. PA_10, //D10
  30. PA_11, //D11
  31. PA_12, //D12
  32. PA_13, //D13
  33. PA_14, //D14
  34. PA_15, //D15
  35. PB_0, //D16
  36. PB_1, //D17
  37. PB_2, //D18
  38. PB_3, //D19
  39. PB_4, //D20
  40. PB_5, //D21
  41. PB_6, //D22
  42. PB_7, //D23
  43. PB_8, //D24
  44. PB_9, //D25
  45. PB_10, //D26
  46. PB_11, //D27
  47. PB_12, //D28
  48. PB_13, //D29
  49. PB_14, //D30
  50. PB_15, //D31
  51. PC_0, //D32
  52. PC_1, //D33
  53. PC_2, //D34
  54. PC_3, //D35
  55. PC_4, //D36
  56. PC_5, //D37
  57. PC_6, //D38
  58. PC_7, //D39
  59. PC_8, //D40
  60. PC_9, //D41
  61. PC_10, //D42
  62. PC_11, //D43
  63. PC_12, //D44
  64. PC_13, //D45
  65. PC_14, //D46
  66. PC_15, //D47
  67. PD_0, //D48
  68. PD_1, //D49
  69. PD_2, //D50
  70. PD_3, //D51
  71. PD_4, //D52
  72. PD_5, //D53
  73. PD_6, //D54
  74. PD_7, //D55
  75. PD_8, //D56
  76. PD_9, //D57
  77. PD_10, //D58
  78. PD_11, //D59
  79. PD_12, //D60
  80. PD_13, //D61
  81. PD_14, //D62
  82. PD_15, //D63
  83. PE_0, //D64
  84. PE_1, //D65
  85. PE_2, //D66
  86. PE_3, //D67
  87. PE_4, //D68
  88. PE_5, //D69
  89. PE_6, //D70
  90. PE_7, //D71
  91. PE_8, //D72
  92. PE_9, //D73
  93. PE_10, //D74
  94. PE_11, //D75
  95. PE_12, //D76
  96. PE_13, //D77
  97. PE_14, //D78
  98. PE_15, //D79
  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, PC2
  115. 35, // A13, PC3
  116. 36, // A14, PC4
  117. 37, // A15, PC5
  118. };
  119. /******************************************************************************/
  120. /* PLL (clocked by HSE) used as System clock source */
  121. /******************************************************************************/
  122. static bool SetSysClock_PLL_HSE(bool bypass)
  123. {
  124. RCC_OscInitTypeDef RCC_OscInitStruct = {};
  125. RCC_ClkInitTypeDef RCC_ClkInitStruct = {};
  126. RCC_PeriphCLKInitTypeDef PeriphClkInit = {};
  127. bool ret = false;
  128. /* Initializes the CPU, AHB and APB busses clocks */
  129. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  130. if (bypass == false) {
  131. RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  132. } else {
  133. RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
  134. }
  135. RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
  136. RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  137. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  138. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  139. RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
  140. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) == HAL_OK) {
  141. /* Initializes the CPU, AHB and APB busses clocks */
  142. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
  143. | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
  144. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  145. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  146. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  147. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  148. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) == HAL_OK) {
  149. PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC | RCC_PERIPHCLK_USB;
  150. PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV6;
  151. PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLL_DIV1_5;
  152. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) == HAL_OK) {
  153. ret = true;
  154. }
  155. }
  156. }
  157. return ret;
  158. }
  159. /******************************************************************************/
  160. /* PLL (clocked by HSI) used as System clock source */
  161. /******************************************************************************/
  162. bool SetSysClock_PLL_HSI(void)
  163. {
  164. RCC_OscInitTypeDef RCC_OscInitStruct = {};
  165. RCC_ClkInitTypeDef RCC_ClkInitStruct = {};
  166. RCC_PeriphCLKInitTypeDef PeriphClkInit = {};
  167. bool ret = false;
  168. /* Initializes the CPU, AHB and APB busses clocks */
  169. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_HSE;
  170. RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  171. RCC_OscInitStruct.HSEState = RCC_HSE_OFF;
  172. RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  173. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  174. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI_DIV2;
  175. RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL12;
  176. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) == HAL_OK) {
  177. /* Initializes the CPU, AHB and APB busses clocks */
  178. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
  179. | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
  180. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  181. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  182. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  183. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  184. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) == HAL_OK) {
  185. PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC | RCC_PERIPHCLK_USB;
  186. PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV4;
  187. PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLL;
  188. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) == HAL_OK) {
  189. ret = true;
  190. }
  191. }
  192. }
  193. return ret;
  194. }
  195. WEAK void SystemClock_Config(void)
  196. {
  197. /*
  198. * If HSE_VALUE is not 8MHz and you want use it, then:
  199. * - Redefine HSE_VALUE to the correct HSE_VALUE
  200. * - Redefine SystemClock_Config() with the correct settings
  201. */
  202. #if HSE_VALUE == 8000000U
  203. /* 1- Try to start with HSE and external 8MHz xtal */
  204. if (SetSysClock_PLL_HSE(false) == false) {
  205. /* 2- If fail try to start with HSE and external clock */
  206. if (SetSysClock_PLL_HSE(true) == false) {
  207. #endif
  208. /* 3- If fail start with HSI clock */
  209. if (SetSysClock_PLL_HSI() == false) {
  210. Error_Handler();
  211. }
  212. #if HSE_VALUE == 8000000U
  213. }
  214. }
  215. #endif
  216. }
  217. #ifdef __cplusplus
  218. }
  219. #endif