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.

variant.cpp 8.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. /*
  2. Copyright (c) 2011 Arduino. All right reserved.
  3. This library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. This library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. See the GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with this library; if not, write to the Free Software
  13. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  14. */
  15. #include "pins_arduino.h"
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. // Pin number
  20. const PinName digitalPin[] = {
  21. PA_0, //D0
  22. PA_1, //D1
  23. PA_2, //D2
  24. PA_3, //D3
  25. PA_4, //D4
  26. PA_5, //D5
  27. PA_6, //D6
  28. PA_7, //D7
  29. PA_8, //D8
  30. PA_9, //D9
  31. PA_10, //D10
  32. PA_11, //D11
  33. PA_12, //D12
  34. PA_13, //D13
  35. PA_14, //D14
  36. PA_15, //D15
  37. PB_0, //D16
  38. PB_1, //D17
  39. PB_2, //D18
  40. PB_3, //D19
  41. PB_4, //D20
  42. PB_5, //D21
  43. PB_6, //D22
  44. PB_7, //D23
  45. PB_8, //D24
  46. PB_9, //D25
  47. PB_10, //D26
  48. PB_11, //D27
  49. PB_12, //D28
  50. PB_13, //D29
  51. PB_14, //D30
  52. PB_15, //D31
  53. PC_0, //D32
  54. PC_1, //D33
  55. PC_2, //D34
  56. PC_3, //D35
  57. PC_4, //D36
  58. PC_5, //D37
  59. PC_6, //D38
  60. PC_7, //D39
  61. PC_8, //D40
  62. PC_9, //D41
  63. PC_10, //D42
  64. PC_11, //D43
  65. PC_12, //D44
  66. PC_13, //D45
  67. PC_14, //D46
  68. PC_15, //D47
  69. PD_0, //D48
  70. PD_1, //D49
  71. PD_2, //D50
  72. PD_3, //D51
  73. PD_4, //D52
  74. PD_5, //D53
  75. PD_6, //D54
  76. PD_7, //D55
  77. PD_8, //D56
  78. PD_9, //D57
  79. PD_10, //D58
  80. PD_11, //D59
  81. PD_12, //D60
  82. PD_13, //D61
  83. PD_14, //D62
  84. PD_15, //D63
  85. PE_0, //D64
  86. PE_1, //D65
  87. PE_2, //D66
  88. PE_3, //D67
  89. PE_4, //D68
  90. PE_5, //D69
  91. PE_6, //D70
  92. PE_7, //D71
  93. PE_8, //D72
  94. PE_9, //D73
  95. PE_10, //D74
  96. PE_11, //D75
  97. PE_12, //D76
  98. PE_13, //D77
  99. PE_14, //D78
  100. PE_15, //D79
  101. PF_0, //D80
  102. PF_1, //D81
  103. PF_2, //D82
  104. PF_3, //D83
  105. PF_4, //D84
  106. PF_5, //D85
  107. PF_6, //D86
  108. PF_7, //D87
  109. PF_8, //D88
  110. PF_9, //D89
  111. PF_10, //D90
  112. PF_11, //D91
  113. PF_12, //D92
  114. PF_13, //D93
  115. PF_14, //D94
  116. PF_15, //D95
  117. PG_0, //D96
  118. PG_1, //D97
  119. PG_2, //D98
  120. PG_3, //D99
  121. PG_4, //D100
  122. PG_5, //D101
  123. PG_6, //D102
  124. PG_7, //D103
  125. PG_8, //D104
  126. PG_9, //D105
  127. PG_10, //D106
  128. PG_11, //D107
  129. PG_12, //D108
  130. PG_13, //D109
  131. PG_14, //D110
  132. PG_15, //D111
  133. PH_0, //D112
  134. PH_1, //D113
  135. PH_2, //D114
  136. PH_3, //D115
  137. PH_4, //D116
  138. PH_5, //D117
  139. PH_6, //D118
  140. PH_7, //D119
  141. PH_8, //D120
  142. PH_9, //D121
  143. PH_10, //D122
  144. PH_11, //D123
  145. PH_12, //D124
  146. PH_13, //D125
  147. PH_14, //D126
  148. PH_15, //D127
  149. //Duplicated ADC Pins
  150. PC_3, //A0 T0 D128
  151. PC_0, //A1 T1 D129
  152. PC_2, //A2 BED D130
  153. };
  154. #ifdef __cplusplus
  155. }
  156. #endif
  157. // ----------------------------------------------------------------------------
  158. #ifdef __cplusplus
  159. extern "C" {
  160. #endif
  161. uint32_t myvar[] = {1,2,3,4,5,6,7,8};
  162. void myshow(int fre, int times) // YSZ-WORK
  163. {
  164. uint32_t index = 10;
  165. RCC->AHB1ENR |= 1 << 6; // port G clock
  166. GPIOG->MODER &= ~(3UL << 2 * index); // clear old mode
  167. GPIOG->MODER |= 1 << 2 * index; // mode is output
  168. GPIOG->OSPEEDR &= ~(3UL << 2 * index) // Clear old output speed
  169. GPIOG->OSPEEDR |= 2 << 2 * index; // Set output speed
  170. GPIOG->OTYPER &= ~(1UL << index) // clear old output
  171. GPIOG->OTYPER |= 0 << index; // Set the output mode to push-pull
  172. GPIOG->PUPDR &= ~(3 << 2 * index) // Clear the original settings first
  173. GPIOG->PUPDR |= 1 << 2 * index; // Set new up and down
  174. while (times != 0) {
  175. GPIOG->BSRR = 1UL << index;
  176. for (int i = 0; i < fre; i++)
  177. for (int j = 0; j < 1000000; j++) __NOP();
  178. GPIOG->BSRR = 1UL << (index + 16);
  179. for (int i = 0; i < fre; i++)
  180. for (int j = 0; j < 1000000; j++) __NOP();
  181. if (times > 0) times--;
  182. }
  183. }
  184. HAL_StatusTypeDef SDMMC_IsProgramming(SDIO_TypeDef *SDIOx,uint32_t RCA)
  185. {
  186. HAL_SD_CardStateTypeDef CardState;
  187. volatile uint32_t respR1 = 0, status = 0;
  188. SDIO_CmdInitTypeDef sdmmc_cmdinit;
  189. do {
  190. sdmmc_cmdinit.Argument = RCA << 16;
  191. sdmmc_cmdinit.CmdIndex = SDMMC_CMD_SEND_STATUS;
  192. sdmmc_cmdinit.Response = SDIO_RESPONSE_SHORT;
  193. sdmmc_cmdinit.WaitForInterrupt = SDIO_WAIT_NO;
  194. sdmmc_cmdinit.CPSM = SDIO_CPSM_ENABLE;
  195. SDIO_SendCommand(SDIOx,&sdmmc_cmdinit); // send CMD13
  196. do status = SDIOx->STA;
  197. while (!(status & ((1 << 0) | (1 << 6) | (1 << 2)))); // wait for the operation to complete
  198. if (status & (1 << 0)) { // CRC check failed
  199. SDIOx->ICR |= 1 << 0; // clear error flag
  200. return HAL_ERROR;
  201. }
  202. if (status & (1 << 2)) { // command timed out
  203. SDIOx->ICR |= 1 << 2; // clear error flag
  204. return HAL_ERROR;
  205. }
  206. if (SDIOx->RESPCMD != SDMMC_CMD_SEND_STATUS) return HAL_ERROR;
  207. SDIOx->ICR = 0X5FF; // clear all tags
  208. respR1 = SDIOx->RESP1;
  209. CardState = (respR1 >> 9) & 0x0000000F;
  210. } while ((CardState == HAL_SD_CARD_RECEIVING) || (CardState == HAL_SD_CARD_SENDING) || (CardState == HAL_SD_CARD_PROGRAMMING));
  211. return HAL_OK;
  212. }
  213. void debugStr(const char *str) {
  214. while (*str) {
  215. while ((USART1->SR & 0x40) == 0);
  216. USART1->DR = *str++;
  217. }
  218. }
  219. /**
  220. * @brief System Clock Configuration
  221. * The system Clock is configured as follows:
  222. * System Clock source = PLL (HSE)
  223. * SYSCLK(Hz) = 168000000/120000000/180000000
  224. * HCLK(Hz) = 168000000/120000000/180000000
  225. * AHB Prescaler = 1
  226. * APB1 Prescaler = 4
  227. * APB2 Prescaler = 2
  228. * HSE Frequency(Hz) = 8000000
  229. * PLL_M = 8/4/8
  230. * PLL_N = 336/120/360
  231. * PLL_P = 2
  232. * PLL_Q = 7/5/7
  233. * VDD(V) = 3.3
  234. * Main regulator output voltage = Scale1 mode
  235. * Flash Latency(WS) = 5
  236. * @param None
  237. * @retval None
  238. */
  239. WEAK void SystemClock_Config(void)
  240. {
  241. RCC_ClkInitTypeDef RCC_ClkInitStruct;
  242. RCC_OscInitTypeDef RCC_OscInitStruct;
  243. RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
  244. HAL_StatusTypeDef ret = HAL_OK;
  245. __HAL_FLASH_INSTRUCTION_CACHE_ENABLE();
  246. __HAL_FLASH_DATA_CACHE_ENABLE();
  247. __HAL_FLASH_PREFETCH_BUFFER_ENABLE();
  248. HAL_RCC_DeInit();
  249. /* Enable Power Control clock */
  250. __HAL_RCC_PWR_CLK_ENABLE();
  251. /* The voltage scaling allows optimizing the power consumption when the device is
  252. clocked below the maximum system frequency, to update the voltage scaling value
  253. regarding system frequency refer to product datasheet. */
  254. __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  255. /* Enable HSE Oscillator and activate PLL with HSE as source */
  256. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  257. RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  258. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  259. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  260. RCC_OscInitStruct.PLL.PLLM = 8;
  261. RCC_OscInitStruct.PLL.PLLN = 336;
  262. RCC_OscInitStruct.PLL.PLLP = 2;
  263. RCC_OscInitStruct.PLL.PLLQ = 7;
  264. RCC_OscInitStruct.PLL.PLLR = 2;
  265. ret = HAL_RCC_OscConfig(&RCC_OscInitStruct);
  266. if (ret != HAL_OK) myshow(10,-1);
  267. HAL_PWREx_EnableOverDrive();
  268. /* Select PLLSAI output as USB clock source */
  269. PeriphClkInitStruct.PLLSAI.PLLSAIM = 8;
  270. PeriphClkInitStruct.PLLSAI.PLLSAIN = 192;
  271. PeriphClkInitStruct.PLLSAI.PLLSAIP = RCC_PLLSAIP_DIV4;
  272. PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_CLK48 | RCC_PERIPHCLK_SDIO;
  273. PeriphClkInitStruct.Clk48ClockSelection = RCC_CK48CLKSOURCE_PLLSAIP;
  274. PeriphClkInitStruct.SdioClockSelection = RCC_SDIOCLKSOURCE_CLK48; // SDIO Clock Mux
  275. HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
  276. /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */
  277. RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
  278. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  279. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  280. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  281. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
  282. ret = HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);
  283. if (ret != HAL_OK) myshow(10,-1);
  284. SystemCoreClockUpdate();
  285. /* Configure the Systick interrupt time */
  286. HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / 1000);
  287. /* Configure the Systick */
  288. HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
  289. /* SysTick_IRQn interrupt configuration */
  290. HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
  291. __enable_irq(); // Turn on the interrupt here because it is turned off in the bootloader
  292. }
  293. #ifdef __cplusplus
  294. }
  295. #endif