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.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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;//端口G时钟
  166. GPIOG->MODER &= ~(3UL << 2 * index);//清除旧模式
  167. GPIOG->MODER |= 1 << 2 * index;//模式为输出
  168. GPIOG->OSPEEDR &= ~(3UL << 2 * index); //清除旧输出速度
  169. GPIOG->OSPEEDR |= 2 << 2 * index;//设置输出速度
  170. GPIOG->OTYPER &= ~(1UL << index);//清除旧输出方式
  171. GPIOG->OTYPER |= 0 << index;//设置输出方式为推挽
  172. GPIOG->PUPDR &= ~(3 << 2 * index);//先清除原来的设置
  173. GPIOG->PUPDR |= 1 << 2 * index;//设置新的上下拉
  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);//发送CMD13
  196. do status = SDIOx->STA;
  197. while(!(status & ((1 << 0) | (1 << 6) | (1 << 2))));//等待操作完成
  198. if(status & (1 << 0)) //CRC检测失败
  199. {
  200. SDIOx->ICR |= 1 << 0; //清除错误标记
  201. return HAL_ERROR;
  202. }
  203. if(status & (1 << 2)) //命令超时
  204. {
  205. SDIOx->ICR |= 1 << 2; //清除错误标记
  206. return HAL_ERROR;
  207. }
  208. if(SDIOx->RESPCMD != SDMMC_CMD_SEND_STATUS)return HAL_ERROR;
  209. SDIOx->ICR = 0X5FF; //清除所有标记
  210. respR1 = SDIOx->RESP1;
  211. CardState = (respR1 >> 9) & 0x0000000F;
  212. }while((CardState == HAL_SD_CARD_RECEIVING) || (CardState == HAL_SD_CARD_SENDING) || (CardState == HAL_SD_CARD_PROGRAMMING));
  213. return HAL_OK;
  214. }
  215. void debugStr(const char*str) {
  216. while(*str) {
  217. while((USART1->SR & 0x40) == 0);
  218. USART1->DR = *str++;
  219. }
  220. }
  221. /**
  222. * @brief System Clock Configuration
  223. * The system Clock is configured as follow :
  224. * System Clock source = PLL (HSE)
  225. * SYSCLK(Hz) = 168000000/120000000/180000000
  226. * HCLK(Hz) = 168000000/120000000/180000000
  227. * AHB Prescaler = 1
  228. * APB1 Prescaler = 4
  229. * APB2 Prescaler = 2
  230. * HSE Frequency(Hz) = 8000000
  231. * PLL_M = 8/4/8
  232. * PLL_N = 336/120/360
  233. * PLL_P = 2
  234. * PLL_Q = 7/5/7
  235. * VDD(V) = 3.3
  236. * Main regulator output voltage = Scale1 mode
  237. * Flash Latency(WS) = 5
  238. * @param None
  239. * @retval None
  240. */
  241. WEAK void SystemClock_Config(void)
  242. {
  243. RCC_ClkInitTypeDef RCC_ClkInitStruct;
  244. RCC_OscInitTypeDef RCC_OscInitStruct;
  245. RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
  246. HAL_StatusTypeDef ret = HAL_OK;
  247. __HAL_FLASH_INSTRUCTION_CACHE_ENABLE();
  248. __HAL_FLASH_DATA_CACHE_ENABLE();
  249. __HAL_FLASH_PREFETCH_BUFFER_ENABLE();
  250. HAL_RCC_DeInit();
  251. /* Enable Power Control clock */
  252. __HAL_RCC_PWR_CLK_ENABLE();
  253. /* The voltage scaling allows optimizing the power consumption when the device is
  254. clocked below the maximum system frequency, to update the voltage scaling value
  255. regarding system frequency refer to product datasheet. */
  256. __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  257. /* Enable HSE Oscillator and activate PLL with HSE as source */
  258. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  259. RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  260. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  261. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  262. RCC_OscInitStruct.PLL.PLLM = 8;
  263. RCC_OscInitStruct.PLL.PLLN = 336;
  264. RCC_OscInitStruct.PLL.PLLP = 2;
  265. RCC_OscInitStruct.PLL.PLLQ = 7;
  266. RCC_OscInitStruct.PLL.PLLR = 2;
  267. ret = HAL_RCC_OscConfig(&RCC_OscInitStruct);
  268. if(ret != HAL_OK)myshow(10,-1);
  269. HAL_PWREx_EnableOverDrive();
  270. /* Select PLLSAI output as USB clock source */
  271. PeriphClkInitStruct.PLLSAI.PLLSAIM = 8;
  272. PeriphClkInitStruct.PLLSAI.PLLSAIN = 192;
  273. PeriphClkInitStruct.PLLSAI.PLLSAIP = RCC_PLLSAIP_DIV4;
  274. PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_CLK48 | RCC_PERIPHCLK_SDIO;
  275. PeriphClkInitStruct.Clk48ClockSelection = RCC_CK48CLKSOURCE_PLLSAIP;
  276. PeriphClkInitStruct.SdioClockSelection = RCC_SDIOCLKSOURCE_CLK48;//SDIO Clock Mux
  277. HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
  278. /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
  279. clocks dividers */
  280. RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
  281. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  282. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  283. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  284. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
  285. ret = HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);
  286. if(ret != HAL_OK)myshow(10,-1);
  287. SystemCoreClockUpdate();//更新系统时钟SystemCoreClock
  288. /**Configure the Systick interrupt time
  289. */
  290. HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / 1000);
  291. /**Configure the Systick
  292. */
  293. HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
  294. /* SysTick_IRQn interrupt configuration */
  295. HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
  296. __enable_irq();//打开中断,因为在bootloader中关闭了,所以这里要打开
  297. }
  298. #ifdef __cplusplus
  299. }
  300. #endif