stm32g0xx_it.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. TIM1->CCER &= ~(TIM_CCER_CC1E);
  48. TIM3->CCER &= ~(TIM_CCER_CC4E);
  49. TIM3->CCER &= ~(TIM_CCER_CC3E);
  50. TIM3->CCER &= ~(TIM_CCER_CC2E);
  51. TIM3->CCER &= ~(TIM_CCER_CC1E);
  52. GPIOA->BSRR = 0x10;
  53. // red led
  54. TIM1->CCR2 = 0xff; TIM1->CCR3 = 0; TIM1->CCR4 = 0;
  55. while (1)
  56. {
  57. }
  58. }
  59. /**
  60. * @brief This function handles System service call via SWI instruction.
  61. */
  62. void SVC_Handler(void)
  63. {
  64. }
  65. /**
  66. * @brief This function handles Pendable request for system service.
  67. */
  68. void PendSV_Handler(void)
  69. {
  70. }
  71. /******************************************************************************/
  72. /* STM32G0xx Peripheral Interrupt Handlers */
  73. /* Add here the Interrupt Handlers for the used peripherals. */
  74. /* For the available peripheral interrupt handler names, */
  75. /* please refer to the startup file (startup_stm32g0xx.s). */
  76. /******************************************************************************/
  77. /**
  78. * @brief This function handles EXTI line 4 to 15 interrupts.
  79. */
  80. void EXTI4_15_IRQHandler(void)
  81. {
  82. if ((EXTI->FPR1 & EXTI_IMR1_IM14) != 0)
  83. {
  84. EXTI->FPR1 = EXTI_IMR1_IM14;
  85. Flag.RTC_IRQ = 1;
  86. ES_PlaceEvent(evNewSecond);
  87. }
  88. }
  89. /**
  90. * @brief This function handles DMA1 channel 1 interrupt.
  91. */
  92. void DMA1_Channel1_IRQHandler(void)
  93. {
  94. if ((DMA1->ISR & DMA_IFCR_CTCIF1) != 0) {
  95. DMA1->IFCR |= DMA_IFCR_CTCIF1; // reset IRQ flag
  96. Flag.SPI_TX_End = 1;
  97. /* Stop SPI-DMA transfer */
  98. DMA1_Channel1->CCR &= ~DMA_CCR_EN;
  99. /* Wait for end SPI transmit */
  100. LATCH_DOWN;
  101. while ((SPI1->SR & SPI_SR_FTLVL) != 0);
  102. while ((SPI1->SR & SPI_SR_BSY) != 0);
  103. LATCH_UP;
  104. }
  105. }
  106. /**
  107. * @brief This function handles DMA1 channel 2 and channel 3 interrupts.
  108. */
  109. void DMA1_Channel2_3_IRQHandler(void)
  110. {
  111. if ((DMA1->ISR & DMA_ISR_TCIF2) != 0) {
  112. /* reset IRQ flag */
  113. DMA1->IFCR |= DMA_IFCR_CTCIF2;
  114. /* Disable DMA channels for I2C RX */
  115. DMA1_Channel2->CCR &= ~DMA_CCR_EN;
  116. Flag.I2C_RX_End = 1;
  117. }
  118. if ((DMA1->ISR & DMA_ISR_TEIF2) != 0) {
  119. DMA1->IFCR |= DMA_IFCR_CTEIF2;
  120. DMA1_Channel2->CCR &= ~DMA_CCR_EN;
  121. Flag.I2C_RX_End = 1;
  122. Flag.I2C_RX_Err = 1;
  123. }
  124. if ((DMA1->ISR & DMA_ISR_TCIF3) != 0) {
  125. /* reset IRQ flag */
  126. DMA1->IFCR |= DMA_IFCR_CTCIF3;
  127. /* Disable DMA channels for I2C TX */
  128. DMA1_Channel3->CCR &= ~DMA_CCR_EN;
  129. Flag.I2C_TX_End = 1;
  130. }
  131. if ((DMA1->ISR & DMA_ISR_TEIF3) != 0) {
  132. DMA1->IFCR |= DMA_IFCR_CTEIF3;
  133. DMA1_Channel3->CCR &= ~DMA_CCR_EN;
  134. Flag.I2C_TX_End = 1;
  135. Flag.I2C_TX_Err = 1;
  136. }
  137. }
  138. /**
  139. * @brief This function handles TIM14 global interrupt.
  140. */
  141. void TIM14_IRQHandler(void)
  142. {
  143. if ((TIM14->SR & TIM_SR_UIF) != 0) {
  144. /* Update interrupt flag */
  145. TIM14->SR &= ~TIM_SR_UIF;
  146. /* enable channels */
  147. if (Flag.Blink_1 != 0) {
  148. TUBE_A_ON;
  149. }
  150. if (Flag.Blink_2 != 0) {
  151. TUBE_B_ON;
  152. }
  153. if (Flag.Blink_3 != 0) {
  154. TUBE_C_ON;
  155. }
  156. if (Flag.Blink_4 != 0) {
  157. TUBE_D_ON;
  158. }
  159. if (Flag.Blink_5 != 0) {
  160. TUBE_E_ON;
  161. }
  162. }
  163. if ((TIM14->SR & TIM_SR_CC1IF) != 0) {
  164. /* Capture/Compare Interrupt flag */
  165. TIM14->SR &= ~TIM_SR_CC1IF;
  166. /* disable unneeded channel */
  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. * @brief This function handles TIM16 global interrupt.
  186. */
  187. #define STOP_FADE_TIME 20
  188. void TIM16_IRQHandler(void)
  189. {
  190. /* Clear interrupt flag */
  191. if ((TIM16->SR & TIM_SR_UIF) != 0) {
  192. TIM16->SR = 0;
  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 = 0;
  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****/