stm32g0xx_hal_msp.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file stm32g0xx_hal_msp.c
  5. * @brief This file provides code for the MSP Initialization
  6. * and de-Initialization codes.
  7. ******************************************************************************
  8. * @attention
  9. *
  10. * Copyright (c) 2025 STMicroelectronics.
  11. * All rights reserved.
  12. *
  13. * This software is licensed under terms that can be found in the LICENSE file
  14. * in the root directory of this software component.
  15. * If no LICENSE file comes with this software, it is provided AS-IS.
  16. *
  17. ******************************************************************************
  18. */
  19. /* USER CODE END Header */
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "main.h"
  22. /* USER CODE BEGIN Includes */
  23. /* USER CODE END Includes */
  24. extern DMA_HandleTypeDef hdma_tim3_ch1;
  25. extern DMA_HandleTypeDef hdma_tim3_ch2;
  26. /* Private typedef -----------------------------------------------------------*/
  27. /* USER CODE BEGIN TD */
  28. /* USER CODE END TD */
  29. /* Private define ------------------------------------------------------------*/
  30. /* USER CODE BEGIN Define */
  31. /* USER CODE END Define */
  32. /* Private macro -------------------------------------------------------------*/
  33. /* USER CODE BEGIN Macro */
  34. /* USER CODE END Macro */
  35. /* Private variables ---------------------------------------------------------*/
  36. /* USER CODE BEGIN PV */
  37. /* USER CODE END PV */
  38. /* Private function prototypes -----------------------------------------------*/
  39. /* USER CODE BEGIN PFP */
  40. /* USER CODE END PFP */
  41. /* External functions --------------------------------------------------------*/
  42. /* USER CODE BEGIN ExternalFunctions */
  43. /* USER CODE END ExternalFunctions */
  44. /* USER CODE BEGIN 0 */
  45. /* USER CODE END 0 */
  46. /**
  47. * Initializes the Global MSP.
  48. */
  49. void HAL_MspInit(void)
  50. {
  51. /* USER CODE BEGIN MspInit 0 */
  52. /* USER CODE END MspInit 0 */
  53. __HAL_RCC_SYSCFG_CLK_ENABLE();
  54. __HAL_RCC_PWR_CLK_ENABLE();
  55. /* System interrupt init*/
  56. /* USER CODE BEGIN MspInit 1 */
  57. /* USER CODE END MspInit 1 */
  58. }
  59. /**
  60. * @brief TIM_Base MSP Initialization
  61. * This function configures the hardware resources used in this example
  62. * @param htim_base: TIM_Base handle pointer
  63. * @retval None
  64. */
  65. void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
  66. {
  67. GPIO_InitTypeDef GPIO_InitStruct = {0};
  68. if(htim_base->Instance==TIM3)
  69. {
  70. /* USER CODE BEGIN TIM3_MspInit 0 */
  71. /* USER CODE END TIM3_MspInit 0 */
  72. /* Peripheral clock enable */
  73. __HAL_RCC_TIM3_CLK_ENABLE();
  74. __HAL_RCC_GPIOA_CLK_ENABLE();
  75. /**TIM3 GPIO Configuration
  76. PA7 ------> TIM3_CH2
  77. */
  78. GPIO_InitStruct.Pin = PWM_DSHOT_INPUT_Pin;
  79. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  80. GPIO_InitStruct.Pull = GPIO_PULLDOWN;
  81. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  82. GPIO_InitStruct.Alternate = GPIO_AF1_TIM3;
  83. HAL_GPIO_Init(PWM_DSHOT_INPUT_GPIO_Port, &GPIO_InitStruct);
  84. /* TIM3 DMA Init */
  85. /* TIM3_CH1 Init */
  86. hdma_tim3_ch1.Instance = DMA1_Channel1;
  87. hdma_tim3_ch1.Init.Request = DMA_REQUEST_TIM3_CH1;
  88. hdma_tim3_ch1.Init.Direction = DMA_PERIPH_TO_MEMORY;
  89. hdma_tim3_ch1.Init.PeriphInc = DMA_PINC_DISABLE;
  90. hdma_tim3_ch1.Init.MemInc = DMA_MINC_ENABLE;
  91. hdma_tim3_ch1.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
  92. hdma_tim3_ch1.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
  93. hdma_tim3_ch1.Init.Mode = DMA_CIRCULAR;
  94. hdma_tim3_ch1.Init.Priority = DMA_PRIORITY_LOW;
  95. if (HAL_DMA_Init(&hdma_tim3_ch1) != HAL_OK)
  96. {
  97. Error_Handler();
  98. }
  99. __HAL_LINKDMA(htim_base,hdma[TIM_DMA_ID_CC1],hdma_tim3_ch1);
  100. /* TIM3_CH2 Init */
  101. hdma_tim3_ch2.Instance = DMA1_Channel2;
  102. hdma_tim3_ch2.Init.Request = DMA_REQUEST_TIM3_CH2;
  103. hdma_tim3_ch2.Init.Direction = DMA_PERIPH_TO_MEMORY;
  104. hdma_tim3_ch2.Init.PeriphInc = DMA_PINC_DISABLE;
  105. hdma_tim3_ch2.Init.MemInc = DMA_MINC_ENABLE;
  106. hdma_tim3_ch2.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
  107. hdma_tim3_ch2.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
  108. hdma_tim3_ch2.Init.Mode = DMA_CIRCULAR;
  109. hdma_tim3_ch2.Init.Priority = DMA_PRIORITY_LOW;
  110. if (HAL_DMA_Init(&hdma_tim3_ch2) != HAL_OK)
  111. {
  112. Error_Handler();
  113. }
  114. __HAL_LINKDMA(htim_base,hdma[TIM_DMA_ID_CC2],hdma_tim3_ch2);
  115. /* TIM3 interrupt Init */
  116. HAL_NVIC_SetPriority(TIM3_IRQn, 0, 0);
  117. HAL_NVIC_EnableIRQ(TIM3_IRQn);
  118. /* USER CODE BEGIN TIM3_MspInit 1 */
  119. /* USER CODE END TIM3_MspInit 1 */
  120. }
  121. }
  122. /**
  123. * @brief TIM_Base MSP De-Initialization
  124. * This function freeze the hardware resources used in this example
  125. * @param htim_base: TIM_Base handle pointer
  126. * @retval None
  127. */
  128. void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
  129. {
  130. if(htim_base->Instance==TIM3)
  131. {
  132. /* USER CODE BEGIN TIM3_MspDeInit 0 */
  133. /* USER CODE END TIM3_MspDeInit 0 */
  134. /* Peripheral clock disable */
  135. __HAL_RCC_TIM3_CLK_DISABLE();
  136. /**TIM3 GPIO Configuration
  137. PA7 ------> TIM3_CH2
  138. */
  139. HAL_GPIO_DeInit(PWM_DSHOT_INPUT_GPIO_Port, PWM_DSHOT_INPUT_Pin);
  140. /* TIM3 DMA DeInit */
  141. HAL_DMA_DeInit(htim_base->hdma[TIM_DMA_ID_CC1]);
  142. HAL_DMA_DeInit(htim_base->hdma[TIM_DMA_ID_CC2]);
  143. /* TIM3 interrupt DeInit */
  144. HAL_NVIC_DisableIRQ(TIM3_IRQn);
  145. /* USER CODE BEGIN TIM3_MspDeInit 1 */
  146. /* USER CODE END TIM3_MspDeInit 1 */
  147. }
  148. }
  149. /* USER CODE BEGIN 1 */
  150. /* USER CODE END 1 */