stm32f1xx_hal_msp.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * File Name : stm32f1xx_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. /* 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. /**
  66. * Initializes the Global MSP.
  67. */
  68. void HAL_MspInit(void)
  69. {
  70. /* USER CODE BEGIN MspInit 0 */
  71. /* USER CODE END MspInit 0 */
  72. __HAL_RCC_AFIO_CLK_ENABLE();
  73. __HAL_RCC_PWR_CLK_ENABLE();
  74. /* System interrupt init*/
  75. /**DISABLE: JTAG-DP Disabled and SW-DP Disabled
  76. */
  77. __HAL_AFIO_REMAP_SWJ_DISABLE();
  78. /* USER CODE BEGIN MspInit 1 */
  79. /* USER CODE END MspInit 1 */
  80. }
  81. /**
  82. * @brief I2C MSP Initialization
  83. * This function configures the hardware resources used in this example
  84. * @param hi2c: I2C handle pointer
  85. * @retval None
  86. */
  87. void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c)
  88. {
  89. GPIO_InitTypeDef GPIO_InitStruct = {0};
  90. if(hi2c->Instance==I2C2)
  91. {
  92. /* USER CODE BEGIN I2C2_MspInit 0 */
  93. /* USER CODE END I2C2_MspInit 0 */
  94. __HAL_RCC_GPIOB_CLK_ENABLE();
  95. /**I2C2 GPIO Configuration
  96. PB10 ------> I2C2_SCL
  97. PB11 ------> I2C2_SDA
  98. */
  99. GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11;
  100. GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
  101. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  102. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  103. /* Peripheral clock enable */
  104. __HAL_RCC_I2C2_CLK_ENABLE();
  105. /* USER CODE BEGIN I2C2_MspInit 1 */
  106. /* USER CODE END I2C2_MspInit 1 */
  107. }
  108. }
  109. /**
  110. * @brief I2C MSP De-Initialization
  111. * This function freeze the hardware resources used in this example
  112. * @param hi2c: I2C handle pointer
  113. * @retval None
  114. */
  115. void HAL_I2C_MspDeInit(I2C_HandleTypeDef* hi2c)
  116. {
  117. if(hi2c->Instance==I2C2)
  118. {
  119. /* USER CODE BEGIN I2C2_MspDeInit 0 */
  120. /* USER CODE END I2C2_MspDeInit 0 */
  121. /* Peripheral clock disable */
  122. __HAL_RCC_I2C2_CLK_DISABLE();
  123. /**I2C2 GPIO Configuration
  124. PB10 ------> I2C2_SCL
  125. PB11 ------> I2C2_SDA
  126. */
  127. HAL_GPIO_DeInit(GPIOB, GPIO_PIN_10|GPIO_PIN_11);
  128. /* USER CODE BEGIN I2C2_MspDeInit 1 */
  129. /* USER CODE END I2C2_MspDeInit 1 */
  130. }
  131. }
  132. /**
  133. * @brief SPI MSP Initialization
  134. * This function configures the hardware resources used in this example
  135. * @param hspi: SPI handle pointer
  136. * @retval None
  137. */
  138. void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
  139. {
  140. GPIO_InitTypeDef GPIO_InitStruct = {0};
  141. if(hspi->Instance==SPI1)
  142. {
  143. /* USER CODE BEGIN SPI1_MspInit 0 */
  144. /* USER CODE END SPI1_MspInit 0 */
  145. /* Peripheral clock enable */
  146. __HAL_RCC_SPI1_CLK_ENABLE();
  147. __HAL_RCC_GPIOA_CLK_ENABLE();
  148. __HAL_RCC_GPIOB_CLK_ENABLE();
  149. /**SPI1 GPIO Configuration
  150. PA15 ------> SPI1_NSS
  151. PB3 ------> SPI1_SCK
  152. PB4 ------> SPI1_MISO
  153. PB5 ------> SPI1_MOSI
  154. */
  155. GPIO_InitStruct.Pin = GPIO_PIN_15;
  156. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  157. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  158. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  159. GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_5;
  160. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  161. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  162. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  163. GPIO_InitStruct.Pin = GPIO_PIN_4;
  164. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  165. GPIO_InitStruct.Pull = GPIO_NOPULL;
  166. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  167. __HAL_AFIO_REMAP_SPI1_ENABLE();
  168. /* USER CODE BEGIN SPI1_MspInit 1 */
  169. /* USER CODE END SPI1_MspInit 1 */
  170. }
  171. }
  172. /**
  173. * @brief SPI MSP De-Initialization
  174. * This function freeze the hardware resources used in this example
  175. * @param hspi: SPI handle pointer
  176. * @retval None
  177. */
  178. void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
  179. {
  180. if(hspi->Instance==SPI1)
  181. {
  182. /* USER CODE BEGIN SPI1_MspDeInit 0 */
  183. /* USER CODE END SPI1_MspDeInit 0 */
  184. /* Peripheral clock disable */
  185. __HAL_RCC_SPI1_CLK_DISABLE();
  186. /**SPI1 GPIO Configuration
  187. PA15 ------> SPI1_NSS
  188. PB3 ------> SPI1_SCK
  189. PB4 ------> SPI1_MISO
  190. PB5 ------> SPI1_MOSI
  191. */
  192. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_15);
  193. HAL_GPIO_DeInit(GPIOB, GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5);
  194. /* USER CODE BEGIN SPI1_MspDeInit 1 */
  195. /* USER CODE END SPI1_MspDeInit 1 */
  196. }
  197. }
  198. /**
  199. * @brief TIM_Base MSP Initialization
  200. * This function configures the hardware resources used in this example
  201. * @param htim_base: TIM_Base handle pointer
  202. * @retval None
  203. */
  204. void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
  205. {
  206. if(htim_base->Instance==TIM6)
  207. {
  208. /* USER CODE BEGIN TIM6_MspInit 0 */
  209. /* USER CODE END TIM6_MspInit 0 */
  210. /* Peripheral clock enable */
  211. __HAL_RCC_TIM6_CLK_ENABLE();
  212. /* USER CODE BEGIN TIM6_MspInit 1 */
  213. /* USER CODE END TIM6_MspInit 1 */
  214. }
  215. }
  216. /**
  217. * @brief TIM_Base MSP De-Initialization
  218. * This function freeze the hardware resources used in this example
  219. * @param htim_base: TIM_Base handle pointer
  220. * @retval None
  221. */
  222. void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
  223. {
  224. if(htim_base->Instance==TIM6)
  225. {
  226. /* USER CODE BEGIN TIM6_MspDeInit 0 */
  227. /* USER CODE END TIM6_MspDeInit 0 */
  228. /* Peripheral clock disable */
  229. __HAL_RCC_TIM6_CLK_DISABLE();
  230. /* TIM6 interrupt DeInit */
  231. HAL_NVIC_DisableIRQ(TIM6_IRQn);
  232. /* USER CODE BEGIN TIM6_MspDeInit 1 */
  233. /* USER CODE END TIM6_MspDeInit 1 */
  234. }
  235. }
  236. /**
  237. * @brief UART MSP Initialization
  238. * This function configures the hardware resources used in this example
  239. * @param huart: UART handle pointer
  240. * @retval None
  241. */
  242. void HAL_UART_MspInit(UART_HandleTypeDef* huart)
  243. {
  244. GPIO_InitTypeDef GPIO_InitStruct = {0};
  245. if(huart->Instance==USART1)
  246. {
  247. /* USER CODE BEGIN USART1_MspInit 0 */
  248. /* USER CODE END USART1_MspInit 0 */
  249. /* Peripheral clock enable */
  250. __HAL_RCC_USART1_CLK_ENABLE();
  251. __HAL_RCC_GPIOA_CLK_ENABLE();
  252. /**USART1 GPIO Configuration
  253. PA9 ------> USART1_TX
  254. PA10 ------> USART1_RX
  255. */
  256. GPIO_InitStruct.Pin = GPIO_PIN_9;
  257. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  258. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  259. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  260. GPIO_InitStruct.Pin = GPIO_PIN_10;
  261. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  262. GPIO_InitStruct.Pull = GPIO_NOPULL;
  263. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  264. /* USER CODE BEGIN USART1_MspInit 1 */
  265. /* USER CODE END USART1_MspInit 1 */
  266. }
  267. else if(huart->Instance==USART2)
  268. {
  269. /* USER CODE BEGIN USART2_MspInit 0 */
  270. /* USER CODE END USART2_MspInit 0 */
  271. /* Peripheral clock enable */
  272. __HAL_RCC_USART2_CLK_ENABLE();
  273. __HAL_RCC_GPIOA_CLK_ENABLE();
  274. /**USART2 GPIO Configuration
  275. PA2 ------> USART2_TX
  276. PA3 ------> USART2_RX
  277. */
  278. GPIO_InitStruct.Pin = GPIO_PIN_2;
  279. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  280. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  281. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  282. GPIO_InitStruct.Pin = GPIO_PIN_3;
  283. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  284. GPIO_InitStruct.Pull = GPIO_NOPULL;
  285. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  286. /* USER CODE BEGIN USART2_MspInit 1 */
  287. /* USER CODE END USART2_MspInit 1 */
  288. }
  289. }
  290. /**
  291. * @brief UART MSP De-Initialization
  292. * This function freeze the hardware resources used in this example
  293. * @param huart: UART handle pointer
  294. * @retval None
  295. */
  296. void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
  297. {
  298. if(huart->Instance==USART1)
  299. {
  300. /* USER CODE BEGIN USART1_MspDeInit 0 */
  301. /* USER CODE END USART1_MspDeInit 0 */
  302. /* Peripheral clock disable */
  303. __HAL_RCC_USART1_CLK_DISABLE();
  304. /**USART1 GPIO Configuration
  305. PA9 ------> USART1_TX
  306. PA10 ------> USART1_RX
  307. */
  308. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10);
  309. /* USART1 interrupt DeInit */
  310. HAL_NVIC_DisableIRQ(USART1_IRQn);
  311. /* USER CODE BEGIN USART1_MspDeInit 1 */
  312. /* USER CODE END USART1_MspDeInit 1 */
  313. }
  314. else if(huart->Instance==USART2)
  315. {
  316. /* USER CODE BEGIN USART2_MspDeInit 0 */
  317. /* USER CODE END USART2_MspDeInit 0 */
  318. /* Peripheral clock disable */
  319. __HAL_RCC_USART2_CLK_DISABLE();
  320. /**USART2 GPIO Configuration
  321. PA2 ------> USART2_TX
  322. PA3 ------> USART2_RX
  323. */
  324. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3);
  325. /* USART2 interrupt DeInit */
  326. HAL_NVIC_DisableIRQ(USART2_IRQn);
  327. /* USER CODE BEGIN USART2_MspDeInit 1 */
  328. /* USER CODE END USART2_MspDeInit 1 */
  329. }
  330. }
  331. /* USER CODE BEGIN 1 */
  332. /* USER CODE END 1 */
  333. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/