stm32f4xx_hal_msp.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  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. /**
  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_SYSCFG_CLK_ENABLE();
  73. __HAL_RCC_PWR_CLK_ENABLE();
  74. /* System interrupt init*/
  75. /* USER CODE BEGIN MspInit 1 */
  76. /* USER CODE END MspInit 1 */
  77. }
  78. /**
  79. * @brief ADC MSP Initialization
  80. * This function configures the hardware resources used in this example
  81. * @param hadc: ADC handle pointer
  82. * @retval None
  83. */
  84. void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
  85. {
  86. GPIO_InitTypeDef GPIO_InitStruct = {0};
  87. if(hadc->Instance==ADC1)
  88. {
  89. /* USER CODE BEGIN ADC1_MspInit 0 */
  90. /* USER CODE END ADC1_MspInit 0 */
  91. /* Peripheral clock enable */
  92. __HAL_RCC_ADC1_CLK_ENABLE();
  93. __HAL_RCC_GPIOB_CLK_ENABLE();
  94. /**ADC1 GPIO Configuration
  95. PB1 ------> ADC1_IN9
  96. */
  97. GPIO_InitStruct.Pin = GPIO_PIN_1;
  98. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  99. GPIO_InitStruct.Pull = GPIO_NOPULL;
  100. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  101. /* USER CODE BEGIN ADC1_MspInit 1 */
  102. /* USER CODE END ADC1_MspInit 1 */
  103. }
  104. }
  105. /**
  106. * @brief ADC MSP De-Initialization
  107. * This function freeze the hardware resources used in this example
  108. * @param hadc: ADC handle pointer
  109. * @retval None
  110. */
  111. void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
  112. {
  113. if(hadc->Instance==ADC1)
  114. {
  115. /* USER CODE BEGIN ADC1_MspDeInit 0 */
  116. /* USER CODE END ADC1_MspDeInit 0 */
  117. /* Peripheral clock disable */
  118. __HAL_RCC_ADC1_CLK_DISABLE();
  119. /**ADC1 GPIO Configuration
  120. PB1 ------> ADC1_IN9
  121. */
  122. HAL_GPIO_DeInit(GPIOB, GPIO_PIN_1);
  123. /* USER CODE BEGIN ADC1_MspDeInit 1 */
  124. /* USER CODE END ADC1_MspDeInit 1 */
  125. }
  126. }
  127. /**
  128. * @brief I2C MSP Initialization
  129. * This function configures the hardware resources used in this example
  130. * @param hi2c: I2C handle pointer
  131. * @retval None
  132. */
  133. void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c)
  134. {
  135. GPIO_InitTypeDef GPIO_InitStruct = {0};
  136. if(hi2c->Instance==I2C1)
  137. {
  138. /* USER CODE BEGIN I2C1_MspInit 0 */
  139. /* USER CODE END I2C1_MspInit 0 */
  140. __HAL_RCC_GPIOB_CLK_ENABLE();
  141. /**I2C1 GPIO Configuration
  142. PB6 ------> I2C1_SCL
  143. PB7 ------> I2C1_SDA
  144. */
  145. GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
  146. GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
  147. GPIO_InitStruct.Pull = GPIO_PULLUP;
  148. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  149. GPIO_InitStruct.Alternate = GPIO_AF4_I2C1;
  150. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  151. /* Peripheral clock enable */
  152. __HAL_RCC_I2C1_CLK_ENABLE();
  153. /* USER CODE BEGIN I2C1_MspInit 1 */
  154. /* USER CODE END I2C1_MspInit 1 */
  155. }
  156. }
  157. /**
  158. * @brief I2C MSP De-Initialization
  159. * This function freeze the hardware resources used in this example
  160. * @param hi2c: I2C handle pointer
  161. * @retval None
  162. */
  163. void HAL_I2C_MspDeInit(I2C_HandleTypeDef* hi2c)
  164. {
  165. if(hi2c->Instance==I2C1)
  166. {
  167. /* USER CODE BEGIN I2C1_MspDeInit 0 */
  168. /* USER CODE END I2C1_MspDeInit 0 */
  169. /* Peripheral clock disable */
  170. __HAL_RCC_I2C1_CLK_DISABLE();
  171. /**I2C1 GPIO Configuration
  172. PB6 ------> I2C1_SCL
  173. PB7 ------> I2C1_SDA
  174. */
  175. HAL_GPIO_DeInit(GPIOB, GPIO_PIN_6|GPIO_PIN_7);
  176. /* USER CODE BEGIN I2C1_MspDeInit 1 */
  177. /* USER CODE END I2C1_MspDeInit 1 */
  178. }
  179. }
  180. /**
  181. * @brief RTC MSP Initialization
  182. * This function configures the hardware resources used in this example
  183. * @param hrtc: RTC handle pointer
  184. * @retval None
  185. */
  186. void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc)
  187. {
  188. if(hrtc->Instance==RTC)
  189. {
  190. /* USER CODE BEGIN RTC_MspInit 0 */
  191. /* USER CODE END RTC_MspInit 0 */
  192. /* Peripheral clock enable */
  193. __HAL_RCC_RTC_ENABLE();
  194. /* USER CODE BEGIN RTC_MspInit 1 */
  195. /* USER CODE END RTC_MspInit 1 */
  196. }
  197. }
  198. /**
  199. * @brief RTC MSP De-Initialization
  200. * This function freeze the hardware resources used in this example
  201. * @param hrtc: RTC handle pointer
  202. * @retval None
  203. */
  204. void HAL_RTC_MspDeInit(RTC_HandleTypeDef* hrtc)
  205. {
  206. if(hrtc->Instance==RTC)
  207. {
  208. /* USER CODE BEGIN RTC_MspDeInit 0 */
  209. /* USER CODE END RTC_MspDeInit 0 */
  210. /* Peripheral clock disable */
  211. __HAL_RCC_RTC_DISABLE();
  212. /* USER CODE BEGIN RTC_MspDeInit 1 */
  213. /* USER CODE END RTC_MspDeInit 1 */
  214. }
  215. }
  216. /**
  217. * @brief SPI MSP Initialization
  218. * This function configures the hardware resources used in this example
  219. * @param hspi: SPI handle pointer
  220. * @retval None
  221. */
  222. void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
  223. {
  224. GPIO_InitTypeDef GPIO_InitStruct = {0};
  225. if(hspi->Instance==SPI2)
  226. {
  227. /* USER CODE BEGIN SPI2_MspInit 0 */
  228. /* USER CODE END SPI2_MspInit 0 */
  229. /* Peripheral clock enable */
  230. __HAL_RCC_SPI2_CLK_ENABLE();
  231. __HAL_RCC_GPIOB_CLK_ENABLE();
  232. /**SPI2 GPIO Configuration
  233. PB13 ------> SPI2_SCK
  234. PB14 ------> SPI2_MISO
  235. PB15 ------> SPI2_MOSI
  236. */
  237. GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
  238. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  239. GPIO_InitStruct.Pull = GPIO_NOPULL;
  240. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  241. GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
  242. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  243. /* USER CODE BEGIN SPI2_MspInit 1 */
  244. /* USER CODE END SPI2_MspInit 1 */
  245. }
  246. }
  247. /**
  248. * @brief SPI MSP De-Initialization
  249. * This function freeze the hardware resources used in this example
  250. * @param hspi: SPI handle pointer
  251. * @retval None
  252. */
  253. void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
  254. {
  255. if(hspi->Instance==SPI2)
  256. {
  257. /* USER CODE BEGIN SPI2_MspDeInit 0 */
  258. /* USER CODE END SPI2_MspDeInit 0 */
  259. /* Peripheral clock disable */
  260. __HAL_RCC_SPI2_CLK_DISABLE();
  261. /**SPI2 GPIO Configuration
  262. PB13 ------> SPI2_SCK
  263. PB14 ------> SPI2_MISO
  264. PB15 ------> SPI2_MOSI
  265. */
  266. HAL_GPIO_DeInit(GPIOB, GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15);
  267. /* USER CODE BEGIN SPI2_MspDeInit 1 */
  268. /* USER CODE END SPI2_MspDeInit 1 */
  269. }
  270. }
  271. /**
  272. * @brief UART MSP Initialization
  273. * This function configures the hardware resources used in this example
  274. * @param huart: UART handle pointer
  275. * @retval None
  276. */
  277. void HAL_UART_MspInit(UART_HandleTypeDef* huart)
  278. {
  279. GPIO_InitTypeDef GPIO_InitStruct = {0};
  280. if(huart->Instance==USART1)
  281. {
  282. /* USER CODE BEGIN USART1_MspInit 0 */
  283. /* USER CODE END USART1_MspInit 0 */
  284. /* Peripheral clock enable */
  285. __HAL_RCC_USART1_CLK_ENABLE();
  286. __HAL_RCC_GPIOA_CLK_ENABLE();
  287. /**USART1 GPIO Configuration
  288. PA9 ------> USART1_TX
  289. PA10 ------> USART1_RX
  290. */
  291. GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10;
  292. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  293. GPIO_InitStruct.Pull = GPIO_PULLUP;
  294. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  295. GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
  296. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  297. /* USER CODE BEGIN USART1_MspInit 1 */
  298. /* USER CODE END USART1_MspInit 1 */
  299. }
  300. else if(huart->Instance==USART2)
  301. {
  302. /* USER CODE BEGIN USART2_MspInit 0 */
  303. /* USER CODE END USART2_MspInit 0 */
  304. /* Peripheral clock enable */
  305. __HAL_RCC_USART2_CLK_ENABLE();
  306. __HAL_RCC_GPIOA_CLK_ENABLE();
  307. /**USART2 GPIO Configuration
  308. PA2 ------> USART2_TX
  309. PA3 ------> USART2_RX
  310. */
  311. GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3;
  312. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  313. GPIO_InitStruct.Pull = GPIO_PULLUP;
  314. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  315. GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
  316. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  317. /* USER CODE BEGIN USART2_MspInit 1 */
  318. /* USER CODE END USART2_MspInit 1 */
  319. }
  320. }
  321. /**
  322. * @brief UART MSP De-Initialization
  323. * This function freeze the hardware resources used in this example
  324. * @param huart: UART handle pointer
  325. * @retval None
  326. */
  327. void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
  328. {
  329. if(huart->Instance==USART1)
  330. {
  331. /* USER CODE BEGIN USART1_MspDeInit 0 */
  332. /* USER CODE END USART1_MspDeInit 0 */
  333. /* Peripheral clock disable */
  334. __HAL_RCC_USART1_CLK_DISABLE();
  335. /**USART1 GPIO Configuration
  336. PA9 ------> USART1_TX
  337. PA10 ------> USART1_RX
  338. */
  339. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10);
  340. /* USER CODE BEGIN USART1_MspDeInit 1 */
  341. /* USER CODE END USART1_MspDeInit 1 */
  342. }
  343. else if(huart->Instance==USART2)
  344. {
  345. /* USER CODE BEGIN USART2_MspDeInit 0 */
  346. /* USER CODE END USART2_MspDeInit 0 */
  347. /* Peripheral clock disable */
  348. __HAL_RCC_USART2_CLK_DISABLE();
  349. /**USART2 GPIO Configuration
  350. PA2 ------> USART2_TX
  351. PA3 ------> USART2_RX
  352. */
  353. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3);
  354. /* USER CODE BEGIN USART2_MspDeInit 1 */
  355. /* USER CODE END USART2_MspDeInit 1 */
  356. }
  357. }
  358. /* USER CODE BEGIN 1 */
  359. /* USER CODE END 1 */
  360. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/