stm32f4xx_it.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /**
  2. ******************************************************************************
  3. * @file Project/STM32F4xx_StdPeriph_Templates/stm32f4xx_it.c
  4. * @author MCD Application Team
  5. * @version V1.5.0
  6. * @date 06-March-2015
  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 2015 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 "usart.h"
  32. /* Scheduler includes */
  33. #include "FreeRTOS.h"
  34. #include "task.h"
  35. #include "queue.h"
  36. #include "semphr.h"
  37. extern SemaphoreHandle_t s_xSemaphore;
  38. /* We can use Web only with libc stdio (PRINTF=stdlib) */
  39. #include "stm32f4x7_eth.h"
  40. /* lwip includes */
  41. #include "lwip/sys.h"
  42. #ifdef PRINTF_STDLIB
  43. #include <stdio.h>
  44. #endif
  45. #ifdef PRINTF_CUSTOM
  46. #include "tinystdio.h"
  47. #endif
  48. /** @addtogroup Template_Project
  49. * @{
  50. */
  51. /* Private typedef -----------------------------------------------------------*/
  52. /* Private define ------------------------------------------------------------*/
  53. /* Private macro -------------------------------------------------------------*/
  54. /* Private variables ---------------------------------------------------------*/
  55. /* Private function prototypes -----------------------------------------------*/
  56. /* Private functions ---------------------------------------------------------*/
  57. /******************************************************************************/
  58. /* Cortex-M4 Processor Exceptions Handlers */
  59. /******************************************************************************/
  60. /**
  61. * @brief This function handles NMI exception.
  62. * @param None
  63. * @retval None
  64. */
  65. void NMI_Handler(void)
  66. {
  67. }
  68. void **HARDFAULT_PSP;
  69. register void *stack_pointer asm("sp");
  70. void HardFault_Output(uint32_t *sp)
  71. {
  72. // Hijack the process stack pointer to make backtrace work
  73. asm("mrs %0, psp" : "=r"(HARDFAULT_PSP) : :);
  74. stack_pointer = HARDFAULT_PSP;
  75. // call our debugger
  76. asm("bkpt #0");
  77. uint32_t r0 = sp[0];
  78. uint32_t r1 = sp[1];
  79. uint32_t r2 = sp[2];
  80. uint32_t r3 = sp[3];
  81. uint32_t r12 = sp[4];
  82. uint32_t lr = sp[5];
  83. uint32_t pc = sp[6];
  84. uint32_t psr = sp[7];
  85. printf("HardFault:\n\r");
  86. /* Print CFSR register */
  87. /* Print CPU registers */
  88. printf("\n\rRegisters:\n\r");
  89. printf("SP 0x%08lx\n\r", (uint32_t)sp);
  90. printf("R0 0x%08lx\n\r", r0);
  91. printf("R1 0x%08lx\n\r", r1);
  92. printf("R2 0x%08lx\n\r", r2);
  93. printf("R3 0x%08lx\n\r", r3);
  94. printf("R12 0x%08lx\n\r", r12);
  95. printf("LR 0x%08lx\n\r", lr);
  96. printf("PC 0x%08lx\n\r", pc);
  97. printf("PSR 0x%08lx\n\r", psr);
  98. /* Go to infinite loop when Hard Fault exception occurs */
  99. while(1);
  100. }
  101. /**
  102. * @brief This function handles Hard Fault exception.
  103. * @param None
  104. * @retval None
  105. */
  106. #if defined ( __GNUC__ )
  107. __attribute__( (naked) )
  108. void HardFault_Handler(void)
  109. {
  110. __asm volatile
  111. (
  112. "tst lr, #4 \n"
  113. "ite eq \n"
  114. "mrseq r0, msp \n"
  115. "mrsne r0, psp \n"
  116. "ldr r1, debugHardfault_address \n"
  117. "bx r1 \n"
  118. "debugHardfault_address: .word HardFault_Output \n"
  119. );
  120. }
  121. #endif
  122. /**
  123. * @brief This function handles Memory Manage exception.
  124. * @param None
  125. * @retval None
  126. */
  127. void MemManage_Handler(void)
  128. {
  129. /* Go to infinite loop when Memory Manage exception occurs */
  130. while (1)
  131. {
  132. }
  133. }
  134. /*void TIM8_UP_TIM13_IRQHandler(void)
  135. {
  136. TIM_ClearITPendingBit(TIM13, TIM_IT_Update);
  137. }*/
  138. /**
  139. * @brief This function handles Bus Fault exception.
  140. * @param None
  141. * @retval None
  142. */
  143. void BusFault_Handler(void)
  144. {
  145. /* Go to infinite loop when Bus Fault exception occurs */
  146. while (1)
  147. {
  148. }
  149. }
  150. /**
  151. * @brief This function handles Usage Fault exception.
  152. * @param None
  153. * @retval None
  154. */
  155. void UsageFault_Handler(void)
  156. {
  157. /* Go to infinite loop when Usage Fault exception occurs */
  158. while (1)
  159. {
  160. }
  161. }
  162. /**
  163. * @brief This function handles SVCall exception.
  164. * @param None
  165. * @retval None
  166. */
  167. /*
  168. void SVC_Handler(void)
  169. {
  170. }
  171. */
  172. /**
  173. * @brief This function handles Debug Monitor exception.
  174. * @param None
  175. * @retval None
  176. */
  177. void DebugMon_Handler(void)
  178. {
  179. }
  180. /**
  181. * @brief This function handles PendSVC exception.
  182. * @param None
  183. * @retval None
  184. */
  185. /*void PendSV_Handler(void)
  186. {
  187. }
  188. */
  189. /**
  190. * @brief This function handles SysTick Handler.
  191. * @param None
  192. * @retval None
  193. */
  194. /*void SysTick_Handler(void)
  195. {
  196. TimingDelay_Decrement();
  197. }
  198. */
  199. /******************************************************************************/
  200. /* STM32F4xx Peripherals Interrupt Handlers */
  201. /* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */
  202. /* available peripheral interrupt handler's name please refer to the startup */
  203. /* file (startup_stm32f4xx.s). */
  204. /******************************************************************************/
  205. /**
  206. * @brief This function handles PPP interrupt request.
  207. * @param None
  208. * @retval None
  209. */
  210. /*void PPP_IRQHandler(void)
  211. {
  212. }*/
  213. void SDIO_IRQHandler(void)
  214. {
  215. /* Process All SDIO Interrupt Sources */
  216. // SD_ProcessIRQSrc();
  217. }
  218. /**
  219. * @brief This function handles DMA2 Stream3 or DMA2 Stream6 global interrupts
  220. * requests.
  221. * @param None
  222. * @retval None
  223. */
  224. void SD_SDIO_DMA_IRQHANDLER(void)
  225. {
  226. /* Process DMA2 Stream3 or DMA2 Stream6 Interrupt Sources */
  227. // SD_ProcessDMAIRQ();
  228. }
  229. //#ifdef OS_FREERTOS
  230. /**
  231. * @brief This function handles ethernet DMA interrupt request.
  232. * @param None
  233. * @retval None
  234. */
  235. void ETH_IRQHandler(void)
  236. {
  237. portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
  238. /* Frame received */
  239. if ( ETH_GetDMAFlagStatus(ETH_DMA_FLAG_R) == SET)
  240. {
  241. /* Give the semaphore to wakeup LwIP task */
  242. xSemaphoreGiveFromISR( s_xSemaphore, &xHigherPriorityTaskWoken );
  243. }
  244. /* Clear the interrupt flags. */
  245. /* Clear the Eth DMA Rx IT pending bits */
  246. ETH_DMAClearITPendingBit(ETH_DMA_IT_R);
  247. ETH_DMAClearITPendingBit(ETH_DMA_IT_NIS);
  248. // Switch tasks if necessary. */
  249. if( xHigherPriorityTaskWoken != pdFALSE )
  250. {
  251. portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );
  252. }
  253. }
  254. //#endif
  255. //#endif
  256. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/