stm32l4xx_hal_msp.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * File Name : stm32l4xx_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. #include <drv_common.h>
  45. /* USER CODE END Includes */
  46. /* Private typedef -----------------------------------------------------------*/
  47. /* USER CODE BEGIN TD */
  48. /* USER CODE END TD */
  49. /* Private define ------------------------------------------------------------*/
  50. /* USER CODE BEGIN Define */
  51. /* USER CODE END Define */
  52. /* Private macro -------------------------------------------------------------*/
  53. /* USER CODE BEGIN Macro */
  54. /* USER CODE END Macro */
  55. /* Private variables ---------------------------------------------------------*/
  56. /* USER CODE BEGIN PV */
  57. /* USER CODE END PV */
  58. /* Private function prototypes -----------------------------------------------*/
  59. /* USER CODE BEGIN PFP */
  60. /* USER CODE END PFP */
  61. /* External functions --------------------------------------------------------*/
  62. /* USER CODE BEGIN ExternalFunctions */
  63. /* USER CODE END ExternalFunctions */
  64. /* USER CODE BEGIN 0 */
  65. /* USER CODE END 0 */
  66. void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);
  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 ADC MSP Initialization
  82. * This function configures the hardware resources used in this example
  83. * @param hadc: ADC handle pointer
  84. * @retval None
  85. */
  86. void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
  87. {
  88. GPIO_InitTypeDef GPIO_InitStruct = {0};
  89. RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
  90. if(hadc->Instance==ADC1)
  91. {
  92. /* USER CODE BEGIN ADC1_MspInit 0 */
  93. /* USER CODE END ADC1_MspInit 0 */
  94. /** Initializes the peripherals clock
  95. */
  96. PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC;
  97. PeriphClkInit.AdcClockSelection = RCC_ADCCLKSOURCE_PLLSAI1;
  98. PeriphClkInit.PLLSAI1.PLLSAI1Source = RCC_PLLSOURCE_HSI;
  99. PeriphClkInit.PLLSAI1.PLLSAI1M = 1;
  100. PeriphClkInit.PLLSAI1.PLLSAI1N = 8;
  101. PeriphClkInit.PLLSAI1.PLLSAI1P = RCC_PLLP_DIV7;
  102. PeriphClkInit.PLLSAI1.PLLSAI1Q = RCC_PLLQ_DIV2;
  103. PeriphClkInit.PLLSAI1.PLLSAI1R = RCC_PLLR_DIV2;
  104. PeriphClkInit.PLLSAI1.PLLSAI1ClockOut = RCC_PLLSAI1_ADC1CLK;
  105. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  106. {
  107. Error_Handler();
  108. }
  109. /* Peripheral clock enable */
  110. __HAL_RCC_ADC_CLK_ENABLE();
  111. __HAL_RCC_GPIOC_CLK_ENABLE();
  112. __HAL_RCC_GPIOA_CLK_ENABLE();
  113. __HAL_RCC_GPIOB_CLK_ENABLE();
  114. /**ADC1 GPIO Configuration
  115. PC0 ------> ADC1_IN1
  116. PC1 ------> ADC1_IN2
  117. PA0 ------> ADC1_IN5
  118. PA1 ------> ADC1_IN6
  119. PA4 ------> ADC1_IN9
  120. PB0 ------> ADC1_IN15
  121. */
  122. GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1;
  123. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG_ADC_CONTROL;
  124. GPIO_InitStruct.Pull = GPIO_NOPULL;
  125. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  126. GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_4;
  127. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG_ADC_CONTROL;
  128. GPIO_InitStruct.Pull = GPIO_NOPULL;
  129. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  130. GPIO_InitStruct.Pin = GPIO_PIN_0;
  131. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG_ADC_CONTROL;
  132. GPIO_InitStruct.Pull = GPIO_NOPULL;
  133. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  134. /* USER CODE BEGIN ADC1_MspInit 1 */
  135. /* USER CODE END ADC1_MspInit 1 */
  136. }
  137. }
  138. /**
  139. * @brief ADC MSP De-Initialization
  140. * This function freeze the hardware resources used in this example
  141. * @param hadc: ADC handle pointer
  142. * @retval None
  143. */
  144. void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
  145. {
  146. if(hadc->Instance==ADC1)
  147. {
  148. /* USER CODE BEGIN ADC1_MspDeInit 0 */
  149. /* USER CODE END ADC1_MspDeInit 0 */
  150. /* Peripheral clock disable */
  151. __HAL_RCC_ADC_CLK_DISABLE();
  152. /**ADC1 GPIO Configuration
  153. PC0 ------> ADC1_IN1
  154. PC1 ------> ADC1_IN2
  155. PA0 ------> ADC1_IN5
  156. PA1 ------> ADC1_IN6
  157. PA4 ------> ADC1_IN9
  158. PB0 ------> ADC1_IN15
  159. */
  160. HAL_GPIO_DeInit(GPIOC, GPIO_PIN_0|GPIO_PIN_1);
  161. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_4);
  162. HAL_GPIO_DeInit(GPIOB, GPIO_PIN_0);
  163. /* USER CODE BEGIN ADC1_MspDeInit 1 */
  164. /* USER CODE END ADC1_MspDeInit 1 */
  165. }
  166. }
  167. /**
  168. * @brief LPTIM MSP Initialization
  169. * This function configures the hardware resources used in this example
  170. * @param hlptim: LPTIM handle pointer
  171. * @retval None
  172. */
  173. void HAL_LPTIM_MspInit(LPTIM_HandleTypeDef* hlptim)
  174. {
  175. RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
  176. if(hlptim->Instance==LPTIM1)
  177. {
  178. /* USER CODE BEGIN LPTIM1_MspInit 0 */
  179. /* USER CODE END LPTIM1_MspInit 0 */
  180. /** Initializes the peripherals clock
  181. */
  182. PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_LPTIM1;
  183. PeriphClkInit.Lptim1ClockSelection = RCC_LPTIM1CLKSOURCE_PCLK;
  184. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  185. {
  186. Error_Handler();
  187. }
  188. /* Peripheral clock enable */
  189. __HAL_RCC_LPTIM1_CLK_ENABLE();
  190. /* USER CODE BEGIN LPTIM1_MspInit 1 */
  191. /* USER CODE END LPTIM1_MspInit 1 */
  192. }
  193. }
  194. /**
  195. * @brief LPTIM MSP De-Initialization
  196. * This function freeze the hardware resources used in this example
  197. * @param hlptim: LPTIM handle pointer
  198. * @retval None
  199. */
  200. void HAL_LPTIM_MspDeInit(LPTIM_HandleTypeDef* hlptim)
  201. {
  202. if(hlptim->Instance==LPTIM1)
  203. {
  204. /* USER CODE BEGIN LPTIM1_MspDeInit 0 */
  205. /* USER CODE END LPTIM1_MspDeInit 0 */
  206. /* Peripheral clock disable */
  207. __HAL_RCC_LPTIM1_CLK_DISABLE();
  208. /* USER CODE BEGIN LPTIM1_MspDeInit 1 */
  209. /* USER CODE END LPTIM1_MspDeInit 1 */
  210. }
  211. }
  212. /**
  213. * @brief RTC MSP Initialization
  214. * This function configures the hardware resources used in this example
  215. * @param hrtc: RTC handle pointer
  216. * @retval None
  217. */
  218. void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc)
  219. {
  220. RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
  221. if(hrtc->Instance==RTC)
  222. {
  223. /* USER CODE BEGIN RTC_MspInit 0 */
  224. /* USER CODE END RTC_MspInit 0 */
  225. /** Initializes the peripherals clock
  226. */
  227. PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC;
  228. PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
  229. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  230. {
  231. Error_Handler();
  232. }
  233. /* Peripheral clock enable */
  234. __HAL_RCC_RTC_ENABLE();
  235. /* USER CODE BEGIN RTC_MspInit 1 */
  236. /* USER CODE END RTC_MspInit 1 */
  237. }
  238. }
  239. /**
  240. * @brief RTC MSP De-Initialization
  241. * This function freeze the hardware resources used in this example
  242. * @param hrtc: RTC handle pointer
  243. * @retval None
  244. */
  245. void HAL_RTC_MspDeInit(RTC_HandleTypeDef* hrtc)
  246. {
  247. if(hrtc->Instance==RTC)
  248. {
  249. /* USER CODE BEGIN RTC_MspDeInit 0 */
  250. /* USER CODE END RTC_MspDeInit 0 */
  251. /* Peripheral clock disable */
  252. __HAL_RCC_RTC_DISABLE();
  253. /* USER CODE BEGIN RTC_MspDeInit 1 */
  254. /* USER CODE END RTC_MspDeInit 1 */
  255. }
  256. }
  257. /**
  258. * @brief SPI MSP Initialization
  259. * This function configures the hardware resources used in this example
  260. * @param hspi: SPI handle pointer
  261. * @retval None
  262. */
  263. void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
  264. {
  265. GPIO_InitTypeDef GPIO_InitStruct = {0};
  266. if(hspi->Instance==SPI3)
  267. {
  268. /* USER CODE BEGIN SPI3_MspInit 0 */
  269. /* USER CODE END SPI3_MspInit 0 */
  270. /* Peripheral clock enable */
  271. __HAL_RCC_SPI3_CLK_ENABLE();
  272. __HAL_RCC_GPIOC_CLK_ENABLE();
  273. /**SPI3 GPIO Configuration
  274. PC10 ------> SPI3_SCK
  275. PC11 ------> SPI3_MISO
  276. PC12 ------> SPI3_MOSI
  277. */
  278. GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12;
  279. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  280. GPIO_InitStruct.Pull = GPIO_NOPULL;
  281. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  282. GPIO_InitStruct.Alternate = GPIO_AF6_SPI3;
  283. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  284. /* USER CODE BEGIN SPI3_MspInit 1 */
  285. /* USER CODE END SPI3_MspInit 1 */
  286. }
  287. }
  288. /**
  289. * @brief SPI MSP De-Initialization
  290. * This function freeze the hardware resources used in this example
  291. * @param hspi: SPI handle pointer
  292. * @retval None
  293. */
  294. void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
  295. {
  296. if(hspi->Instance==SPI3)
  297. {
  298. /* USER CODE BEGIN SPI3_MspDeInit 0 */
  299. /* USER CODE END SPI3_MspDeInit 0 */
  300. /* Peripheral clock disable */
  301. __HAL_RCC_SPI3_CLK_DISABLE();
  302. /**SPI3 GPIO Configuration
  303. PC10 ------> SPI3_SCK
  304. PC11 ------> SPI3_MISO
  305. PC12 ------> SPI3_MOSI
  306. */
  307. HAL_GPIO_DeInit(GPIOC, GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12);
  308. /* USER CODE BEGIN SPI3_MspDeInit 1 */
  309. /* USER CODE END SPI3_MspDeInit 1 */
  310. }
  311. }
  312. /**
  313. * @brief TIM_PWM MSP Initialization
  314. * This function configures the hardware resources used in this example
  315. * @param htim_pwm: TIM_PWM handle pointer
  316. * @retval None
  317. */
  318. void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef* htim_pwm)
  319. {
  320. if(htim_pwm->Instance==TIM2)
  321. {
  322. /* USER CODE BEGIN TIM2_MspInit 0 */
  323. /* USER CODE END TIM2_MspInit 0 */
  324. /* Peripheral clock enable */
  325. __HAL_RCC_TIM2_CLK_ENABLE();
  326. /* USER CODE BEGIN TIM2_MspInit 1 */
  327. /* USER CODE END TIM2_MspInit 1 */
  328. }
  329. else if(htim_pwm->Instance==TIM3)
  330. {
  331. /* USER CODE BEGIN TIM3_MspInit 0 */
  332. /* USER CODE END TIM3_MspInit 0 */
  333. /* Peripheral clock enable */
  334. __HAL_RCC_TIM3_CLK_ENABLE();
  335. /* USER CODE BEGIN TIM3_MspInit 1 */
  336. /* USER CODE END TIM3_MspInit 1 */
  337. }
  338. else if(htim_pwm->Instance==TIM4)
  339. {
  340. /* USER CODE BEGIN TIM4_MspInit 0 */
  341. /* USER CODE END TIM4_MspInit 0 */
  342. /* Peripheral clock enable */
  343. __HAL_RCC_TIM4_CLK_ENABLE();
  344. /* USER CODE BEGIN TIM4_MspInit 1 */
  345. /* USER CODE END TIM4_MspInit 1 */
  346. }
  347. }
  348. /**
  349. * @brief TIM_Base MSP Initialization
  350. * This function configures the hardware resources used in this example
  351. * @param htim_base: TIM_Base handle pointer
  352. * @retval None
  353. */
  354. void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
  355. {
  356. if(htim_base->Instance==TIM15)
  357. {
  358. /* USER CODE BEGIN TIM15_MspInit 0 */
  359. /* USER CODE END TIM15_MspInit 0 */
  360. /* Peripheral clock enable */
  361. __HAL_RCC_TIM15_CLK_ENABLE();
  362. /* USER CODE BEGIN TIM15_MspInit 1 */
  363. /* USER CODE END TIM15_MspInit 1 */
  364. }
  365. else if(htim_base->Instance==TIM16)
  366. {
  367. /* USER CODE BEGIN TIM16_MspInit 0 */
  368. /* USER CODE END TIM16_MspInit 0 */
  369. /* Peripheral clock enable */
  370. __HAL_RCC_TIM16_CLK_ENABLE();
  371. /* USER CODE BEGIN TIM16_MspInit 1 */
  372. /* USER CODE END TIM16_MspInit 1 */
  373. }
  374. else if(htim_base->Instance==TIM17)
  375. {
  376. /* USER CODE BEGIN TIM17_MspInit 0 */
  377. /* USER CODE END TIM17_MspInit 0 */
  378. /* Peripheral clock enable */
  379. __HAL_RCC_TIM17_CLK_ENABLE();
  380. /* USER CODE BEGIN TIM17_MspInit 1 */
  381. /* USER CODE END TIM17_MspInit 1 */
  382. }
  383. }
  384. void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
  385. {
  386. GPIO_InitTypeDef GPIO_InitStruct = {0};
  387. if(htim->Instance==TIM2)
  388. {
  389. /* USER CODE BEGIN TIM2_MspPostInit 0 */
  390. /* USER CODE END TIM2_MspPostInit 0 */
  391. __HAL_RCC_GPIOB_CLK_ENABLE();
  392. /**TIM2 GPIO Configuration
  393. PB10 ------> TIM2_CH3
  394. PB3 (JTDO-TRACESWO) ------> TIM2_CH2
  395. */
  396. GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_3;
  397. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  398. GPIO_InitStruct.Pull = GPIO_NOPULL;
  399. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  400. GPIO_InitStruct.Alternate = GPIO_AF1_TIM2;
  401. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  402. /* USER CODE BEGIN TIM2_MspPostInit 1 */
  403. /* USER CODE END TIM2_MspPostInit 1 */
  404. }
  405. else if(htim->Instance==TIM3)
  406. {
  407. /* USER CODE BEGIN TIM3_MspPostInit 0 */
  408. /* USER CODE END TIM3_MspPostInit 0 */
  409. __HAL_RCC_GPIOC_CLK_ENABLE();
  410. __HAL_RCC_GPIOB_CLK_ENABLE();
  411. /**TIM3 GPIO Configuration
  412. PC7 ------> TIM3_CH2
  413. PB4 (NJTRST) ------> TIM3_CH1
  414. */
  415. GPIO_InitStruct.Pin = GPIO_PIN_7;
  416. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  417. GPIO_InitStruct.Pull = GPIO_NOPULL;
  418. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  419. GPIO_InitStruct.Alternate = GPIO_AF2_TIM3;
  420. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  421. GPIO_InitStruct.Pin = GPIO_PIN_4;
  422. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  423. GPIO_InitStruct.Pull = GPIO_NOPULL;
  424. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  425. GPIO_InitStruct.Alternate = GPIO_AF2_TIM3;
  426. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  427. /* USER CODE BEGIN TIM3_MspPostInit 1 */
  428. /* USER CODE END TIM3_MspPostInit 1 */
  429. }
  430. else if(htim->Instance==TIM4)
  431. {
  432. /* USER CODE BEGIN TIM4_MspPostInit 0 */
  433. /* USER CODE END TIM4_MspPostInit 0 */
  434. __HAL_RCC_GPIOB_CLK_ENABLE();
  435. /**TIM4 GPIO Configuration
  436. PB6 ------> TIM4_CH1
  437. */
  438. GPIO_InitStruct.Pin = GPIO_PIN_6;
  439. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  440. GPIO_InitStruct.Pull = GPIO_NOPULL;
  441. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  442. GPIO_InitStruct.Alternate = GPIO_AF2_TIM4;
  443. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  444. /* USER CODE BEGIN TIM4_MspPostInit 1 */
  445. /* USER CODE END TIM4_MspPostInit 1 */
  446. }
  447. else if(htim->Instance==TIM17)
  448. {
  449. /* USER CODE BEGIN TIM17_MspPostInit 0 */
  450. /* USER CODE END TIM17_MspPostInit 0 */
  451. __HAL_RCC_GPIOA_CLK_ENABLE();
  452. /**TIM17 GPIO Configuration
  453. PA7 ------> TIM17_CH1
  454. */
  455. GPIO_InitStruct.Pin = GPIO_PIN_7;
  456. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  457. GPIO_InitStruct.Pull = GPIO_NOPULL;
  458. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  459. GPIO_InitStruct.Alternate = GPIO_AF14_TIM17;
  460. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  461. /* USER CODE BEGIN TIM17_MspPostInit 1 */
  462. /* USER CODE END TIM17_MspPostInit 1 */
  463. }
  464. }
  465. /**
  466. * @brief TIM_PWM MSP De-Initialization
  467. * This function freeze the hardware resources used in this example
  468. * @param htim_pwm: TIM_PWM handle pointer
  469. * @retval None
  470. */
  471. void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef* htim_pwm)
  472. {
  473. if(htim_pwm->Instance==TIM2)
  474. {
  475. /* USER CODE BEGIN TIM2_MspDeInit 0 */
  476. /* USER CODE END TIM2_MspDeInit 0 */
  477. /* Peripheral clock disable */
  478. __HAL_RCC_TIM2_CLK_DISABLE();
  479. /* USER CODE BEGIN TIM2_MspDeInit 1 */
  480. /* USER CODE END TIM2_MspDeInit 1 */
  481. }
  482. else if(htim_pwm->Instance==TIM3)
  483. {
  484. /* USER CODE BEGIN TIM3_MspDeInit 0 */
  485. /* USER CODE END TIM3_MspDeInit 0 */
  486. /* Peripheral clock disable */
  487. __HAL_RCC_TIM3_CLK_DISABLE();
  488. /* USER CODE BEGIN TIM3_MspDeInit 1 */
  489. /* USER CODE END TIM3_MspDeInit 1 */
  490. }
  491. else if(htim_pwm->Instance==TIM4)
  492. {
  493. /* USER CODE BEGIN TIM4_MspDeInit 0 */
  494. /* USER CODE END TIM4_MspDeInit 0 */
  495. /* Peripheral clock disable */
  496. __HAL_RCC_TIM4_CLK_DISABLE();
  497. /* USER CODE BEGIN TIM4_MspDeInit 1 */
  498. /* USER CODE END TIM4_MspDeInit 1 */
  499. }
  500. }
  501. /**
  502. * @brief TIM_Base MSP De-Initialization
  503. * This function freeze the hardware resources used in this example
  504. * @param htim_base: TIM_Base handle pointer
  505. * @retval None
  506. */
  507. void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
  508. {
  509. if(htim_base->Instance==TIM15)
  510. {
  511. /* USER CODE BEGIN TIM15_MspDeInit 0 */
  512. /* USER CODE END TIM15_MspDeInit 0 */
  513. /* Peripheral clock disable */
  514. __HAL_RCC_TIM15_CLK_DISABLE();
  515. /* USER CODE BEGIN TIM15_MspDeInit 1 */
  516. /* USER CODE END TIM15_MspDeInit 1 */
  517. }
  518. else if(htim_base->Instance==TIM16)
  519. {
  520. /* USER CODE BEGIN TIM16_MspDeInit 0 */
  521. /* USER CODE END TIM16_MspDeInit 0 */
  522. /* Peripheral clock disable */
  523. __HAL_RCC_TIM16_CLK_DISABLE();
  524. /* USER CODE BEGIN TIM16_MspDeInit 1 */
  525. /* USER CODE END TIM16_MspDeInit 1 */
  526. }
  527. else if(htim_base->Instance==TIM17)
  528. {
  529. /* USER CODE BEGIN TIM17_MspDeInit 0 */
  530. /* USER CODE END TIM17_MspDeInit 0 */
  531. /* Peripheral clock disable */
  532. __HAL_RCC_TIM17_CLK_DISABLE();
  533. /* USER CODE BEGIN TIM17_MspDeInit 1 */
  534. /* USER CODE END TIM17_MspDeInit 1 */
  535. }
  536. }
  537. /**
  538. * @brief UART MSP Initialization
  539. * This function configures the hardware resources used in this example
  540. * @param huart: UART handle pointer
  541. * @retval None
  542. */
  543. void HAL_UART_MspInit(UART_HandleTypeDef* huart)
  544. {
  545. GPIO_InitTypeDef GPIO_InitStruct = {0};
  546. RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
  547. if(huart->Instance==USART2)
  548. {
  549. /* USER CODE BEGIN USART2_MspInit 0 */
  550. /* USER CODE END USART2_MspInit 0 */
  551. /** Initializes the peripherals clock
  552. */
  553. PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART2;
  554. PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;
  555. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  556. {
  557. Error_Handler();
  558. }
  559. /* Peripheral clock enable */
  560. __HAL_RCC_USART2_CLK_ENABLE();
  561. __HAL_RCC_GPIOA_CLK_ENABLE();
  562. /**USART2 GPIO Configuration
  563. PA2 ------> USART2_TX
  564. PA3 ------> USART2_RX
  565. */
  566. GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3;
  567. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  568. GPIO_InitStruct.Pull = GPIO_PULLUP;
  569. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  570. GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
  571. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  572. /* USER CODE BEGIN USART2_MspInit 1 */
  573. /* USER CODE END USART2_MspInit 1 */
  574. }
  575. }
  576. /**
  577. * @brief UART MSP De-Initialization
  578. * This function freeze the hardware resources used in this example
  579. * @param huart: UART handle pointer
  580. * @retval None
  581. */
  582. void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
  583. {
  584. if(huart->Instance==USART2)
  585. {
  586. /* USER CODE BEGIN USART2_MspDeInit 0 */
  587. /* USER CODE END USART2_MspDeInit 0 */
  588. /* Peripheral clock disable */
  589. __HAL_RCC_USART2_CLK_DISABLE();
  590. /**USART2 GPIO Configuration
  591. PA2 ------> USART2_TX
  592. PA3 ------> USART2_RX
  593. */
  594. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3);
  595. /* USER CODE BEGIN USART2_MspDeInit 1 */
  596. /* USER CODE END USART2_MspDeInit 1 */
  597. }
  598. }
  599. /* USER CODE BEGIN 1 */
  600. /* USER CODE END 1 */