stm32f1xx_it(7060).c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file stm32f1xx_it.c
  5. * @brief Interrupt Service Routines.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2024 STMicroelectronics.
  10. * All rights reserved.
  11. *
  12. * This software is licensed under terms that can be found in the LICENSE file
  13. * in the root directory of this software component.
  14. * If no LICENSE file comes with this software, it is provided AS-IS.
  15. *
  16. ******************************************************************************
  17. */
  18. /* USER CODE END Header */
  19. /* Includes ------------------------------------------------------------------*/
  20. #include "main.h"
  21. #include "stm32f1xx_it.h"
  22. /* Private includes ----------------------------------------------------------*/
  23. /* USER CODE BEGIN Includes */
  24. /* USER CODE END Includes */
  25. /* Private typedef -----------------------------------------------------------*/
  26. /* USER CODE BEGIN TD */
  27. /* USER CODE END TD */
  28. /* Private define ------------------------------------------------------------*/
  29. /* USER CODE BEGIN PD */
  30. /* USER CODE END PD */
  31. /* Private macro -------------------------------------------------------------*/
  32. /* USER CODE BEGIN PM */
  33. /* USER CODE END PM */
  34. /* Private variables ---------------------------------------------------------*/
  35. /* USER CODE BEGIN PV */
  36. /* USER CODE END PV */
  37. /* Private function prototypes -----------------------------------------------*/
  38. /* USER CODE BEGIN PFP */
  39. /* USER CODE END PFP */
  40. /* Private user code ---------------------------------------------------------*/
  41. /* USER CODE BEGIN 0 */
  42. /* USER CODE END 0 */
  43. /* External variables --------------------------------------------------------*/
  44. extern TIM_HandleTypeDef htim2;
  45. extern TIM_HandleTypeDef htim4;
  46. extern DMA_HandleTypeDef hdma_usart2_rx;
  47. extern DMA_HandleTypeDef hdma_usart2_tx;
  48. extern DMA_HandleTypeDef hdma_usart3_tx;
  49. extern DMA_HandleTypeDef hdma_usart3_rx;
  50. extern UART_HandleTypeDef huart1;
  51. extern UART_HandleTypeDef huart2;
  52. extern UART_HandleTypeDef huart3;
  53. extern TIM_HandleTypeDef htim1;
  54. /* USER CODE BEGIN EV */
  55. /* USER CODE END EV */
  56. /******************************************************************************/
  57. /* Cortex-M3 Processor Interruption and Exception Handlers */
  58. /******************************************************************************/
  59. /**
  60. * @brief This function handles Non maskable interrupt.
  61. */
  62. void NMI_Handler(void)
  63. {
  64. /* USER CODE BEGIN NonMaskableInt_IRQn 0 */
  65. /* USER CODE END NonMaskableInt_IRQn 0 */
  66. /* USER CODE BEGIN NonMaskableInt_IRQn 1 */
  67. while (1)
  68. {
  69. }
  70. /* USER CODE END NonMaskableInt_IRQn 1 */
  71. }
  72. /**
  73. * @brief This function handles Hard fault interrupt.
  74. */
  75. void HardFault_Handler(void)
  76. {
  77. /* USER CODE BEGIN HardFault_IRQn 0 */
  78. /* USER CODE END HardFault_IRQn 0 */
  79. while (1)
  80. {
  81. /* USER CODE BEGIN W1_HardFault_IRQn 0 */
  82. /* USER CODE END W1_HardFault_IRQn 0 */
  83. }
  84. }
  85. /**
  86. * @brief This function handles Memory management fault.
  87. */
  88. void MemManage_Handler(void)
  89. {
  90. /* USER CODE BEGIN MemoryManagement_IRQn 0 */
  91. /* USER CODE END MemoryManagement_IRQn 0 */
  92. while (1)
  93. {
  94. /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */
  95. /* USER CODE END W1_MemoryManagement_IRQn 0 */
  96. }
  97. }
  98. /**
  99. * @brief This function handles Prefetch fault, memory access fault.
  100. */
  101. void BusFault_Handler(void)
  102. {
  103. /* USER CODE BEGIN BusFault_IRQn 0 */
  104. /* USER CODE END BusFault_IRQn 0 */
  105. while (1)
  106. {
  107. /* USER CODE BEGIN W1_BusFault_IRQn 0 */
  108. /* USER CODE END W1_BusFault_IRQn 0 */
  109. }
  110. }
  111. /**
  112. * @brief This function handles Undefined instruction or illegal state.
  113. */
  114. void UsageFault_Handler(void)
  115. {
  116. /* USER CODE BEGIN UsageFault_IRQn 0 */
  117. /* USER CODE END UsageFault_IRQn 0 */
  118. while (1)
  119. {
  120. /* USER CODE BEGIN W1_UsageFault_IRQn 0 */
  121. /* USER CODE END W1_UsageFault_IRQn 0 */
  122. }
  123. }
  124. /**
  125. * @brief This function handles Debug monitor.
  126. */
  127. void DebugMon_Handler(void)
  128. {
  129. /* USER CODE BEGIN DebugMonitor_IRQn 0 */
  130. /* USER CODE END DebugMonitor_IRQn 0 */
  131. /* USER CODE BEGIN DebugMonitor_IRQn 1 */
  132. /* USER CODE END DebugMonitor_IRQn 1 */
  133. }
  134. /******************************************************************************/
  135. /* STM32F1xx Peripheral Interrupt Handlers */
  136. /* Add here the Interrupt Handlers for the used peripherals. */
  137. /* For the available peripheral interrupt handler names, */
  138. /* please refer to the startup file (startup_stm32f1xx.s). */
  139. /******************************************************************************/
  140. /**
  141. * @brief This function handles DMA1 channel2 global interrupt.
  142. */
  143. void DMA1_Channel2_IRQHandler(void)
  144. {
  145. /* USER CODE BEGIN DMA1_Channel2_IRQn 0 */
  146. /* USER CODE END DMA1_Channel2_IRQn 0 */
  147. HAL_DMA_IRQHandler(&hdma_usart3_tx);
  148. /* USER CODE BEGIN DMA1_Channel2_IRQn 1 */
  149. /* USER CODE END DMA1_Channel2_IRQn 1 */
  150. }
  151. /**
  152. * @brief This function handles DMA1 channel3 global interrupt.
  153. */
  154. void DMA1_Channel3_IRQHandler(void)
  155. {
  156. /* USER CODE BEGIN DMA1_Channel3_IRQn 0 */
  157. /* USER CODE END DMA1_Channel3_IRQn 0 */
  158. HAL_DMA_IRQHandler(&hdma_usart3_rx);
  159. /* USER CODE BEGIN DMA1_Channel3_IRQn 1 */
  160. /* USER CODE END DMA1_Channel3_IRQn 1 */
  161. }
  162. /**
  163. * @brief This function handles DMA1 channel6 global interrupt.
  164. */
  165. void DMA1_Channel6_IRQHandler(void)
  166. {
  167. /* USER CODE BEGIN DMA1_Channel6_IRQn 0 */
  168. /* USER CODE END DMA1_Channel6_IRQn 0 */
  169. HAL_DMA_IRQHandler(&hdma_usart2_rx);
  170. /* USER CODE BEGIN DMA1_Channel6_IRQn 1 */
  171. /* USER CODE END DMA1_Channel6_IRQn 1 */
  172. }
  173. /**
  174. * @brief This function handles DMA1 channel7 global interrupt.
  175. */
  176. void DMA1_Channel7_IRQHandler(void)
  177. {
  178. /* USER CODE BEGIN DMA1_Channel7_IRQn 0 */
  179. /* USER CODE END DMA1_Channel7_IRQn 0 */
  180. HAL_DMA_IRQHandler(&hdma_usart2_tx);
  181. /* USER CODE BEGIN DMA1_Channel7_IRQn 1 */
  182. /* USER CODE END DMA1_Channel7_IRQn 1 */
  183. }
  184. /**
  185. * @brief This function handles TIM1 update interrupt.
  186. */
  187. void TIM1_UP_IRQHandler(void)
  188. {
  189. /* USER CODE BEGIN TIM1_UP_IRQn 0 */
  190. /* USER CODE END TIM1_UP_IRQn 0 */
  191. HAL_TIM_IRQHandler(&htim1);
  192. /* USER CODE BEGIN TIM1_UP_IRQn 1 */
  193. /* USER CODE END TIM1_UP_IRQn 1 */
  194. }
  195. /**
  196. * @brief This function handles TIM2 global interrupt.
  197. */
  198. void TIM2_IRQHandler(void)
  199. {
  200. /* USER CODE BEGIN TIM2_IRQn 0 */
  201. /* USER CODE END TIM2_IRQn 0 */
  202. HAL_TIM_IRQHandler(&htim2);
  203. /* USER CODE BEGIN TIM2_IRQn 1 */
  204. /* USER CODE END TIM2_IRQn 1 */
  205. }
  206. /**
  207. * @brief This function handles TIM4 global interrupt.
  208. */
  209. void TIM4_IRQHandler(void)
  210. {
  211. /* USER CODE BEGIN TIM4_IRQn 0 */
  212. /* USER CODE END TIM4_IRQn 0 */
  213. HAL_TIM_IRQHandler(&htim4);
  214. /* USER CODE BEGIN TIM4_IRQn 1 */
  215. /* USER CODE END TIM4_IRQn 1 */
  216. }
  217. /**
  218. * @brief This function handles USART1 global interrupt.
  219. */
  220. void USART1_IRQHandler(void)
  221. {
  222. /* USER CODE BEGIN USART1_IRQn 0 */
  223. /* USER CODE END USART1_IRQn 0 */
  224. HAL_UART_IRQHandler(&huart1);
  225. /* USER CODE BEGIN USART1_IRQn 1 */
  226. /* USER CODE END USART1_IRQn 1 */
  227. }
  228. /**
  229. * @brief This function handles USART2 global interrupt.
  230. */
  231. void USART2_IRQHandler(void)
  232. {
  233. /* USER CODE BEGIN USART2_IRQn 0 */
  234. /* USER CODE END USART2_IRQn 0 */
  235. HAL_UART_IRQHandler(&huart2);
  236. /* USER CODE BEGIN USART2_IRQn 1 */
  237. /* USER CODE END USART2_IRQn 1 */
  238. }
  239. /**
  240. * @brief This function handles USART3 global interrupt.
  241. */
  242. void USART3_IRQHandler(void)
  243. {
  244. /* USER CODE BEGIN USART3_IRQn 0 */
  245. // uint8_t temp = 0;
  246. /* USER CODE END USART3_IRQn 0 */
  247. HAL_UART_IRQHandler(&huart3);
  248. /* USER CODE BEGIN USART3_IRQn 1 */
  249. // if(__HAL_UART_GET_FLAG(&huart3, UART_FLAG_ORE) != RESET){
  250. // __HAL_UART_CLEAR_OREFLAG(&huart3);
  251. // (void)huart3.Instance->SR;
  252. // (void)huart3.Instance->DR;
  253. // }
  254. // if(__HAL_UART_GET_FLAG(&huart3, UART_FLAG_RXNE) != RESET){
  255. // HAL_UART_Receive(&huart3, &temp, 1, HAL_MAX_DELAY);
  256. // if(g_usart3_rx_len < (USART3_REC_LEN - 1)){
  257. // g_usart3_rx_buf[g_usart3_rx_len] = temp;
  258. // g_usart3_rx_len++;
  259. // }else{
  260. // g_usart3_rx_len = 0;
  261. // g_usart3_rx_buf[g_usart3_rx_len] = temp;
  262. // g_usart3_rx_len++;
  263. // }
  264. // }
  265. if(__HAL_UART_GET_FLAG(&huart3, UART_FLAG_IDLE) != RESET){
  266. // __HAL_UART_CLEAR_IDLEFLAG(&huart3);
  267. g_usart3_rx_sta++;
  268. // HAL_UART_DMAStop(&huart3);
  269. // 清除空闲中断标志(否则,中断将不断重新触发)
  270. __HAL_UART_CLEAR_IDLEFLAG(&huart3);
  271. // 停止DMA接收(这将更新DMA传输计数器)
  272. HAL_UART_DMAStop(&huart3);
  273. // 计算实际接收到的数据长度
  274. // uint16_t dataSize = BUFFER_SIZE - __HAL_DMA_GET_COUNTER(huart3.hdmarx);
  275. // 处理接收到的数据...
  276. // 如果需要继续接收,可以再次启动DMA接收
  277. HAL_UART_Receive_DMA(&huart3, (uint8_t*)g_usart3_rx_buf, USART3_REC_LEN);
  278. }
  279. // if(__HAL_UART_GET_FLAG(&huart3, UART_FLAG_TXE) != RESET)
  280. // {
  281. // huart3.Instance->DR = (uint8_t)(*huart3.pTxBuffPtr++ & (uint8_t)0x00FF);
  282. // if (huart3.TxXferCount == 0U)
  283. // {
  284. // /* Disable the UART Transmit Data Register Empty Interrupt */
  285. // __HAL_UART_DISABLE_IT(&huart3, UART_IT_TXE);
  286. // /* Enable the UART Transmit Complete Interrupt */
  287. // __HAL_UART_ENABLE_IT(&huart3, UART_IT_TC);
  288. // }
  289. // return;
  290. // }
  291. // /* UART in mode Transmitter end --------------------------------------------*/
  292. // if (__HAL_UART_GET_FLAG(&huart3, UART_FLAG_TC) != RESET)
  293. // {
  294. // /* Disable the UART Transmit Complete Interrupt */
  295. // __HAL_UART_DISABLE_IT(&huart3, UART_IT_TC);
  296. // return;
  297. // }
  298. /* USER CODE END USART3_IRQn 1 */
  299. }
  300. /* USER CODE BEGIN 1 */
  301. /* USER CODE END 1 */