stm32f0xx_hal_msp.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * File Name : stm32f0xx_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. /* System interrupt init*/
  76. /* USER CODE BEGIN MspInit 1 */
  77. /* USER CODE END MspInit 1 */
  78. }
  79. /**
  80. * @brief ADC MSP Initialization
  81. * This function configures the hardware resources used in this example
  82. * @param hadc: ADC handle pointer
  83. * @retval None
  84. */
  85. void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
  86. {
  87. GPIO_InitTypeDef GPIO_InitStruct = {0};
  88. if(hadc->Instance==ADC1)
  89. {
  90. /* USER CODE BEGIN ADC1_MspInit 0 */
  91. /* USER CODE END ADC1_MspInit 0 */
  92. /* Peripheral clock enable */
  93. __HAL_RCC_ADC1_CLK_ENABLE();
  94. __HAL_RCC_GPIOA_CLK_ENABLE();
  95. /**ADC GPIO Configuration
  96. PA0 ------> ADC_IN0
  97. */
  98. GPIO_InitStruct.Pin = GPIO_PIN_0;
  99. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  100. GPIO_InitStruct.Pull = GPIO_NOPULL;
  101. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  102. /* USER CODE BEGIN ADC1_MspInit 1 */
  103. /* USER CODE END ADC1_MspInit 1 */
  104. }
  105. }
  106. /**
  107. * @brief ADC MSP De-Initialization
  108. * This function freeze the hardware resources used in this example
  109. * @param hadc: ADC handle pointer
  110. * @retval None
  111. */
  112. void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
  113. {
  114. if(hadc->Instance==ADC1)
  115. {
  116. /* USER CODE BEGIN ADC1_MspDeInit 0 */
  117. /* USER CODE END ADC1_MspDeInit 0 */
  118. /* Peripheral clock disable */
  119. __HAL_RCC_ADC1_CLK_DISABLE();
  120. /**ADC GPIO Configuration
  121. PA0 ------> ADC_IN0
  122. */
  123. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_0);
  124. /* USER CODE BEGIN ADC1_MspDeInit 1 */
  125. /* USER CODE END ADC1_MspDeInit 1 */
  126. }
  127. }
  128. /**
  129. * @brief RTC MSP Initialization
  130. * This function configures the hardware resources used in this example
  131. * @param hrtc: RTC handle pointer
  132. * @retval None
  133. */
  134. void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc)
  135. {
  136. if(hrtc->Instance==RTC)
  137. {
  138. /* USER CODE BEGIN RTC_MspInit 0 */
  139. /* USER CODE END RTC_MspInit 0 */
  140. /* Peripheral clock enable */
  141. __HAL_RCC_RTC_ENABLE();
  142. /* USER CODE BEGIN RTC_MspInit 1 */
  143. /* USER CODE END RTC_MspInit 1 */
  144. }
  145. }
  146. /**
  147. * @brief RTC MSP De-Initialization
  148. * This function freeze the hardware resources used in this example
  149. * @param hrtc: RTC handle pointer
  150. * @retval None
  151. */
  152. void HAL_RTC_MspDeInit(RTC_HandleTypeDef* hrtc)
  153. {
  154. if(hrtc->Instance==RTC)
  155. {
  156. /* USER CODE BEGIN RTC_MspDeInit 0 */
  157. /* USER CODE END RTC_MspDeInit 0 */
  158. /* Peripheral clock disable */
  159. __HAL_RCC_RTC_DISABLE();
  160. /* USER CODE BEGIN RTC_MspDeInit 1 */
  161. /* USER CODE END RTC_MspDeInit 1 */
  162. }
  163. }
  164. /**
  165. * @brief SPI MSP Initialization
  166. * This function configures the hardware resources used in this example
  167. * @param hspi: SPI handle pointer
  168. * @retval None
  169. */
  170. void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
  171. {
  172. GPIO_InitTypeDef GPIO_InitStruct = {0};
  173. if(hspi->Instance==SPI1)
  174. {
  175. /* USER CODE BEGIN SPI1_MspInit 0 */
  176. /* USER CODE END SPI1_MspInit 0 */
  177. /* Peripheral clock enable */
  178. __HAL_RCC_SPI1_CLK_ENABLE();
  179. __HAL_RCC_GPIOA_CLK_ENABLE();
  180. /**SPI1 GPIO Configuration
  181. PA5 ------> SPI1_SCK
  182. PA6 ------> SPI1_MISO
  183. PA7 ------> SPI1_MOSI
  184. */
  185. GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7;
  186. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  187. GPIO_InitStruct.Pull = GPIO_NOPULL;
  188. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  189. GPIO_InitStruct.Alternate = GPIO_AF0_SPI1;
  190. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  191. /* USER CODE BEGIN SPI1_MspInit 1 */
  192. /* USER CODE END SPI1_MspInit 1 */
  193. }
  194. }
  195. /**
  196. * @brief SPI MSP De-Initialization
  197. * This function freeze the hardware resources used in this example
  198. * @param hspi: SPI handle pointer
  199. * @retval None
  200. */
  201. void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
  202. {
  203. if(hspi->Instance==SPI1)
  204. {
  205. /* USER CODE BEGIN SPI1_MspDeInit 0 */
  206. /* USER CODE END SPI1_MspDeInit 0 */
  207. /* Peripheral clock disable */
  208. __HAL_RCC_SPI1_CLK_DISABLE();
  209. /**SPI1 GPIO Configuration
  210. PA5 ------> SPI1_SCK
  211. PA6 ------> SPI1_MISO
  212. PA7 ------> SPI1_MOSI
  213. */
  214. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7);
  215. /* USER CODE BEGIN SPI1_MspDeInit 1 */
  216. /* USER CODE END SPI1_MspDeInit 1 */
  217. }
  218. }
  219. /**
  220. * @brief TIM_Base MSP Initialization
  221. * This function configures the hardware resources used in this example
  222. * @param htim_base: TIM_Base handle pointer
  223. * @retval None
  224. */
  225. void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
  226. {
  227. if(htim_base->Instance==TIM2)
  228. {
  229. /* USER CODE BEGIN TIM2_MspInit 0 */
  230. /* USER CODE END TIM2_MspInit 0 */
  231. /* Peripheral clock enable */
  232. __HAL_RCC_TIM2_CLK_ENABLE();
  233. /* USER CODE BEGIN TIM2_MspInit 1 */
  234. /* USER CODE END TIM2_MspInit 1 */
  235. }
  236. else if(htim_base->Instance==TIM14)
  237. {
  238. /* USER CODE BEGIN TIM14_MspInit 0 */
  239. /* USER CODE END TIM14_MspInit 0 */
  240. /* Peripheral clock enable */
  241. __HAL_RCC_TIM14_CLK_ENABLE();
  242. /* USER CODE BEGIN TIM14_MspInit 1 */
  243. /* USER CODE END TIM14_MspInit 1 */
  244. }
  245. else if(htim_base->Instance==TIM16)
  246. {
  247. /* USER CODE BEGIN TIM16_MspInit 0 */
  248. /* USER CODE END TIM16_MspInit 0 */
  249. /* Peripheral clock enable */
  250. __HAL_RCC_TIM16_CLK_ENABLE();
  251. /* USER CODE BEGIN TIM16_MspInit 1 */
  252. /* USER CODE END TIM16_MspInit 1 */
  253. }
  254. else if(htim_base->Instance==TIM17)
  255. {
  256. /* USER CODE BEGIN TIM17_MspInit 0 */
  257. /* USER CODE END TIM17_MspInit 0 */
  258. /* Peripheral clock enable */
  259. __HAL_RCC_TIM17_CLK_ENABLE();
  260. /* USER CODE BEGIN TIM17_MspInit 1 */
  261. /* USER CODE END TIM17_MspInit 1 */
  262. }
  263. }
  264. void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
  265. {
  266. GPIO_InitTypeDef GPIO_InitStruct = {0};
  267. if(htim->Instance==TIM2)
  268. {
  269. /* USER CODE BEGIN TIM2_MspPostInit 0 */
  270. /* USER CODE END TIM2_MspPostInit 0 */
  271. __HAL_RCC_GPIOB_CLK_ENABLE();
  272. /**TIM2 GPIO Configuration
  273. PB11 ------> TIM2_CH4
  274. */
  275. GPIO_InitStruct.Pin = GPIO_PIN_11;
  276. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  277. GPIO_InitStruct.Pull = GPIO_NOPULL;
  278. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  279. GPIO_InitStruct.Alternate = GPIO_AF2_TIM2;
  280. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  281. /* USER CODE BEGIN TIM2_MspPostInit 1 */
  282. /* USER CODE END TIM2_MspPostInit 1 */
  283. }
  284. }
  285. /**
  286. * @brief TIM_Base MSP De-Initialization
  287. * This function freeze the hardware resources used in this example
  288. * @param htim_base: TIM_Base handle pointer
  289. * @retval None
  290. */
  291. void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
  292. {
  293. if(htim_base->Instance==TIM2)
  294. {
  295. /* USER CODE BEGIN TIM2_MspDeInit 0 */
  296. /* USER CODE END TIM2_MspDeInit 0 */
  297. /* Peripheral clock disable */
  298. __HAL_RCC_TIM2_CLK_DISABLE();
  299. /* USER CODE BEGIN TIM2_MspDeInit 1 */
  300. /* USER CODE END TIM2_MspDeInit 1 */
  301. }
  302. else if(htim_base->Instance==TIM14)
  303. {
  304. /* USER CODE BEGIN TIM14_MspDeInit 0 */
  305. /* USER CODE END TIM14_MspDeInit 0 */
  306. /* Peripheral clock disable */
  307. __HAL_RCC_TIM14_CLK_DISABLE();
  308. /* USER CODE BEGIN TIM14_MspDeInit 1 */
  309. /* USER CODE END TIM14_MspDeInit 1 */
  310. }
  311. else if(htim_base->Instance==TIM16)
  312. {
  313. /* USER CODE BEGIN TIM16_MspDeInit 0 */
  314. /* USER CODE END TIM16_MspDeInit 0 */
  315. /* Peripheral clock disable */
  316. __HAL_RCC_TIM16_CLK_DISABLE();
  317. /* USER CODE BEGIN TIM16_MspDeInit 1 */
  318. /* USER CODE END TIM16_MspDeInit 1 */
  319. }
  320. else if(htim_base->Instance==TIM17)
  321. {
  322. /* USER CODE BEGIN TIM17_MspDeInit 0 */
  323. /* USER CODE END TIM17_MspDeInit 0 */
  324. /* Peripheral clock disable */
  325. __HAL_RCC_TIM17_CLK_DISABLE();
  326. /* USER CODE BEGIN TIM17_MspDeInit 1 */
  327. /* USER CODE END TIM17_MspDeInit 1 */
  328. }
  329. }
  330. /**
  331. * @brief USART MSP Initialization
  332. * This function configures the hardware resources used in this example
  333. * @param husart: USART handle pointer
  334. * @retval None
  335. */
  336. void HAL_USART_MspInit(USART_HandleTypeDef* husart)
  337. {
  338. GPIO_InitTypeDef GPIO_InitStruct = {0};
  339. if(husart->Instance==USART1)
  340. {
  341. /* USER CODE BEGIN USART1_MspInit 0 */
  342. /* USER CODE END USART1_MspInit 0 */
  343. /* Peripheral clock enable */
  344. __HAL_RCC_USART1_CLK_ENABLE();
  345. __HAL_RCC_GPIOA_CLK_ENABLE();
  346. /**USART1 GPIO Configuration
  347. PA8 ------> USART1_CK
  348. PA9 ------> USART1_TX
  349. PA10 ------> USART1_RX
  350. */
  351. GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10;
  352. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  353. GPIO_InitStruct.Pull = GPIO_NOPULL;
  354. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  355. GPIO_InitStruct.Alternate = GPIO_AF1_USART1;
  356. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  357. /* USER CODE BEGIN USART1_MspInit 1 */
  358. /* USER CODE END USART1_MspInit 1 */
  359. }
  360. }
  361. /**
  362. * @brief UART MSP Initialization
  363. * This function configures the hardware resources used in this example
  364. * @param huart: UART handle pointer
  365. * @retval None
  366. */
  367. void HAL_UART_MspInit(UART_HandleTypeDef* huart)
  368. {
  369. GPIO_InitTypeDef GPIO_InitStruct = {0};
  370. if(huart->Instance==USART2)
  371. {
  372. /* USER CODE BEGIN USART2_MspInit 0 */
  373. /* USER CODE END USART2_MspInit 0 */
  374. /* Peripheral clock enable */
  375. __HAL_RCC_USART2_CLK_ENABLE();
  376. __HAL_RCC_GPIOA_CLK_ENABLE();
  377. /**USART2 GPIO Configuration
  378. PA2 ------> USART2_TX
  379. PA3 ------> USART2_RX
  380. */
  381. GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3;
  382. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  383. GPIO_InitStruct.Pull = GPIO_NOPULL;
  384. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  385. GPIO_InitStruct.Alternate = GPIO_AF1_USART2;
  386. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  387. /* USER CODE BEGIN USART2_MspInit 1 */
  388. /* USER CODE END USART2_MspInit 1 */
  389. }
  390. }
  391. /**
  392. * @brief USART MSP De-Initialization
  393. * This function freeze the hardware resources used in this example
  394. * @param husart: USART handle pointer
  395. * @retval None
  396. */
  397. void HAL_USART_MspDeInit(USART_HandleTypeDef* husart)
  398. {
  399. if(husart->Instance==USART1)
  400. {
  401. /* USER CODE BEGIN USART1_MspDeInit 0 */
  402. /* USER CODE END USART1_MspDeInit 0 */
  403. /* Peripheral clock disable */
  404. __HAL_RCC_USART1_CLK_DISABLE();
  405. /**USART1 GPIO Configuration
  406. PA8 ------> USART1_CK
  407. PA9 ------> USART1_TX
  408. PA10 ------> USART1_RX
  409. */
  410. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10);
  411. /* USER CODE BEGIN USART1_MspDeInit 1 */
  412. /* USER CODE END USART1_MspDeInit 1 */
  413. }
  414. }
  415. /**
  416. * @brief UART MSP De-Initialization
  417. * This function freeze the hardware resources used in this example
  418. * @param huart: UART handle pointer
  419. * @retval None
  420. */
  421. void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
  422. {
  423. if(huart->Instance==USART2)
  424. {
  425. /* USER CODE BEGIN USART2_MspDeInit 0 */
  426. /* USER CODE END USART2_MspDeInit 0 */
  427. /* Peripheral clock disable */
  428. __HAL_RCC_USART2_CLK_DISABLE();
  429. /**USART2 GPIO Configuration
  430. PA2 ------> USART2_TX
  431. PA3 ------> USART2_RX
  432. */
  433. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3);
  434. /* USER CODE BEGIN USART2_MspDeInit 1 */
  435. /* USER CODE END USART2_MspDeInit 1 */
  436. }
  437. }
  438. /* USER CODE BEGIN 1 */
  439. /* USER CODE END 1 */
  440. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/