您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

368 行
11 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_it.c
  4. * @author MCD Application Team
  5. * @version V1.0.0
  6. * @date Apr-2013
  7. * @brief Main Interrupt Service Routines.
  8. * This file provides template for all exceptions handler and
  9. * peripherals interrupt service routine.
  10. ******************************************************************************
  11. * @attention
  12. *
  13. * <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>
  14. *
  15. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  16. * You may not use this file except in compliance with the License.
  17. * You may obtain a copy of the License at:
  18. *
  19. * http://www.st.com/software_license_agreement_liberty_v2
  20. *
  21. * Unless required by applicable law or agreed to in writing, software
  22. * distributed under the License is distributed on an "AS IS" BASIS,
  23. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  24. * See the License for the specific language governing permissions and
  25. * limitations under the License.
  26. *
  27. ******************************************************************************
  28. */
  29. /* Includes ------------------------------------------------------------------*/
  30. #include "stm32f4xx_it.h"
  31. #include "ucos_ii.h"
  32. //#include "stm32f4xx_STLlib.h"
  33. //#include "stm32f4xx_STLclassBvar.h"
  34. #if defined STL_EVAL_MODE
  35. #if defined (USE_STM324xG_EVAL)
  36. #include "stm324xg_eval.h"
  37. #else /* USE_STM324x7I_EVAL */
  38. #include "stm324x7i_eval.h"
  39. #endif
  40. #endif /* STL_EVAL_MODE */
  41. #ifdef STL_VERBOSE
  42. #include <stdio.h>
  43. #endif /* STL_VERBOSE */
  44. /** @addtogroup STM32F4xx_IEC60335_Example
  45. * @{
  46. */
  47. /* Private typedef -----------------------------------------------------------*/
  48. /* Private define ------------------------------------------------------------*/
  49. /* Private macro -------------------------------------------------------------*/
  50. /* Private variables ---------------------------------------------------------*/
  51. uint32_t tmpCC4_last; /* keep last TIM5/Chn4 captured value */
  52. /* Private function prototypes -----------------------------------------------*/
  53. /* Private functions ---------------------------------------------------------*/
  54. /******************************************************************************/
  55. /* Cortex-M4 Processor Exceptions Handlers */
  56. /******************************************************************************/
  57. /**
  58. * @brief This function handles NMI exception.
  59. * @param : None
  60. * @retval : None
  61. */
  62. void NMI_Handler(void)
  63. {
  64. #ifdef STL_VERBOSE
  65. if (RCC_GetITStatus(RCC_IT_CSS) == SET)
  66. {
  67. while(USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TC) == RESET)
  68. { /* Wait previous transmission completion */
  69. }
  70. /* Re-configure USART baud rate to have 115200 bds with HSI clock (8MHz) */
  71. EVAL_COM1->BRR = 0x45u;
  72. printf("\n\r Clock Source failure (Clock Security System)\n\r");
  73. }
  74. else
  75. {
  76. printf("\n\r NMI Exception\n\r");
  77. }
  78. #endif /* STL_VERBOSE */
  79. /* Go to infinite loop when NMI Exception occurs */
  80. while (1)
  81. {
  82. }
  83. }
  84. /******************************************************************************/
  85. /**
  86. * @brief This function handles Hard Fault exception.
  87. * @param : None
  88. * @retval : None
  89. */
  90. void HardFault_Handler(void)
  91. {
  92. #ifdef STL_VERBOSE
  93. printf("\n\r Hard fault Exception \n\r");
  94. #endif /* STL_VERBOSE */
  95. /* Go to infinite loop when Hard Fault exception occurs */
  96. while (1)
  97. {
  98. }
  99. }
  100. /******************************************************************************/
  101. /**
  102. * @brief This function handles Memory Manage exception.
  103. * @param : None
  104. * @retval : None
  105. */
  106. void MemManage_Handler(void)
  107. {
  108. #ifdef STL_VERBOSE
  109. printf("\n\r Mem manage Exception \n\r");
  110. #endif /* STL_VERBOSE */
  111. /* Go to infinite loop when Memory Manage exception occurs */
  112. while (1)
  113. {
  114. }
  115. }
  116. /******************************************************************************/
  117. /**
  118. * @brief This function handles Bus Fault exception.
  119. * @param : None
  120. * @retval : None
  121. */
  122. void BusFault_Handler(void)
  123. {
  124. #ifdef STL_VERBOSE
  125. printf("\n\r Bus fault Exception \n\r");
  126. #endif /* STL_VERBOSE */
  127. /* Go to infinite loop when Bus Fault exception occurs */
  128. while (1)
  129. {
  130. }
  131. }
  132. /******************************************************************************/
  133. /**
  134. * @brief This function handles Usage Fault exception.
  135. * @param : None
  136. * @retval : None
  137. */
  138. void UsageFault_Handler(void)
  139. {
  140. #ifdef STL_VERBOSE
  141. printf("\n\r Usage fault Exception \n\r");
  142. #endif /* STL_VERBOSE */
  143. /* Go to infinite loop when Usage Fault exception occurs */
  144. while (1)
  145. {
  146. }
  147. }
  148. /******************************************************************************/
  149. /**
  150. * @brief This function handles SVCall exception.
  151. * @param : None
  152. * @retval : None
  153. */
  154. void SVC_Handler(void)
  155. {
  156. #ifdef STL_VERBOSE
  157. printf("\n\r SVCall Exception \n\r");
  158. #endif /* STL_VERBOSE */
  159. }
  160. /******************************************************************************/
  161. /**
  162. * @brief This function handles Debug Monitor exception.
  163. * @param : None
  164. * @retval : None
  165. */
  166. void DebugMon_Handler(void)
  167. {
  168. #ifdef STL_VERBOSE
  169. printf("\n\r Debug Monitor Exception \n\r");
  170. #endif /* STL_VERBOSE */
  171. }
  172. /******************************************************************************/
  173. /**
  174. * @brief This function handles PendSVC exception.
  175. * @param : None
  176. * @retval : None
  177. */
  178. void PendSV_Handler(void)
  179. {
  180. #ifdef STL_VERBOSE
  181. printf("\n\r PendSVC Exception \n\r");
  182. #endif /* STL_VERBOSE */
  183. }
  184. /******************************************************************************/
  185. /**
  186. * @brief This function handles SysTick Handler.
  187. * @param : None
  188. * @retval : None
  189. */
  190. void SysTick_Handler(void)
  191. {
  192. // #if defined STL_EVAL_MODE
  193. // /* Toggle LED2 for debug purposes */
  194. // STM_EVAL_LEDToggle(LED2);
  195. // #endif /* STL_EVAL_MODE */
  196. OSIntEnter();
  197. OSTimeTick();
  198. OSIntExit();
  199. // /* Verify TickCounter integrity */
  200. // if ((TickCounter ^ TickCounterInv) == 0xFFFFFFFFuL)
  201. // {
  202. // TickCounter++;
  203. // TickCounterInv = ~TickCounter;
  204. //
  205. // if (TickCounter >= SYSTICK_10ms_TB)
  206. // {
  207. // uint32_t RamTestResult;
  208. //
  209. // /* Reset timebase counter */
  210. // TickCounter = 0u;
  211. // TickCounterInv = 0xFFFFFFFF;
  212. //
  213. // /* Set Flag read in main loop */
  214. // TimeBaseFlag = 0xAAAAAAAAu;
  215. // TimeBaseFlagInv = 0x55555555u;
  216. //
  217. // #ifndef USE_MARCHX_RAM_TEST
  218. // ISRCtrlFlowCnt += RAM_MARCHC_ISR_CALLER;
  219. // RamTestResult = STL_TranspMarchC();
  220. // ISRCtrlFlowCntInv -= RAM_MARCHC_ISR_CALLER;
  221. // #else
  222. // ISRCtrlFlowCnt += RAM_MARCHX_ISR_CALLER;
  223. // RamTestResult = STL_TranspMarchX();
  224. // ISRCtrlFlowCntInv -= RAM_MARCHX_ISR_CALLER;
  225. // #endif /* USE_MARCHX_RAM_TEST */
  226. //
  227. // switch ( RamTestResult )
  228. // {
  229. // case TEST_RUNNING:
  230. // break;
  231. // case TEST_OK:
  232. // #ifdef STL_VERBOSE
  233. // /* avoid any long string output here in the interrupt, '#' marks ram test completed ok */
  234. // putchar((int)'#');
  235. // #endif /* STL_VERBOSE */
  236. // #ifdef STL_EVAL_MODE
  237. // /* Toggle LED2 for debug purposes */
  238. // STM_EVAL_LEDToggle(LED2);
  239. // #endif /* STL_EVAL_MODE */
  240. // break;
  241. // case TEST_FAILURE:
  242. // case CLASS_B_DATA_FAIL:
  243. // default:
  244. // #ifdef STL_VERBOSE
  245. // printf("\n\r >>>>>>>>>>>>>>>>>>> RAM Error (March C- Run-time check)\n\r");
  246. // #endif /* STL_VERBOSE */
  247. // FailSafePOR();
  248. // break;
  249. // } /* End of the switch */
  250. //
  251. // /* Do we reached the end of RAM test? */
  252. // /* Verify 1st ISRCtrlFlowCnt integrity */
  253. // if ((ISRCtrlFlowCnt ^ ISRCtrlFlowCntInv) == 0xFFFFFFFFuL)
  254. // {
  255. // if (RamTestResult == TEST_OK)
  256. // {
  257. // /* ==============================================================================*/
  258. // /* MISRA violation of rule 17.4 - pointer arithmetic is used to check RAM test control flow */
  259. // #ifdef __IAR_SYSTEMS_ICC__ /* IAR Compiler */
  260. // #pragma diag_suppress=Pm088
  261. // #endif /* __IAR_SYSTEMS_ICC__ */
  262. // if (ISRCtrlFlowCnt != RAM_TEST_COMPLETED)
  263. // #ifdef __IAR_SYSTEMS_ICC__ /* IAR Compiler */
  264. // #pragma diag_default=Pm088
  265. // #endif /* __IAR_SYSTEMS_ICC__ */
  266. // /* ==============================================================================*/
  267. // {
  268. // #ifdef STL_VERBOSE
  269. // printf("\n\r Control Flow error (RAM test) \n\r");
  270. // #endif /* STL_VERBOSE */
  271. // FailSafePOR();
  272. // }
  273. // else /* Full RAM was scanned */
  274. // {
  275. // ISRCtrlFlowCnt = 0u;
  276. // ISRCtrlFlowCntInv = 0xFFFFFFFF;
  277. // }
  278. // } /* End of RAM completed if*/
  279. // } /* End of control flow monitoring */
  280. // else
  281. // {
  282. // #ifdef STL_VERBOSE
  283. // printf("\n\r Control Flow error in ISR \n\r");
  284. // #endif /* STL_VERBOSE */
  285. // FailSafePOR();
  286. // }
  287. // } /* End of the 10 ms timebase interrupt */
  288. // }
  289. // else /* Class B variable TickCounter integrity error */
  290. // {
  291. // #ifdef STL_VERBOSE
  292. // printf("\n\r Class B Error on TickCounter\n\r");
  293. // #endif /* STL_VERBOSE */
  294. // FailSafePOR();
  295. // }
  296. //
  297. // #if defined STL_EVAL_MODE
  298. // /* Toggle LED2 for debug purposes */
  299. // STM_EVAL_LEDToggle(LED2);
  300. // #endif /* STL_EVAL_MODE */
  301. }
  302. /******************************************************************************/
  303. /**
  304. * @brief This function handles TIM5 global interrupt request.
  305. * @param : None
  306. * @retval : None
  307. */
  308. //void TIM5_IRQHandler(void)
  309. //{
  310. // uint32_t tmpCC4_last_cpy;
  311. //
  312. // if ((TIM5->SR & TIM_SR_CC4IF) != 0u )
  313. // {
  314. // /* store previous captured value */
  315. // tmpCC4_last_cpy = tmpCC4_last;
  316. // /* get currently captured value */
  317. // tmpCC4_last = TIM5->CCR4;
  318. // /* The CC4IF flag is already cleared here be reading CCR4 register */
  319. //
  320. // /* overight results only in case the data is required */
  321. // if (LSIPeriodFlag == 0u)
  322. // {
  323. // /* take correct measurement only */
  324. // if ((TIM5->SR & TIM_SR_CC4OF) == 0u)
  325. // {
  326. // /* Compute period length */
  327. // PeriodValue = tmpCC4_last - tmpCC4_last_cpy;
  328. // PeriodValueInv = ~PeriodValue;
  329. //
  330. // /* Set Flag tested at main loop */
  331. // LSIPeriodFlag = 0xAAAAAAAAu;
  332. // LSIPeriodFlagInv = 0x55555555u;
  333. // }
  334. // else
  335. // {
  336. // /* ignore computation in case of IC overflow */
  337. // TIM5->SR &= (uint16_t)(~TIM_SR_CC4OF);
  338. // }
  339. // /* ignore computation in case data is not required */
  340. // }
  341. // }
  342. //}
  343. /**
  344. * @}
  345. */
  346. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/