stm32f2xx_hal_msp.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * File Name : stm32f2xx_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) 2019 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. extern DMA_HandleTypeDef hdma_usart3_rx;
  46. extern DMA_HandleTypeDef hdma_usart3_tx;
  47. /* Private typedef -----------------------------------------------------------*/
  48. /* USER CODE BEGIN TD */
  49. /* USER CODE END TD */
  50. /* Private define ------------------------------------------------------------*/
  51. /* USER CODE BEGIN Define */
  52. /* USER CODE END Define */
  53. /* Private macro -------------------------------------------------------------*/
  54. /* USER CODE BEGIN Macro */
  55. /* USER CODE END Macro */
  56. /* Private variables ---------------------------------------------------------*/
  57. /* USER CODE BEGIN PV */
  58. /* USER CODE END PV */
  59. /* Private function prototypes -----------------------------------------------*/
  60. /* USER CODE BEGIN PFP */
  61. /* USER CODE END PFP */
  62. /* External functions --------------------------------------------------------*/
  63. /* USER CODE BEGIN ExternalFunctions */
  64. /* USER CODE END ExternalFunctions */
  65. /* USER CODE BEGIN 0 */
  66. /* USER CODE END 0 */
  67. /**
  68. * Initializes the Global MSP.
  69. */
  70. void HAL_MspInit(void)
  71. {
  72. /* USER CODE BEGIN MspInit 0 */
  73. /* USER CODE END MspInit 0 */
  74. __HAL_RCC_SYSCFG_CLK_ENABLE();
  75. __HAL_RCC_PWR_CLK_ENABLE();
  76. /* System interrupt init*/
  77. /* USER CODE BEGIN MspInit 1 */
  78. /* USER CODE END MspInit 1 */
  79. }
  80. /**
  81. * @brief I2C MSP Initialization
  82. * This function configures the hardware resources used in this example
  83. * @param hi2c: I2C handle pointer
  84. * @retval None
  85. */
  86. void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c)
  87. {
  88. GPIO_InitTypeDef GPIO_InitStruct = {0};
  89. if(hi2c->Instance==I2C3)
  90. {
  91. /* USER CODE BEGIN I2C3_MspInit 0 */
  92. /* USER CODE END I2C3_MspInit 0 */
  93. __HAL_RCC_GPIOC_CLK_ENABLE();
  94. __HAL_RCC_GPIOA_CLK_ENABLE();
  95. /**I2C3 GPIO Configuration
  96. PC9 ------> I2C3_SDA
  97. PA8 ------> I2C3_SCL
  98. */
  99. GPIO_InitStruct.Pin = GPIO_PIN_9;
  100. GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
  101. GPIO_InitStruct.Pull = GPIO_PULLUP;
  102. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  103. GPIO_InitStruct.Alternate = GPIO_AF4_I2C3;
  104. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  105. GPIO_InitStruct.Pin = GPIO_PIN_8;
  106. GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
  107. GPIO_InitStruct.Pull = GPIO_PULLUP;
  108. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  109. GPIO_InitStruct.Alternate = GPIO_AF4_I2C3;
  110. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  111. /* Peripheral clock enable */
  112. __HAL_RCC_I2C3_CLK_ENABLE();
  113. /* USER CODE BEGIN I2C3_MspInit 1 */
  114. /* USER CODE END I2C3_MspInit 1 */
  115. }
  116. }
  117. /**
  118. * @brief I2C MSP De-Initialization
  119. * This function freeze the hardware resources used in this example
  120. * @param hi2c: I2C handle pointer
  121. * @retval None
  122. */
  123. void HAL_I2C_MspDeInit(I2C_HandleTypeDef* hi2c)
  124. {
  125. if(hi2c->Instance==I2C3)
  126. {
  127. /* USER CODE BEGIN I2C3_MspDeInit 0 */
  128. /* USER CODE END I2C3_MspDeInit 0 */
  129. /* Peripheral clock disable */
  130. __HAL_RCC_I2C3_CLK_DISABLE();
  131. /**I2C3 GPIO Configuration
  132. PC9 ------> I2C3_SDA
  133. PA8 ------> I2C3_SCL
  134. */
  135. HAL_GPIO_DeInit(GPIOC, GPIO_PIN_9);
  136. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8);
  137. /* USER CODE BEGIN I2C3_MspDeInit 1 */
  138. /* USER CODE END I2C3_MspDeInit 1 */
  139. }
  140. }
  141. /**
  142. * @brief TIM_Base MSP Initialization
  143. * This function configures the hardware resources used in this example
  144. * @param htim_base: TIM_Base handle pointer
  145. * @retval None
  146. */
  147. void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
  148. {
  149. if(htim_base->Instance==TIM6)
  150. {
  151. /* USER CODE BEGIN TIM6_MspInit 0 */
  152. /* USER CODE END TIM6_MspInit 0 */
  153. /* Peripheral clock enable */
  154. __HAL_RCC_TIM6_CLK_ENABLE();
  155. /* USER CODE BEGIN TIM6_MspInit 1 */
  156. /* USER CODE END TIM6_MspInit 1 */
  157. }
  158. }
  159. /**
  160. * @brief TIM_Base MSP De-Initialization
  161. * This function freeze the hardware resources used in this example
  162. * @param htim_base: TIM_Base handle pointer
  163. * @retval None
  164. */
  165. void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
  166. {
  167. if(htim_base->Instance==TIM6)
  168. {
  169. /* USER CODE BEGIN TIM6_MspDeInit 0 */
  170. /* USER CODE END TIM6_MspDeInit 0 */
  171. /* Peripheral clock disable */
  172. __HAL_RCC_TIM6_CLK_DISABLE();
  173. /* TIM6 interrupt DeInit */
  174. HAL_NVIC_DisableIRQ(TIM6_DAC_IRQn);
  175. /* USER CODE BEGIN TIM6_MspDeInit 1 */
  176. /* USER CODE END TIM6_MspDeInit 1 */
  177. }
  178. }
  179. /**
  180. * @brief UART MSP Initialization
  181. * This function configures the hardware resources used in this example
  182. * @param huart: UART handle pointer
  183. * @retval None
  184. */
  185. void HAL_UART_MspInit(UART_HandleTypeDef* huart)
  186. {
  187. GPIO_InitTypeDef GPIO_InitStruct = {0};
  188. if(huart->Instance==USART3)
  189. {
  190. /* USER CODE BEGIN USART3_MspInit 0 */
  191. /* USER CODE END USART3_MspInit 0 */
  192. /* Peripheral clock enable */
  193. __HAL_RCC_USART3_CLK_ENABLE();
  194. __HAL_RCC_GPIOB_CLK_ENABLE();
  195. /**USART3 GPIO Configuration
  196. PB10 ------> USART3_TX
  197. PB11 ------> USART3_RX
  198. */
  199. GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11;
  200. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  201. GPIO_InitStruct.Pull = GPIO_PULLUP;
  202. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  203. GPIO_InitStruct.Alternate = GPIO_AF7_USART3;
  204. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  205. /* USART3 DMA Init */
  206. /* USART3_RX Init */
  207. hdma_usart3_rx.Instance = DMA1_Stream1;
  208. hdma_usart3_rx.Init.Channel = DMA_CHANNEL_4;
  209. hdma_usart3_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
  210. hdma_usart3_rx.Init.PeriphInc = DMA_PINC_DISABLE;
  211. hdma_usart3_rx.Init.MemInc = DMA_MINC_ENABLE;
  212. hdma_usart3_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
  213. hdma_usart3_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
  214. hdma_usart3_rx.Init.Mode = DMA_NORMAL;
  215. hdma_usart3_rx.Init.Priority = DMA_PRIORITY_LOW;
  216. hdma_usart3_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
  217. if (HAL_DMA_Init(&hdma_usart3_rx) != HAL_OK)
  218. {
  219. Error_Handler();
  220. }
  221. __HAL_LINKDMA(huart,hdmarx,hdma_usart3_rx);
  222. /* USART3_TX Init */
  223. hdma_usart3_tx.Instance = DMA1_Stream4;
  224. hdma_usart3_tx.Init.Channel = DMA_CHANNEL_7;
  225. hdma_usart3_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
  226. hdma_usart3_tx.Init.PeriphInc = DMA_PINC_DISABLE;
  227. hdma_usart3_tx.Init.MemInc = DMA_MINC_ENABLE;
  228. hdma_usart3_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
  229. hdma_usart3_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
  230. hdma_usart3_tx.Init.Mode = DMA_NORMAL;
  231. hdma_usart3_tx.Init.Priority = DMA_PRIORITY_LOW;
  232. hdma_usart3_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
  233. if (HAL_DMA_Init(&hdma_usart3_tx) != HAL_OK)
  234. {
  235. Error_Handler();
  236. }
  237. __HAL_LINKDMA(huart,hdmatx,hdma_usart3_tx);
  238. /* USER CODE BEGIN USART3_MspInit 1 */
  239. /* USER CODE END USART3_MspInit 1 */
  240. }
  241. }
  242. /**
  243. * @brief UART MSP De-Initialization
  244. * This function freeze the hardware resources used in this example
  245. * @param huart: UART handle pointer
  246. * @retval None
  247. */
  248. void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
  249. {
  250. if(huart->Instance==USART3)
  251. {
  252. /* USER CODE BEGIN USART3_MspDeInit 0 */
  253. /* USER CODE END USART3_MspDeInit 0 */
  254. /* Peripheral clock disable */
  255. __HAL_RCC_USART3_CLK_DISABLE();
  256. /**USART3 GPIO Configuration
  257. PB10 ------> USART3_TX
  258. PB11 ------> USART3_RX
  259. */
  260. HAL_GPIO_DeInit(GPIOB, GPIO_PIN_10|GPIO_PIN_11);
  261. /* USART3 DMA DeInit */
  262. HAL_DMA_DeInit(huart->hdmarx);
  263. HAL_DMA_DeInit(huart->hdmatx);
  264. /* USART3 interrupt DeInit */
  265. HAL_NVIC_DisableIRQ(USART3_IRQn);
  266. /* USER CODE BEGIN USART3_MspDeInit 1 */
  267. /* USER CODE END USART3_MspDeInit 1 */
  268. }
  269. }
  270. /* USER CODE BEGIN 1 */
  271. /* USER CODE END 1 */
  272. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/