stm32f4xx_hal_msp.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * File Name : stm32f4xx_hal_msp.c
  5. * Description : This file provides code for the MSP Initialization
  6. * and de-Initialization codes.
  7. ******************************************************************************
  8. ** This notice applies to any and all portions of this file
  9. * that are not between comment pairs USER CODE BEGIN and
  10. * USER CODE END. Other portions of this file, whether
  11. * inserted by the user or by software development tools
  12. * are owned by their respective copyright owners.
  13. *
  14. * COPYRIGHT(c) 2018 STMicroelectronics
  15. *
  16. * Redistribution and use in source and binary forms, with or without modification,
  17. * are permitted provided that the following conditions are met:
  18. * 1. Redistributions of source code must retain the above copyright notice,
  19. * this list of conditions and the following disclaimer.
  20. * 2. Redistributions in binary form must reproduce the above copyright notice,
  21. * this list of conditions and the following disclaimer in the documentation
  22. * and/or other materials provided with the distribution.
  23. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  24. * may be used to endorse or promote products derived from this software
  25. * without specific prior written permission.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  28. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  29. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  30. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  31. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  32. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  33. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  34. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  35. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  36. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  37. *
  38. ******************************************************************************
  39. */
  40. /* USER CODE END Header */
  41. /* Includes ------------------------------------------------------------------*/
  42. #include "main.h"
  43. /* USER CODE BEGIN Includes */
  44. /* USER CODE END Includes */
  45. /* Private typedef -----------------------------------------------------------*/
  46. /* USER CODE BEGIN TD */
  47. /* USER CODE END TD */
  48. /* Private define ------------------------------------------------------------*/
  49. /* USER CODE BEGIN Define */
  50. /* USER CODE END Define */
  51. /* Private macro -------------------------------------------------------------*/
  52. /* USER CODE BEGIN Macro */
  53. /* USER CODE END Macro */
  54. /* Private variables ---------------------------------------------------------*/
  55. /* USER CODE BEGIN PV */
  56. /* USER CODE END PV */
  57. /* Private function prototypes -----------------------------------------------*/
  58. /* USER CODE BEGIN PFP */
  59. /* USER CODE END PFP */
  60. /* External functions --------------------------------------------------------*/
  61. /* USER CODE BEGIN ExternalFunctions */
  62. /* USER CODE END ExternalFunctions */
  63. /* USER CODE BEGIN 0 */
  64. /* USER CODE END 0 */
  65. void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);
  66. /**
  67. * Initializes the Global MSP.
  68. */
  69. void HAL_MspInit(void)
  70. {
  71. /* USER CODE BEGIN MspInit 0 */
  72. /* USER CODE END MspInit 0 */
  73. __HAL_RCC_SYSCFG_CLK_ENABLE();
  74. __HAL_RCC_PWR_CLK_ENABLE();
  75. HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_0);
  76. /* System interrupt init*/
  77. /* USER CODE BEGIN MspInit 1 */
  78. /* USER CODE END MspInit 1 */
  79. }
  80. /**
  81. * @brief TIM_Base MSP Initialization
  82. * This function configures the hardware resources used in this example
  83. * @param htim_base: TIM_Base handle pointer
  84. * @retval None
  85. */
  86. void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
  87. {
  88. if(htim_base->Instance==TIM3)
  89. {
  90. /* USER CODE BEGIN TIM3_MspInit 0 */
  91. /* USER CODE END TIM3_MspInit 0 */
  92. /* Peripheral clock enable */
  93. __HAL_RCC_TIM3_CLK_ENABLE();
  94. /* USER CODE BEGIN TIM3_MspInit 1 */
  95. /* USER CODE END TIM3_MspInit 1 */
  96. }
  97. }
  98. void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
  99. {
  100. GPIO_InitTypeDef GPIO_InitStruct = {0};
  101. if(htim->Instance==TIM3)
  102. {
  103. /* USER CODE BEGIN TIM3_MspPostInit 0 */
  104. /* USER CODE END TIM3_MspPostInit 0 */
  105. __HAL_RCC_GPIOA_CLK_ENABLE();
  106. __HAL_RCC_GPIOB_CLK_ENABLE();
  107. /**TIM3 GPIO Configuration
  108. PA6 ------> TIM3_CH1
  109. PA7 ------> TIM3_CH2
  110. PB0 ------> TIM3_CH3
  111. PB1 ------> TIM3_CH4
  112. */
  113. GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
  114. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  115. GPIO_InitStruct.Pull = GPIO_NOPULL;
  116. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  117. GPIO_InitStruct.Alternate = GPIO_AF2_TIM3;
  118. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  119. GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1;
  120. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  121. GPIO_InitStruct.Pull = GPIO_NOPULL;
  122. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  123. GPIO_InitStruct.Alternate = GPIO_AF2_TIM3;
  124. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  125. /* USER CODE BEGIN TIM3_MspPostInit 1 */
  126. /* USER CODE END TIM3_MspPostInit 1 */
  127. }
  128. }
  129. /**
  130. * @brief TIM_Base MSP De-Initialization
  131. * This function freeze the hardware resources used in this example
  132. * @param htim_base: TIM_Base handle pointer
  133. * @retval None
  134. */
  135. void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
  136. {
  137. if(htim_base->Instance==TIM3)
  138. {
  139. /* USER CODE BEGIN TIM3_MspDeInit 0 */
  140. /* USER CODE END TIM3_MspDeInit 0 */
  141. /* Peripheral clock disable */
  142. __HAL_RCC_TIM3_CLK_DISABLE();
  143. /* USER CODE BEGIN TIM3_MspDeInit 1 */
  144. /* USER CODE END TIM3_MspDeInit 1 */
  145. }
  146. }
  147. /**
  148. * @brief UART MSP Initialization
  149. * This function configures the hardware resources used in this example
  150. * @param huart: UART handle pointer
  151. * @retval None
  152. */
  153. void HAL_UART_MspInit(UART_HandleTypeDef* huart)
  154. {
  155. GPIO_InitTypeDef GPIO_InitStruct = {0};
  156. if(huart->Instance==USART2)
  157. {
  158. /* USER CODE BEGIN USART2_MspInit 0 */
  159. /* USER CODE END USART2_MspInit 0 */
  160. /* Peripheral clock enable */
  161. __HAL_RCC_USART2_CLK_ENABLE();
  162. __HAL_RCC_GPIOA_CLK_ENABLE();
  163. /**USART2 GPIO Configuration
  164. PA2 ------> USART2_TX
  165. PA3 ------> USART2_RX
  166. */
  167. GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3;
  168. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  169. GPIO_InitStruct.Pull = GPIO_PULLUP;
  170. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  171. GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
  172. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  173. /* USER CODE BEGIN USART2_MspInit 1 */
  174. /* USER CODE END USART2_MspInit 1 */
  175. }
  176. }
  177. /**
  178. * @brief UART MSP De-Initialization
  179. * This function freeze the hardware resources used in this example
  180. * @param huart: UART handle pointer
  181. * @retval None
  182. */
  183. void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
  184. {
  185. if(huart->Instance==USART2)
  186. {
  187. /* USER CODE BEGIN USART2_MspDeInit 0 */
  188. /* USER CODE END USART2_MspDeInit 0 */
  189. /* Peripheral clock disable */
  190. __HAL_RCC_USART2_CLK_DISABLE();
  191. /**USART2 GPIO Configuration
  192. PA2 ------> USART2_TX
  193. PA3 ------> USART2_RX
  194. */
  195. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3);
  196. /* USER CODE BEGIN USART2_MspDeInit 1 */
  197. /* USER CODE END USART2_MspDeInit 1 */
  198. }
  199. }
  200. /* USER CODE BEGIN 1 */
  201. /* USER CODE END 1 */
  202. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/