usart.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. /**
  2. ******************************************************************************
  3. * @file usart.c
  4. * @brief This file provides code for the configuration
  5. * of the USART instances.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2023 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. /* Includes ------------------------------------------------------------------*/
  20. #include "usart.h"
  21. /* USER CODE BEGIN 0 */
  22. #include <rtthread.h>
  23. #include "string.h"
  24. #include "weight.h"
  25. #include "display.h"
  26. volatile uint8_t rx_len=0;
  27. //volatile uint8_t recv_end_flag=0;
  28. uint8_t rx_buffer1[BUFFER_SIZE];
  29. uint8_t rx_buffer2[BUFFER_SIZE];
  30. uint8_t rx_buffer3[BUFFER_SIZE];
  31. uint8_t rx_buffer4[BUFFER_SIZE];
  32. /* 消息队列控制块 */
  33. //struct rt_messagequeue mq;
  34. /* 消息队列中用到的放置消息的内存池 */
  35. //rt_uint8_t msg_pool[2048];
  36. /* USER CODE END 0 */
  37. UART_HandleTypeDef huart4;
  38. UART_HandleTypeDef huart5;
  39. UART_HandleTypeDef huart1;
  40. UART_HandleTypeDef huart2;
  41. UART_HandleTypeDef huart3;
  42. DMA_HandleTypeDef hdma_uart4_rx;
  43. DMA_HandleTypeDef hdma_uart4_tx;
  44. DMA_HandleTypeDef hdma_usart1_rx;
  45. DMA_HandleTypeDef hdma_usart1_tx;
  46. DMA_HandleTypeDef hdma_usart2_rx;
  47. DMA_HandleTypeDef hdma_usart2_tx;
  48. DMA_HandleTypeDef hdma_usart3_rx;
  49. DMA_HandleTypeDef hdma_usart3_tx;
  50. /* UART4 init function */
  51. void MX_UART4_Init(void)
  52. {
  53. huart4.Instance = UART4;
  54. huart4.Init.BaudRate = 57600;
  55. huart4.Init.WordLength = UART_WORDLENGTH_8B;
  56. huart4.Init.StopBits = UART_STOPBITS_1;
  57. huart4.Init.Parity = UART_PARITY_NONE;
  58. huart4.Init.Mode = UART_MODE_TX_RX;
  59. huart4.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  60. huart4.Init.OverSampling = UART_OVERSAMPLING_16;
  61. if (HAL_UART_Init(&huart4) != HAL_OK)
  62. {
  63. Error_Handler();
  64. }
  65. }
  66. /* UART5 init function */
  67. void MX_UART5_Init(void)
  68. {
  69. huart5.Instance = UART5;
  70. huart5.Init.BaudRate = 115200;
  71. huart5.Init.WordLength = UART_WORDLENGTH_8B;
  72. huart5.Init.StopBits = UART_STOPBITS_1;
  73. huart5.Init.Parity = UART_PARITY_NONE;
  74. huart5.Init.Mode = UART_MODE_TX_RX;
  75. huart5.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  76. huart5.Init.OverSampling = UART_OVERSAMPLING_16;
  77. if (HAL_UART_Init(&huart5) != HAL_OK)
  78. {
  79. Error_Handler();
  80. }
  81. }
  82. /* USART1 init function */
  83. void MX_USART1_UART_Init(void)
  84. {
  85. huart1.Instance = USART1;
  86. huart1.Init.BaudRate = 9600;
  87. huart1.Init.WordLength = UART_WORDLENGTH_8B;
  88. huart1.Init.StopBits = UART_STOPBITS_1;
  89. huart1.Init.Parity = UART_PARITY_NONE;
  90. huart1.Init.Mode = UART_MODE_TX_RX;
  91. huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  92. huart1.Init.OverSampling = UART_OVERSAMPLING_16;
  93. if (HAL_UART_Init(&huart1) != HAL_OK)
  94. {
  95. Error_Handler();
  96. }
  97. }
  98. /* USART2 init function */
  99. void MX_USART2_UART_Init(void)
  100. {
  101. huart2.Instance = USART2;
  102. huart2.Init.BaudRate = 9600;
  103. huart2.Init.WordLength = UART_WORDLENGTH_8B;
  104. huart2.Init.StopBits = UART_STOPBITS_1;
  105. huart2.Init.Parity = UART_PARITY_NONE;
  106. huart2.Init.Mode = UART_MODE_TX_RX;
  107. huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  108. huart2.Init.OverSampling = UART_OVERSAMPLING_16;
  109. if (HAL_UART_Init(&huart2) != HAL_OK)
  110. {
  111. Error_Handler();
  112. }
  113. }
  114. /* USART3 init function */
  115. void MX_USART3_UART_Init(void)
  116. {
  117. huart3.Instance = USART3;
  118. huart3.Init.BaudRate = 9600;
  119. huart3.Init.WordLength = UART_WORDLENGTH_8B;
  120. huart3.Init.StopBits = UART_STOPBITS_1;
  121. huart3.Init.Parity = UART_PARITY_NONE;
  122. huart3.Init.Mode = UART_MODE_TX_RX;
  123. huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  124. huart3.Init.OverSampling = UART_OVERSAMPLING_16;
  125. if (HAL_UART_Init(&huart3) != HAL_OK)
  126. {
  127. Error_Handler();
  128. }
  129. }
  130. void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)
  131. {
  132. GPIO_InitTypeDef GPIO_InitStruct = {0};
  133. if(uartHandle->Instance==UART4)
  134. {
  135. /* USER CODE BEGIN UART4_MspInit 0 */
  136. /* USER CODE END UART4_MspInit 0 */
  137. /* UART4 clock enable */
  138. __HAL_RCC_UART4_CLK_ENABLE();
  139. __HAL_RCC_GPIOC_CLK_ENABLE();
  140. /**UART4 GPIO Configuration
  141. PC10 ------> UART4_TX
  142. PC11 ------> UART4_RX
  143. */
  144. GPIO_InitStruct.Pin = GPIO_PIN_10;
  145. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  146. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  147. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  148. GPIO_InitStruct.Pin = GPIO_PIN_11;
  149. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  150. GPIO_InitStruct.Pull = GPIO_NOPULL;
  151. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  152. /* UART4 DMA Init */
  153. /* UART4_RX Init */
  154. hdma_uart4_rx.Instance = DMA2_Channel3;
  155. hdma_uart4_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
  156. hdma_uart4_rx.Init.PeriphInc = DMA_PINC_DISABLE;
  157. hdma_uart4_rx.Init.MemInc = DMA_MINC_ENABLE;
  158. hdma_uart4_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
  159. hdma_uart4_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
  160. hdma_uart4_rx.Init.Mode = DMA_NORMAL;
  161. hdma_uart4_rx.Init.Priority = DMA_PRIORITY_LOW;
  162. if (HAL_DMA_Init(&hdma_uart4_rx) != HAL_OK)
  163. {
  164. Error_Handler();
  165. }
  166. __HAL_LINKDMA(uartHandle,hdmarx,hdma_uart4_rx);
  167. /* UART4_TX Init */
  168. hdma_uart4_tx.Instance = DMA2_Channel5;
  169. hdma_uart4_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
  170. hdma_uart4_tx.Init.PeriphInc = DMA_PINC_DISABLE;
  171. hdma_uart4_tx.Init.MemInc = DMA_MINC_ENABLE;
  172. hdma_uart4_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
  173. hdma_uart4_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
  174. hdma_uart4_tx.Init.Mode = DMA_NORMAL;
  175. hdma_uart4_tx.Init.Priority = DMA_PRIORITY_LOW;
  176. if (HAL_DMA_Init(&hdma_uart4_tx) != HAL_OK)
  177. {
  178. Error_Handler();
  179. }
  180. __HAL_LINKDMA(uartHandle,hdmatx,hdma_uart4_tx);
  181. /* UART4 interrupt Init */
  182. HAL_NVIC_SetPriority(UART4_IRQn, 1, 0);
  183. HAL_NVIC_EnableIRQ(UART4_IRQn);
  184. /* USER CODE BEGIN UART4_MspInit 1 */
  185. display_usart_Init(uartHandle);
  186. /* USER CODE END UART4_MspInit 1 */
  187. }
  188. else if(uartHandle->Instance==UART5)
  189. {
  190. /* USER CODE BEGIN UART5_MspInit 0 */
  191. /* USER CODE END UART5_MspInit 0 */
  192. /* UART5 clock enable */
  193. __HAL_RCC_UART5_CLK_ENABLE();
  194. __HAL_RCC_GPIOC_CLK_ENABLE();
  195. __HAL_RCC_GPIOD_CLK_ENABLE();
  196. /**UART5 GPIO Configuration
  197. PC12 ------> UART5_TX
  198. PD2 ------> UART5_RX
  199. */
  200. GPIO_InitStruct.Pin = GPIO_PIN_12;
  201. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  202. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  203. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  204. GPIO_InitStruct.Pin = GPIO_PIN_2;
  205. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  206. GPIO_InitStruct.Pull = GPIO_NOPULL;
  207. HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  208. /* UART5 interrupt Init */
  209. HAL_NVIC_SetPriority(UART5_IRQn, 0, 0);
  210. HAL_NVIC_EnableIRQ(UART5_IRQn);
  211. /* USER CODE BEGIN UART5_MspInit 1 */
  212. /* USER CODE END UART5_MspInit 1 */
  213. }
  214. else if(uartHandle->Instance==USART1)
  215. {
  216. /* USER CODE BEGIN USART1_MspInit 0 */
  217. /* USER CODE END USART1_MspInit 0 */
  218. /* USART1 clock enable */
  219. __HAL_RCC_USART1_CLK_ENABLE();
  220. __HAL_RCC_GPIOA_CLK_ENABLE();
  221. /**USART1 GPIO Configuration
  222. PA9 ------> USART1_TX
  223. PA10 ------> USART1_RX
  224. */
  225. GPIO_InitStruct.Pin = GPIO_PIN_9;
  226. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  227. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  228. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  229. GPIO_InitStruct.Pin = GPIO_PIN_10;
  230. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  231. GPIO_InitStruct.Pull = GPIO_NOPULL;
  232. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  233. /* USART1 DMA Init */
  234. /* USART1_RX Init */
  235. hdma_usart1_rx.Instance = DMA1_Channel5;
  236. hdma_usart1_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
  237. hdma_usart1_rx.Init.PeriphInc = DMA_PINC_DISABLE;
  238. hdma_usart1_rx.Init.MemInc = DMA_MINC_ENABLE;
  239. hdma_usart1_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
  240. hdma_usart1_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
  241. hdma_usart1_rx.Init.Mode = DMA_NORMAL;
  242. hdma_usart1_rx.Init.Priority = DMA_PRIORITY_LOW;
  243. if (HAL_DMA_Init(&hdma_usart1_rx) != HAL_OK)
  244. {
  245. Error_Handler();
  246. }
  247. __HAL_LINKDMA(uartHandle,hdmarx,hdma_usart1_rx);
  248. /* USART1_TX Init */
  249. hdma_usart1_tx.Instance = DMA1_Channel4;
  250. hdma_usart1_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
  251. hdma_usart1_tx.Init.PeriphInc = DMA_PINC_DISABLE;
  252. hdma_usart1_tx.Init.MemInc = DMA_MINC_ENABLE;
  253. hdma_usart1_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
  254. hdma_usart1_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
  255. hdma_usart1_tx.Init.Mode = DMA_NORMAL;
  256. hdma_usart1_tx.Init.Priority = DMA_PRIORITY_LOW;
  257. if (HAL_DMA_Init(&hdma_usart1_tx) != HAL_OK)
  258. {
  259. Error_Handler();
  260. }
  261. __HAL_LINKDMA(uartHandle,hdmatx,hdma_usart1_tx);
  262. /* USART1 interrupt Init */
  263. HAL_NVIC_SetPriority(USART1_IRQn, 1, 0);
  264. HAL_NVIC_EnableIRQ(USART1_IRQn);
  265. /* USER CODE BEGIN USART1_MspInit 1 */
  266. weight_usart_Init(uartHandle);
  267. /* USER CODE END USART1_MspInit 1 */
  268. }
  269. else if(uartHandle->Instance==USART2)
  270. {
  271. /* USER CODE BEGIN USART2_MspInit 0 */
  272. /* USER CODE END USART2_MspInit 0 */
  273. /* USART2 clock enable */
  274. __HAL_RCC_USART2_CLK_ENABLE();
  275. __HAL_RCC_GPIOA_CLK_ENABLE();
  276. /**USART2 GPIO Configuration
  277. PA2 ------> USART2_TX
  278. PA3 ------> USART2_RX
  279. */
  280. GPIO_InitStruct.Pin = GPIO_PIN_2;
  281. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  282. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  283. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  284. GPIO_InitStruct.Pin = GPIO_PIN_3;
  285. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  286. GPIO_InitStruct.Pull = GPIO_NOPULL;
  287. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  288. /* USART2 DMA Init */
  289. /* USART2_RX Init */
  290. hdma_usart2_rx.Instance = DMA1_Channel6;
  291. hdma_usart2_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
  292. hdma_usart2_rx.Init.PeriphInc = DMA_PINC_DISABLE;
  293. hdma_usart2_rx.Init.MemInc = DMA_MINC_ENABLE;
  294. hdma_usart2_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
  295. hdma_usart2_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
  296. hdma_usart2_rx.Init.Mode = DMA_NORMAL;
  297. hdma_usart2_rx.Init.Priority = DMA_PRIORITY_LOW;
  298. if (HAL_DMA_Init(&hdma_usart2_rx) != HAL_OK)
  299. {
  300. Error_Handler();
  301. }
  302. __HAL_LINKDMA(uartHandle,hdmarx,hdma_usart2_rx);
  303. /* USART2_TX Init */
  304. hdma_usart2_tx.Instance = DMA1_Channel7;
  305. hdma_usart2_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
  306. hdma_usart2_tx.Init.PeriphInc = DMA_PINC_DISABLE;
  307. hdma_usart2_tx.Init.MemInc = DMA_MINC_ENABLE;
  308. hdma_usart2_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
  309. hdma_usart2_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
  310. hdma_usart2_tx.Init.Mode = DMA_NORMAL;
  311. hdma_usart2_tx.Init.Priority = DMA_PRIORITY_LOW;
  312. if (HAL_DMA_Init(&hdma_usart2_tx) != HAL_OK)
  313. {
  314. Error_Handler();
  315. }
  316. __HAL_LINKDMA(uartHandle,hdmatx,hdma_usart2_tx);
  317. /* USART2 interrupt Init */
  318. HAL_NVIC_SetPriority(USART2_IRQn, 1, 0);
  319. HAL_NVIC_EnableIRQ(USART2_IRQn);
  320. /* USER CODE BEGIN USART2_MspInit 1 */
  321. weight_usart_Init(uartHandle);
  322. /* USER CODE END USART2_MspInit 1 */
  323. }
  324. else if(uartHandle->Instance==USART3)
  325. {
  326. /* USER CODE BEGIN USART3_MspInit 0 */
  327. /* USER CODE END USART3_MspInit 0 */
  328. /* USART3 clock enable */
  329. __HAL_RCC_USART3_CLK_ENABLE();
  330. __HAL_RCC_GPIOB_CLK_ENABLE();
  331. /**USART3 GPIO Configuration
  332. PB10 ------> USART3_TX
  333. PB11 ------> USART3_RX
  334. */
  335. GPIO_InitStruct.Pin = GPIO_PIN_10;
  336. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  337. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  338. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  339. GPIO_InitStruct.Pin = GPIO_PIN_11;
  340. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  341. GPIO_InitStruct.Pull = GPIO_NOPULL;
  342. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  343. /* USART3 DMA Init */
  344. /* USART3_RX Init */
  345. hdma_usart3_rx.Instance = DMA1_Channel3;
  346. hdma_usart3_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
  347. hdma_usart3_rx.Init.PeriphInc = DMA_PINC_DISABLE;
  348. hdma_usart3_rx.Init.MemInc = DMA_MINC_ENABLE;
  349. hdma_usart3_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
  350. hdma_usart3_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
  351. hdma_usart3_rx.Init.Mode = DMA_NORMAL;
  352. hdma_usart3_rx.Init.Priority = DMA_PRIORITY_LOW;
  353. if (HAL_DMA_Init(&hdma_usart3_rx) != HAL_OK)
  354. {
  355. Error_Handler();
  356. }
  357. __HAL_LINKDMA(uartHandle,hdmarx,hdma_usart3_rx);
  358. /* USART3_TX Init */
  359. hdma_usart3_tx.Instance = DMA1_Channel2;
  360. hdma_usart3_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
  361. hdma_usart3_tx.Init.PeriphInc = DMA_PINC_DISABLE;
  362. hdma_usart3_tx.Init.MemInc = DMA_MINC_ENABLE;
  363. hdma_usart3_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
  364. hdma_usart3_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
  365. hdma_usart3_tx.Init.Mode = DMA_NORMAL;
  366. hdma_usart3_tx.Init.Priority = DMA_PRIORITY_LOW;
  367. if (HAL_DMA_Init(&hdma_usart3_tx) != HAL_OK)
  368. {
  369. Error_Handler();
  370. }
  371. __HAL_LINKDMA(uartHandle,hdmatx,hdma_usart3_tx);
  372. /* USART3 interrupt Init */
  373. HAL_NVIC_SetPriority(USART3_IRQn, 1, 0);
  374. HAL_NVIC_EnableIRQ(USART3_IRQn);
  375. /* USER CODE BEGIN USART3_MspInit 1 */
  376. weight_usart_Init(uartHandle);
  377. /* USER CODE END USART3_MspInit 1 */
  378. }
  379. }
  380. void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle)
  381. {
  382. if(uartHandle->Instance==UART4)
  383. {
  384. /* USER CODE BEGIN UART4_MspDeInit 0 */
  385. /* USER CODE END UART4_MspDeInit 0 */
  386. /* Peripheral clock disable */
  387. __HAL_RCC_UART4_CLK_DISABLE();
  388. /**UART4 GPIO Configuration
  389. PC10 ------> UART4_TX
  390. PC11 ------> UART4_RX
  391. */
  392. HAL_GPIO_DeInit(GPIOC, GPIO_PIN_10|GPIO_PIN_11);
  393. /* UART4 DMA DeInit */
  394. HAL_DMA_DeInit(uartHandle->hdmarx);
  395. HAL_DMA_DeInit(uartHandle->hdmatx);
  396. /* UART4 interrupt Deinit */
  397. HAL_NVIC_DisableIRQ(UART4_IRQn);
  398. /* USER CODE BEGIN UART4_MspDeInit 1 */
  399. /* USER CODE END UART4_MspDeInit 1 */
  400. }
  401. else if(uartHandle->Instance==UART5)
  402. {
  403. /* USER CODE BEGIN UART5_MspDeInit 0 */
  404. /* USER CODE END UART5_MspDeInit 0 */
  405. /* Peripheral clock disable */
  406. __HAL_RCC_UART5_CLK_DISABLE();
  407. /**UART5 GPIO Configuration
  408. PC12 ------> UART5_TX
  409. PD2 ------> UART5_RX
  410. */
  411. HAL_GPIO_DeInit(GPIOC, GPIO_PIN_12);
  412. HAL_GPIO_DeInit(GPIOD, GPIO_PIN_2);
  413. /* UART5 interrupt Deinit */
  414. HAL_NVIC_DisableIRQ(UART5_IRQn);
  415. /* USER CODE BEGIN UART5_MspDeInit 1 */
  416. /* USER CODE END UART5_MspDeInit 1 */
  417. }
  418. else if(uartHandle->Instance==USART1)
  419. {
  420. /* USER CODE BEGIN USART1_MspDeInit 0 */
  421. /* USER CODE END USART1_MspDeInit 0 */
  422. /* Peripheral clock disable */
  423. __HAL_RCC_USART1_CLK_DISABLE();
  424. /**USART1 GPIO Configuration
  425. PA9 ------> USART1_TX
  426. PA10 ------> USART1_RX
  427. */
  428. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10);
  429. /* USART1 DMA DeInit */
  430. HAL_DMA_DeInit(uartHandle->hdmarx);
  431. HAL_DMA_DeInit(uartHandle->hdmatx);
  432. /* USART1 interrupt Deinit */
  433. HAL_NVIC_DisableIRQ(USART1_IRQn);
  434. /* USER CODE BEGIN USART1_MspDeInit 1 */
  435. /* USER CODE END USART1_MspDeInit 1 */
  436. }
  437. else if(uartHandle->Instance==USART2)
  438. {
  439. /* USER CODE BEGIN USART2_MspDeInit 0 */
  440. /* USER CODE END USART2_MspDeInit 0 */
  441. /* Peripheral clock disable */
  442. __HAL_RCC_USART2_CLK_DISABLE();
  443. /**USART2 GPIO Configuration
  444. PA2 ------> USART2_TX
  445. PA3 ------> USART2_RX
  446. */
  447. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3);
  448. /* USART2 DMA DeInit */
  449. HAL_DMA_DeInit(uartHandle->hdmarx);
  450. HAL_DMA_DeInit(uartHandle->hdmatx);
  451. /* USART2 interrupt Deinit */
  452. HAL_NVIC_DisableIRQ(USART2_IRQn);
  453. /* USER CODE BEGIN USART2_MspDeInit 1 */
  454. /* USER CODE END USART2_MspDeInit 1 */
  455. }
  456. else if(uartHandle->Instance==USART3)
  457. {
  458. /* USER CODE BEGIN USART3_MspDeInit 0 */
  459. /* USER CODE END USART3_MspDeInit 0 */
  460. /* Peripheral clock disable */
  461. __HAL_RCC_USART3_CLK_DISABLE();
  462. /**USART3 GPIO Configuration
  463. PB10 ------> USART3_TX
  464. PB11 ------> USART3_RX
  465. */
  466. HAL_GPIO_DeInit(GPIOB, GPIO_PIN_10|GPIO_PIN_11);
  467. /* USART3 DMA DeInit */
  468. HAL_DMA_DeInit(uartHandle->hdmarx);
  469. HAL_DMA_DeInit(uartHandle->hdmatx);
  470. /* USART3 interrupt Deinit */
  471. HAL_NVIC_DisableIRQ(USART3_IRQn);
  472. /* USER CODE BEGIN USART3_MspDeInit 1 */
  473. /* USER CODE END USART3_MspDeInit 1 */
  474. }
  475. }
  476. /* USER CODE BEGIN 1 */
  477. void print_char(char c)
  478. {
  479. HAL_UART_Transmit(&huart5, (uint8_t *) (&c), 1, 1);
  480. }
  481. /* USER CODE END 1 */
  482. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/