stm32g0xx_it.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /**
  2. ******************************************************************************
  3. * @file stm32g0xx_it.c
  4. * @brief Interrupt Service Routines.
  5. ******************************************************************************
  6. * @attention
  7. *
  8. * <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
  9. * All rights reserved.</center></h2>
  10. *
  11. * This software component is licensed by ST under BSD 3-Clause license,
  12. * the "License"; You may not use this file except in compliance with the
  13. * License. You may obtain a copy of the License at:
  14. * opensource.org/licenses/BSD-3-Clause
  15. *
  16. ******************************************************************************
  17. */
  18. /* Includes ------------------------------------------------------------------*/
  19. #include "main.h"
  20. #include "stm32g0xx_it.h"
  21. /* Private includes ----------------------------------------------------------*/
  22. /* Private typedef -----------------------------------------------------------*/
  23. /* Private define ------------------------------------------------------------*/
  24. /* Private macro -------------------------------------------------------------*/
  25. /* Private variables ---------------------------------------------------------*/
  26. /* Private function prototypes -----------------------------------------------*/
  27. /* Private user code ---------------------------------------------------------*/
  28. /* External variables --------------------------------------------------------*/
  29. /******************************************************************************/
  30. /* Cortex-M0+ Processor Interruption and Exception Handlers */
  31. /******************************************************************************/
  32. /**
  33. * @brief This function handles Non maskable interrupt.
  34. */
  35. void NMI_Handler(void)
  36. {
  37. while (1)
  38. {
  39. }
  40. }
  41. /**
  42. * @brief This function handles Hard fault interrupt.
  43. */
  44. void HardFault_Handler(void)
  45. {
  46. // tube power off
  47. GPIOA->BSRR = 0x10;
  48. // red led
  49. TIM1->CCR2 = 0xff; TIM1->CCR3 = 0; TIM1->CCR4 = 0;
  50. /* https://habr.com/ru/post/511924/ */
  51. struct
  52. {
  53. uint32_t r0;
  54. uint32_t r1;
  55. uint32_t r2;
  56. uint32_t r3;
  57. uint32_t r12;
  58. uint32_t lr;
  59. uint32_t pc;
  60. uint32_t psr;
  61. } * stack_ptr; //Указатель на текущее значение стека(SP)
  62. asm (
  63. "TST lr, #4 \n" //Тестируем 3-й бит указателя стека (побитовое И)
  64. "ITE EQ \n" //Значение указателя стека имеет бит 3?
  65. "MRSEQ %[ptr], MSP \n" //Да, сохраняем основной указатель стека
  66. "MRSNE %[ptr], PSP \n" //Нет, сохраняем указатель стека процесса
  67. : [ptr] "=r" (stack_ptr)
  68. );
  69. // there plase break-point...
  70. while (1)
  71. {
  72. }
  73. }
  74. /**
  75. * @brief This function handles System service call via SWI instruction.
  76. */
  77. void SVC_Handler(void)
  78. {
  79. }
  80. /**
  81. * @brief This function handles Pendable request for system service.
  82. */
  83. void PendSV_Handler(void)
  84. {
  85. }
  86. /******************************************************************************/
  87. /* STM32G0xx Peripheral Interrupt Handlers */
  88. /* Add here the Interrupt Handlers for the used peripherals. */
  89. /* For the available peripheral interrupt handler names, */
  90. /* please refer to the startup file (startup_stm32g0xx.s). */
  91. /******************************************************************************/
  92. /**
  93. * @brief This function handles EXTI line 4 to 15 interrupts.
  94. */
  95. void EXTI4_15_IRQHandler(void)
  96. {
  97. if ((EXTI->FPR1 & EXTI_IMR1_IM14) != 0)
  98. {
  99. EXTI->FPR1 = EXTI_IMR1_IM14;
  100. Flag.RTC_IRQ = 1;
  101. ES_PlaceEvent(evNewSecond);
  102. }
  103. }
  104. /**
  105. * @brief This function handles DMA1 channel 1 interrupt.
  106. */
  107. void DMA1_Channel1_IRQHandler(void)
  108. {
  109. if ((DMA1->ISR & DMA_IFCR_CTCIF1) != 0) {
  110. DMA1->IFCR |= DMA_IFCR_CTCIF1; // reset IRQ flag
  111. Flag.SPI_TX_End = 1;
  112. /* Stop SPI-DMA transfer */
  113. DMA1_Channel1->CCR &= ~DMA_CCR_EN;
  114. /* Wait for end SPI transmit */
  115. LATCH_DOWN;
  116. while ((SPI1->SR & SPI_SR_FTLVL) != 0) {};
  117. while ((SPI1->SR & SPI_SR_BSY) != 0) {};
  118. LATCH_UP;
  119. }
  120. }
  121. /**
  122. * @brief This function handles DMA1 channel 2 and channel 3 interrupts.
  123. */
  124. void DMA1_Channel2_3_IRQHandler(void)
  125. {
  126. if ((DMA1->ISR & DMA_ISR_TCIF2) != 0) {
  127. /* reset IRQ flag */
  128. DMA1->IFCR |= DMA_IFCR_CTCIF2;
  129. /* Disable DMA channels for I2C RX */
  130. DMA1_Channel2->CCR &= ~DMA_CCR_EN;
  131. Flag.I2C_RX_End = 1;
  132. }
  133. if ((DMA1->ISR & DMA_ISR_TEIF2) != 0) {
  134. DMA1->IFCR |= DMA_IFCR_CTEIF2;
  135. DMA1_Channel2->CCR &= ~DMA_CCR_EN;
  136. Flag.I2C_RX_End = 1;
  137. Flag.I2C_RX_Err = 1;
  138. }
  139. if ((DMA1->ISR & DMA_ISR_TCIF3) != 0) {
  140. /* reset IRQ flag */
  141. DMA1->IFCR |= DMA_IFCR_CTCIF3;
  142. /* Disable DMA channels for I2C TX */
  143. DMA1_Channel3->CCR &= ~DMA_CCR_EN;
  144. Flag.I2C_TX_End = 1;
  145. }
  146. if ((DMA1->ISR & DMA_ISR_TEIF3) != 0) {
  147. DMA1->IFCR |= DMA_IFCR_CTEIF3;
  148. DMA1_Channel3->CCR &= ~DMA_CCR_EN;
  149. Flag.I2C_TX_End = 1;
  150. Flag.I2C_TX_Err = 1;
  151. }
  152. }
  153. /**
  154. * @brief This function handles TIM14 global interrupt.
  155. */
  156. void TIM14_IRQHandler(void)
  157. {
  158. if ((TIM14->SR & TIM_SR_UIF) != 0) {
  159. /* Update interrupt flag */
  160. TIM14->SR |= TIM_SR_UIF;
  161. }
  162. if ((TIM14->SR & TIM_SR_CC1IF) != 0) {
  163. /* Capture/Compare Interrupt */
  164. TIM14->SR |= TIM_SR_CC1IF;
  165. /* disable unneeded channel */
  166. /*
  167. if (Flag.Blink_1 != 0) {
  168. TUBE_A_OFF;
  169. }
  170. if (Flag.Blink_2 != 0) {
  171. TUBE_B_OFF;
  172. }
  173. if (Flag.Blink_3 != 0) {
  174. TUBE_C_OFF;
  175. }
  176. if (Flag.Blink_4 != 0) {
  177. TUBE_D_OFF;
  178. }
  179. if (Flag.Blink_5 != 0) {
  180. TUBE_E_OFF;
  181. }
  182. */
  183. }
  184. }
  185. /**
  186. * @brief This function handles TIM16 global interrupt.
  187. */
  188. void TIM16_IRQHandler(void)
  189. {
  190. if ((TIM16->SR & TIM_SR_UIF) != 0) {
  191. /* Update interrupt flag */
  192. TIM16->SR |= TIM_SR_UIF;
  193. }
  194. }
  195. /**
  196. * @brief This function handles TIM17 global interrupt.
  197. */
  198. void TIM17_IRQHandler(void)
  199. {
  200. if ((TIM17->SR & TIM_SR_UIF) != 0) {
  201. /* Update interrupt flag */
  202. TIM17->SR |= TIM_SR_UIF;
  203. }
  204. }
  205. /**
  206. * @brief This function handles SPI1 global interrupt.
  207. */
  208. void SPI1_IRQHandler(void)
  209. {
  210. }
  211. /**
  212. * @brief This function handles USART1 global interrupt / USART1 wake-up interrupt through EXTI line 25.
  213. */
  214. void USART1_IRQHandler(void)
  215. {
  216. }
  217. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/