stm32l4xx_hal_msp.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921
  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. * @attention
  9. *
  10. * <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
  11. * All rights reserved.</center></h2>
  12. *
  13. * This software component is licensed by ST under BSD 3-Clause license,
  14. * the "License"; You may not use this file except in compliance with the
  15. * License. You may obtain a copy of the License at:
  16. * opensource.org/licenses/BSD-3-Clause
  17. *
  18. ******************************************************************************
  19. */
  20. /* USER CODE END Header */
  21. /* Includes ------------------------------------------------------------------*/
  22. #include "main.h"
  23. /* USER CODE BEGIN Includes */
  24. #include <drv_common.h>
  25. /* USER CODE END Includes */
  26. /* Private typedef -----------------------------------------------------------*/
  27. /* USER CODE BEGIN TD */
  28. /* USER CODE END TD */
  29. /* Private define ------------------------------------------------------------*/
  30. /* USER CODE BEGIN Define */
  31. /* USER CODE END Define */
  32. /* Private macro -------------------------------------------------------------*/
  33. /* USER CODE BEGIN Macro */
  34. /* USER CODE END Macro */
  35. /* Private variables ---------------------------------------------------------*/
  36. /* USER CODE BEGIN PV */
  37. /* USER CODE END PV */
  38. /* Private function prototypes -----------------------------------------------*/
  39. /* USER CODE BEGIN PFP */
  40. /* USER CODE END PFP */
  41. /* External functions --------------------------------------------------------*/
  42. /* USER CODE BEGIN ExternalFunctions */
  43. /* USER CODE END ExternalFunctions */
  44. /* USER CODE BEGIN 0 */
  45. /* USER CODE END 0 */
  46. void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);
  47. /**
  48. * Initializes the Global MSP.
  49. */
  50. void HAL_MspInit(void)
  51. {
  52. /* USER CODE BEGIN MspInit 0 */
  53. /* USER CODE END MspInit 0 */
  54. __HAL_RCC_SYSCFG_CLK_ENABLE();
  55. __HAL_RCC_PWR_CLK_ENABLE();
  56. /* System interrupt init*/
  57. /* USER CODE BEGIN MspInit 1 */
  58. /* USER CODE END MspInit 1 */
  59. }
  60. /**
  61. * @brief ADC MSP Initialization
  62. * This function configures the hardware resources used in this example
  63. * @param hadc: ADC handle pointer
  64. * @retval None
  65. */
  66. void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
  67. {
  68. GPIO_InitTypeDef GPIO_InitStruct = {0};
  69. if(hadc->Instance==ADC1)
  70. {
  71. /* USER CODE BEGIN ADC1_MspInit 0 */
  72. /* USER CODE END ADC1_MspInit 0 */
  73. /* Peripheral clock enable */
  74. __HAL_RCC_ADC_CLK_ENABLE();
  75. __HAL_RCC_GPIOC_CLK_ENABLE();
  76. /**ADC1 GPIO Configuration
  77. PC0 ------> ADC1_IN1
  78. PC1 ------> ADC1_IN2
  79. */
  80. GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1;
  81. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  82. GPIO_InitStruct.Pull = GPIO_NOPULL;
  83. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  84. /* USER CODE BEGIN ADC1_MspInit 1 */
  85. /* USER CODE END ADC1_MspInit 1 */
  86. }
  87. }
  88. /**
  89. * @brief ADC MSP De-Initialization
  90. * This function freeze the hardware resources used in this example
  91. * @param hadc: ADC handle pointer
  92. * @retval None
  93. */
  94. void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
  95. {
  96. if(hadc->Instance==ADC1)
  97. {
  98. /* USER CODE BEGIN ADC1_MspDeInit 0 */
  99. /* USER CODE END ADC1_MspDeInit 0 */
  100. /* Peripheral clock disable */
  101. __HAL_RCC_ADC_CLK_DISABLE();
  102. /**ADC1 GPIO Configuration
  103. PC0 ------> ADC1_IN1
  104. PC1 ------> ADC1_IN2
  105. */
  106. HAL_GPIO_DeInit(GPIOC, GPIO_PIN_0|GPIO_PIN_1);
  107. /* USER CODE BEGIN ADC1_MspDeInit 1 */
  108. /* USER CODE END ADC1_MspDeInit 1 */
  109. }
  110. }
  111. /**
  112. * @brief CAN MSP Initialization
  113. * This function configures the hardware resources used in this example
  114. * @param hcan: CAN handle pointer
  115. * @retval None
  116. */
  117. void HAL_CAN_MspInit(CAN_HandleTypeDef* hcan)
  118. {
  119. GPIO_InitTypeDef GPIO_InitStruct = {0};
  120. if(hcan->Instance==CAN1)
  121. {
  122. /* USER CODE BEGIN CAN1_MspInit 0 */
  123. /* USER CODE END CAN1_MspInit 0 */
  124. /* Peripheral clock enable */
  125. __HAL_RCC_CAN1_CLK_ENABLE();
  126. __HAL_RCC_GPIOD_CLK_ENABLE();
  127. /**CAN1 GPIO Configuration
  128. PD0 ------> CAN1_RX
  129. PD1 ------> CAN1_TX
  130. */
  131. GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1;
  132. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  133. GPIO_InitStruct.Pull = GPIO_NOPULL;
  134. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  135. GPIO_InitStruct.Alternate = GPIO_AF9_CAN1;
  136. HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  137. /* USER CODE BEGIN CAN1_MspInit 1 */
  138. /* USER CODE END CAN1_MspInit 1 */
  139. }
  140. }
  141. /**
  142. * @brief CAN MSP De-Initialization
  143. * This function freeze the hardware resources used in this example
  144. * @param hcan: CAN handle pointer
  145. * @retval None
  146. */
  147. void HAL_CAN_MspDeInit(CAN_HandleTypeDef* hcan)
  148. {
  149. if(hcan->Instance==CAN1)
  150. {
  151. /* USER CODE BEGIN CAN1_MspDeInit 0 */
  152. /* USER CODE END CAN1_MspDeInit 0 */
  153. /* Peripheral clock disable */
  154. __HAL_RCC_CAN1_CLK_DISABLE();
  155. /**CAN1 GPIO Configuration
  156. PD0 ------> CAN1_RX
  157. PD1 ------> CAN1_TX
  158. */
  159. HAL_GPIO_DeInit(GPIOD, GPIO_PIN_0|GPIO_PIN_1);
  160. /* USER CODE BEGIN CAN1_MspDeInit 1 */
  161. /* USER CODE END CAN1_MspDeInit 1 */
  162. }
  163. }
  164. /**
  165. * @brief DAC MSP Initialization
  166. * This function configures the hardware resources used in this example
  167. * @param hdac: DAC handle pointer
  168. * @retval None
  169. */
  170. void HAL_DAC_MspInit(DAC_HandleTypeDef* hdac)
  171. {
  172. GPIO_InitTypeDef GPIO_InitStruct = {0};
  173. if(hdac->Instance==DAC1)
  174. {
  175. /* USER CODE BEGIN DAC1_MspInit 0 */
  176. /* USER CODE END DAC1_MspInit 0 */
  177. /* Peripheral clock enable */
  178. __HAL_RCC_DAC1_CLK_ENABLE();
  179. __HAL_RCC_GPIOA_CLK_ENABLE();
  180. /**DAC1 GPIO Configuration
  181. PA4 ------> DAC1_OUT1
  182. */
  183. GPIO_InitStruct.Pin = GPIO_PIN_4;
  184. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  185. GPIO_InitStruct.Pull = GPIO_NOPULL;
  186. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  187. /* USER CODE BEGIN DAC1_MspInit 1 */
  188. /* USER CODE END DAC1_MspInit 1 */
  189. }
  190. }
  191. /**
  192. * @brief DAC MSP De-Initialization
  193. * This function freeze the hardware resources used in this example
  194. * @param hdac: DAC handle pointer
  195. * @retval None
  196. */
  197. void HAL_DAC_MspDeInit(DAC_HandleTypeDef* hdac)
  198. {
  199. if(hdac->Instance==DAC1)
  200. {
  201. /* USER CODE BEGIN DAC1_MspDeInit 0 */
  202. /* USER CODE END DAC1_MspDeInit 0 */
  203. /* Peripheral clock disable */
  204. __HAL_RCC_DAC1_CLK_DISABLE();
  205. /**DAC1 GPIO Configuration
  206. PA4 ------> DAC1_OUT1
  207. */
  208. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_4);
  209. /* USER CODE BEGIN DAC1_MspDeInit 1 */
  210. /* USER CODE END DAC1_MspDeInit 1 */
  211. }
  212. }
  213. /**
  214. * @brief I2C MSP Initialization
  215. * This function configures the hardware resources used in this example
  216. * @param hi2c: I2C handle pointer
  217. * @retval None
  218. */
  219. void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c)
  220. {
  221. GPIO_InitTypeDef GPIO_InitStruct = {0};
  222. RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
  223. if(hi2c->Instance==I2C1)
  224. {
  225. /* USER CODE BEGIN I2C1_MspInit 0 */
  226. /* USER CODE END I2C1_MspInit 0 */
  227. /** Initializes the peripherals clock
  228. */
  229. PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_I2C1;
  230. PeriphClkInit.I2c1ClockSelection = RCC_I2C1CLKSOURCE_PCLK1;
  231. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  232. {
  233. Error_Handler();
  234. }
  235. __HAL_RCC_GPIOG_CLK_ENABLE();
  236. HAL_PWREx_EnableVddIO2();
  237. /**I2C1 GPIO Configuration
  238. PG13 ------> I2C1_SDA
  239. PG14 ------> I2C1_SCL
  240. */
  241. GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_14;
  242. GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
  243. GPIO_InitStruct.Pull = GPIO_NOPULL;
  244. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  245. GPIO_InitStruct.Alternate = GPIO_AF4_I2C1;
  246. HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
  247. /* Peripheral clock enable */
  248. __HAL_RCC_I2C1_CLK_ENABLE();
  249. /* USER CODE BEGIN I2C1_MspInit 1 */
  250. /* USER CODE END I2C1_MspInit 1 */
  251. }
  252. }
  253. /**
  254. * @brief I2C MSP De-Initialization
  255. * This function freeze the hardware resources used in this example
  256. * @param hi2c: I2C handle pointer
  257. * @retval None
  258. */
  259. void HAL_I2C_MspDeInit(I2C_HandleTypeDef* hi2c)
  260. {
  261. if(hi2c->Instance==I2C1)
  262. {
  263. /* USER CODE BEGIN I2C1_MspDeInit 0 */
  264. /* USER CODE END I2C1_MspDeInit 0 */
  265. /* Peripheral clock disable */
  266. __HAL_RCC_I2C1_CLK_DISABLE();
  267. /**I2C1 GPIO Configuration
  268. PG13 ------> I2C1_SDA
  269. PG14 ------> I2C1_SCL
  270. */
  271. HAL_GPIO_DeInit(GPIOG, GPIO_PIN_13);
  272. HAL_GPIO_DeInit(GPIOG, GPIO_PIN_14);
  273. /* USER CODE BEGIN I2C1_MspDeInit 1 */
  274. /* USER CODE END I2C1_MspDeInit 1 */
  275. }
  276. }
  277. /**
  278. * @brief UART MSP Initialization
  279. * This function configures the hardware resources used in this example
  280. * @param huart: UART handle pointer
  281. * @retval None
  282. */
  283. void HAL_UART_MspInit(UART_HandleTypeDef* huart)
  284. {
  285. GPIO_InitTypeDef GPIO_InitStruct = {0};
  286. RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
  287. if(huart->Instance==LPUART1)
  288. {
  289. /* USER CODE BEGIN LPUART1_MspInit 0 */
  290. /* USER CODE END LPUART1_MspInit 0 */
  291. /** Initializes the peripherals clock
  292. */
  293. PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_LPUART1;
  294. PeriphClkInit.Lpuart1ClockSelection = RCC_LPUART1CLKSOURCE_PCLK1;
  295. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  296. {
  297. Error_Handler();
  298. }
  299. /* Peripheral clock enable */
  300. __HAL_RCC_LPUART1_CLK_ENABLE();
  301. __HAL_RCC_GPIOG_CLK_ENABLE();
  302. HAL_PWREx_EnableVddIO2();
  303. /**LPUART1 GPIO Configuration
  304. PG7 ------> LPUART1_TX
  305. PG8 ------> LPUART1_RX
  306. */
  307. GPIO_InitStruct.Pin = STLK_RX_Pin|STLK_TX_Pin;
  308. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  309. GPIO_InitStruct.Pull = GPIO_NOPULL;
  310. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  311. GPIO_InitStruct.Alternate = GPIO_AF8_LPUART1;
  312. HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
  313. /* USER CODE BEGIN LPUART1_MspInit 1 */
  314. /* USER CODE END LPUART1_MspInit 1 */
  315. }
  316. }
  317. /**
  318. * @brief UART MSP De-Initialization
  319. * This function freeze the hardware resources used in this example
  320. * @param huart: UART handle pointer
  321. * @retval None
  322. */
  323. void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
  324. {
  325. if(huart->Instance==LPUART1)
  326. {
  327. /* USER CODE BEGIN LPUART1_MspDeInit 0 */
  328. /* USER CODE END LPUART1_MspDeInit 0 */
  329. /* Peripheral clock disable */
  330. __HAL_RCC_LPUART1_CLK_DISABLE();
  331. /**LPUART1 GPIO Configuration
  332. PG7 ------> LPUART1_TX
  333. PG8 ------> LPUART1_RX
  334. */
  335. HAL_GPIO_DeInit(GPIOG, STLK_RX_Pin|STLK_TX_Pin);
  336. /* USER CODE BEGIN LPUART1_MspDeInit 1 */
  337. /* USER CODE END LPUART1_MspDeInit 1 */
  338. }
  339. }
  340. /**
  341. * @brief QSPI MSP Initialization
  342. * This function configures the hardware resources used in this example
  343. * @param hqspi: QSPI handle pointer
  344. * @retval None
  345. */
  346. void HAL_QSPI_MspInit(QSPI_HandleTypeDef* hqspi)
  347. {
  348. GPIO_InitTypeDef GPIO_InitStruct = {0};
  349. if(hqspi->Instance==QUADSPI)
  350. {
  351. /* USER CODE BEGIN QUADSPI_MspInit 0 */
  352. /* USER CODE END QUADSPI_MspInit 0 */
  353. /* Peripheral clock enable */
  354. __HAL_RCC_QSPI_CLK_ENABLE();
  355. __HAL_RCC_GPIOF_CLK_ENABLE();
  356. __HAL_RCC_GPIOE_CLK_ENABLE();
  357. /**QUADSPI GPIO Configuration
  358. PF8 ------> QUADSPI_BK1_IO0
  359. PF9 ------> QUADSPI_BK1_IO1
  360. PF10 ------> QUADSPI_CLK
  361. PE11 ------> QUADSPI_BK1_NCS
  362. */
  363. GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9;
  364. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  365. GPIO_InitStruct.Pull = GPIO_NOPULL;
  366. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  367. GPIO_InitStruct.Alternate = GPIO_AF10_QUADSPI;
  368. HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
  369. GPIO_InitStruct.Pin = GPIO_PIN_10;
  370. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  371. GPIO_InitStruct.Pull = GPIO_NOPULL;
  372. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  373. GPIO_InitStruct.Alternate = GPIO_AF3_QUADSPI;
  374. HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
  375. GPIO_InitStruct.Pin = GPIO_PIN_11;
  376. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  377. GPIO_InitStruct.Pull = GPIO_NOPULL;
  378. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  379. GPIO_InitStruct.Alternate = GPIO_AF10_QUADSPI;
  380. HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
  381. /* USER CODE BEGIN QUADSPI_MspInit 1 */
  382. /* USER CODE END QUADSPI_MspInit 1 */
  383. }
  384. }
  385. /**
  386. * @brief QSPI MSP De-Initialization
  387. * This function freeze the hardware resources used in this example
  388. * @param hqspi: QSPI handle pointer
  389. * @retval None
  390. */
  391. void HAL_QSPI_MspDeInit(QSPI_HandleTypeDef* hqspi)
  392. {
  393. if(hqspi->Instance==QUADSPI)
  394. {
  395. /* USER CODE BEGIN QUADSPI_MspDeInit 0 */
  396. /* USER CODE END QUADSPI_MspDeInit 0 */
  397. /* Peripheral clock disable */
  398. __HAL_RCC_QSPI_CLK_DISABLE();
  399. /**QUADSPI GPIO Configuration
  400. PF8 ------> QUADSPI_BK1_IO0
  401. PF9 ------> QUADSPI_BK1_IO1
  402. PF10 ------> QUADSPI_CLK
  403. PE11 ------> QUADSPI_BK1_NCS
  404. */
  405. HAL_GPIO_DeInit(GPIOF, GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10);
  406. HAL_GPIO_DeInit(GPIOE, GPIO_PIN_11);
  407. /* USER CODE BEGIN QUADSPI_MspDeInit 1 */
  408. /* USER CODE END QUADSPI_MspDeInit 1 */
  409. }
  410. }
  411. /**
  412. * @brief RTC MSP Initialization
  413. * This function configures the hardware resources used in this example
  414. * @param hrtc: RTC handle pointer
  415. * @retval None
  416. */
  417. void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc)
  418. {
  419. RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
  420. if(hrtc->Instance==RTC)
  421. {
  422. /* USER CODE BEGIN RTC_MspInit 0 */
  423. /* USER CODE END RTC_MspInit 0 */
  424. /** Initializes the peripherals clock
  425. */
  426. PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC;
  427. PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
  428. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  429. {
  430. Error_Handler();
  431. }
  432. /* Peripheral clock enable */
  433. __HAL_RCC_RTC_ENABLE();
  434. /* USER CODE BEGIN RTC_MspInit 1 */
  435. /* USER CODE END RTC_MspInit 1 */
  436. }
  437. }
  438. /**
  439. * @brief RTC MSP De-Initialization
  440. * This function freeze the hardware resources used in this example
  441. * @param hrtc: RTC handle pointer
  442. * @retval None
  443. */
  444. void HAL_RTC_MspDeInit(RTC_HandleTypeDef* hrtc)
  445. {
  446. if(hrtc->Instance==RTC)
  447. {
  448. /* USER CODE BEGIN RTC_MspDeInit 0 */
  449. /* USER CODE END RTC_MspDeInit 0 */
  450. /* Peripheral clock disable */
  451. __HAL_RCC_RTC_DISABLE();
  452. /* USER CODE BEGIN RTC_MspDeInit 1 */
  453. /* USER CODE END RTC_MspDeInit 1 */
  454. }
  455. }
  456. /**
  457. * @brief SPI MSP Initialization
  458. * This function configures the hardware resources used in this example
  459. * @param hspi: SPI handle pointer
  460. * @retval None
  461. */
  462. void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
  463. {
  464. GPIO_InitTypeDef GPIO_InitStruct = {0};
  465. if(hspi->Instance==SPI1)
  466. {
  467. /* USER CODE BEGIN SPI1_MspInit 0 */
  468. /* USER CODE END SPI1_MspInit 0 */
  469. /* Peripheral clock enable */
  470. __HAL_RCC_SPI1_CLK_ENABLE();
  471. __HAL_RCC_GPIOA_CLK_ENABLE();
  472. /**SPI1 GPIO Configuration
  473. PA1 ------> SPI1_SCK
  474. PA6 ------> SPI1_MISO
  475. PA7 ------> SPI1_MOSI
  476. */
  477. GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_6|GPIO_PIN_7;
  478. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  479. GPIO_InitStruct.Pull = GPIO_NOPULL;
  480. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  481. GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
  482. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  483. /* USER CODE BEGIN SPI1_MspInit 1 */
  484. /* USER CODE END SPI1_MspInit 1 */
  485. }
  486. }
  487. /**
  488. * @brief SPI MSP De-Initialization
  489. * This function freeze the hardware resources used in this example
  490. * @param hspi: SPI handle pointer
  491. * @retval None
  492. */
  493. void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
  494. {
  495. if(hspi->Instance==SPI1)
  496. {
  497. /* USER CODE BEGIN SPI1_MspDeInit 0 */
  498. /* USER CODE END SPI1_MspDeInit 0 */
  499. /* Peripheral clock disable */
  500. __HAL_RCC_SPI1_CLK_DISABLE();
  501. /**SPI1 GPIO Configuration
  502. PA1 ------> SPI1_SCK
  503. PA6 ------> SPI1_MISO
  504. PA7 ------> SPI1_MOSI
  505. */
  506. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_1|GPIO_PIN_6|GPIO_PIN_7);
  507. /* USER CODE BEGIN SPI1_MspDeInit 1 */
  508. /* USER CODE END SPI1_MspDeInit 1 */
  509. }
  510. }
  511. /**
  512. * @brief TIM_PWM MSP Initialization
  513. * This function configures the hardware resources used in this example
  514. * @param htim_pwm: TIM_PWM handle pointer
  515. * @retval None
  516. */
  517. void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef* htim_pwm)
  518. {
  519. if(htim_pwm->Instance==TIM2)
  520. {
  521. /* USER CODE BEGIN TIM2_MspInit 0 */
  522. /* USER CODE END TIM2_MspInit 0 */
  523. /* Peripheral clock enable */
  524. __HAL_RCC_TIM2_CLK_ENABLE();
  525. /* USER CODE BEGIN TIM2_MspInit 1 */
  526. /* USER CODE END TIM2_MspInit 1 */
  527. }
  528. else if(htim_pwm->Instance==TIM4)
  529. {
  530. /* USER CODE BEGIN TIM4_MspInit 0 */
  531. /* USER CODE END TIM4_MspInit 0 */
  532. /* Peripheral clock enable */
  533. __HAL_RCC_TIM4_CLK_ENABLE();
  534. /* USER CODE BEGIN TIM4_MspInit 1 */
  535. /* USER CODE END TIM4_MspInit 1 */
  536. }
  537. }
  538. void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
  539. {
  540. GPIO_InitTypeDef GPIO_InitStruct = {0};
  541. if(htim->Instance==TIM2)
  542. {
  543. /* USER CODE BEGIN TIM2_MspPostInit 0 */
  544. /* USER CODE END TIM2_MspPostInit 0 */
  545. __HAL_RCC_GPIOA_CLK_ENABLE();
  546. /**TIM2 GPIO Configuration
  547. PA2 ------> TIM2_CH3
  548. PA3 ------> TIM2_CH4
  549. */
  550. GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3;
  551. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  552. GPIO_InitStruct.Pull = GPIO_NOPULL;
  553. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  554. GPIO_InitStruct.Alternate = GPIO_AF1_TIM2;
  555. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  556. /* USER CODE BEGIN TIM2_MspPostInit 1 */
  557. /* USER CODE END TIM2_MspPostInit 1 */
  558. }
  559. else if(htim->Instance==TIM4)
  560. {
  561. /* USER CODE BEGIN TIM4_MspPostInit 0 */
  562. /* USER CODE END TIM4_MspPostInit 0 */
  563. __HAL_RCC_GPIOD_CLK_ENABLE();
  564. /**TIM4 GPIO Configuration
  565. PD12 ------> TIM4_CH1
  566. PD13 ------> TIM4_CH2
  567. PD14 ------> TIM4_CH3
  568. PD15 ------> TIM4_CH4
  569. */
  570. GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
  571. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  572. GPIO_InitStruct.Pull = GPIO_NOPULL;
  573. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  574. GPIO_InitStruct.Alternate = GPIO_AF2_TIM4;
  575. HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  576. /* USER CODE BEGIN TIM4_MspPostInit 1 */
  577. /* USER CODE END TIM4_MspPostInit 1 */
  578. }
  579. }
  580. /**
  581. * @brief TIM_PWM MSP De-Initialization
  582. * This function freeze the hardware resources used in this example
  583. * @param htim_pwm: TIM_PWM handle pointer
  584. * @retval None
  585. */
  586. void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef* htim_pwm)
  587. {
  588. if(htim_pwm->Instance==TIM2)
  589. {
  590. /* USER CODE BEGIN TIM2_MspDeInit 0 */
  591. /* USER CODE END TIM2_MspDeInit 0 */
  592. /* Peripheral clock disable */
  593. __HAL_RCC_TIM2_CLK_DISABLE();
  594. /* USER CODE BEGIN TIM2_MspDeInit 1 */
  595. /* USER CODE END TIM2_MspDeInit 1 */
  596. }
  597. else if(htim_pwm->Instance==TIM4)
  598. {
  599. /* USER CODE BEGIN TIM4_MspDeInit 0 */
  600. /* USER CODE END TIM4_MspDeInit 0 */
  601. /* Peripheral clock disable */
  602. __HAL_RCC_TIM4_CLK_DISABLE();
  603. /* USER CODE BEGIN TIM4_MspDeInit 1 */
  604. /* USER CODE END TIM4_MspDeInit 1 */
  605. }
  606. }
  607. /**
  608. * @brief PCD MSP Initialization
  609. * This function configures the hardware resources used in this example
  610. * @param hpcd: PCD handle pointer
  611. * @retval None
  612. */
  613. void HAL_PCD_MspInit(PCD_HandleTypeDef* hpcd)
  614. {
  615. GPIO_InitTypeDef GPIO_InitStruct = {0};
  616. if(hpcd->Instance==USB_OTG_FS)
  617. {
  618. /* USER CODE BEGIN USB_OTG_FS_MspInit 0 */
  619. /* USER CODE END USB_OTG_FS_MspInit 0 */
  620. __HAL_RCC_GPIOA_CLK_ENABLE();
  621. /**USB_OTG_FS GPIO Configuration
  622. PA8 ------> USB_OTG_FS_SOF
  623. PA9 ------> USB_OTG_FS_VBUS
  624. PA10 ------> USB_OTG_FS_ID
  625. PA11 ------> USB_OTG_FS_DM
  626. PA12 ------> USB_OTG_FS_DP
  627. */
  628. GPIO_InitStruct.Pin = USB_SOF_Pin|USB_ID_Pin|USB_DM_Pin|USB_DP_Pin;
  629. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  630. GPIO_InitStruct.Pull = GPIO_NOPULL;
  631. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  632. GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
  633. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  634. GPIO_InitStruct.Pin = USB_VBUS_Pin;
  635. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  636. GPIO_InitStruct.Pull = GPIO_NOPULL;
  637. HAL_GPIO_Init(USB_VBUS_GPIO_Port, &GPIO_InitStruct);
  638. /* Peripheral clock enable */
  639. __HAL_RCC_USB_OTG_FS_CLK_ENABLE();
  640. /* Enable VDDUSB */
  641. if(__HAL_RCC_PWR_IS_CLK_DISABLED())
  642. {
  643. __HAL_RCC_PWR_CLK_ENABLE();
  644. HAL_PWREx_EnableVddUSB();
  645. __HAL_RCC_PWR_CLK_DISABLE();
  646. }
  647. else
  648. {
  649. HAL_PWREx_EnableVddUSB();
  650. }
  651. /* USB_OTG_FS interrupt Init */
  652. HAL_NVIC_SetPriority(OTG_FS_IRQn, 0, 0);
  653. HAL_NVIC_EnableIRQ(OTG_FS_IRQn);
  654. /* USER CODE BEGIN USB_OTG_FS_MspInit 1 */
  655. /* USER CODE END USB_OTG_FS_MspInit 1 */
  656. }
  657. }
  658. /**
  659. * @brief PCD MSP De-Initialization
  660. * This function freeze the hardware resources used in this example
  661. * @param hpcd: PCD handle pointer
  662. * @retval None
  663. */
  664. void HAL_PCD_MspDeInit(PCD_HandleTypeDef* hpcd)
  665. {
  666. if(hpcd->Instance==USB_OTG_FS)
  667. {
  668. /* USER CODE BEGIN USB_OTG_FS_MspDeInit 0 */
  669. /* USER CODE END USB_OTG_FS_MspDeInit 0 */
  670. /* Peripheral clock disable */
  671. __HAL_RCC_USB_OTG_FS_CLK_DISABLE();
  672. /**USB_OTG_FS GPIO Configuration
  673. PA8 ------> USB_OTG_FS_SOF
  674. PA9 ------> USB_OTG_FS_VBUS
  675. PA10 ------> USB_OTG_FS_ID
  676. PA11 ------> USB_OTG_FS_DM
  677. PA12 ------> USB_OTG_FS_DP
  678. */
  679. HAL_GPIO_DeInit(GPIOA, USB_SOF_Pin|USB_VBUS_Pin|USB_ID_Pin|USB_DM_Pin
  680. |USB_DP_Pin);
  681. /* Disable VDDUSB */
  682. if(__HAL_RCC_PWR_IS_CLK_DISABLED())
  683. {
  684. __HAL_RCC_PWR_CLK_ENABLE();
  685. HAL_PWREx_DisableVddUSB();
  686. __HAL_RCC_PWR_CLK_DISABLE();
  687. }
  688. else
  689. {
  690. HAL_PWREx_DisableVddUSB();
  691. }
  692. /* USB_OTG_FS interrupt DeInit */
  693. HAL_NVIC_DisableIRQ(OTG_FS_IRQn);
  694. /* USER CODE BEGIN USB_OTG_FS_MspDeInit 1 */
  695. /* USER CODE END USB_OTG_FS_MspDeInit 1 */
  696. }
  697. }
  698. static uint32_t SAI1_client =0;
  699. void HAL_SAI_MspInit(SAI_HandleTypeDef* hsai)
  700. {
  701. GPIO_InitTypeDef GPIO_InitStruct;
  702. /* SAI1 */
  703. if(hsai->Instance==SAI1_Block_A)
  704. {
  705. /* Peripheral clock enable */
  706. if (SAI1_client == 0)
  707. {
  708. __HAL_RCC_SAI1_CLK_ENABLE();
  709. }
  710. SAI1_client ++;
  711. /**SAI1_A_Block_A GPIO Configuration
  712. PE4 ------> SAI1_FS_A
  713. PE5 ------> SAI1_SCK_A
  714. PE6 ------> SAI1_SD_A
  715. */
  716. GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6;
  717. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  718. GPIO_InitStruct.Pull = GPIO_NOPULL;
  719. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  720. GPIO_InitStruct.Alternate = GPIO_AF13_SAI1;
  721. HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
  722. }
  723. }
  724. void HAL_SAI_MspDeInit(SAI_HandleTypeDef* hsai)
  725. {
  726. /* SAI1 */
  727. if(hsai->Instance==SAI1_Block_A)
  728. {
  729. SAI1_client --;
  730. if (SAI1_client == 0)
  731. {
  732. /* Peripheral clock disable */
  733. __HAL_RCC_SAI1_CLK_DISABLE();
  734. }
  735. /**SAI1_A_Block_A GPIO Configuration
  736. PE4 ------> SAI1_FS_A
  737. PE5 ------> SAI1_SCK_A
  738. PE6 ------> SAI1_SD_A
  739. */
  740. HAL_GPIO_DeInit(GPIOE, GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6);
  741. }
  742. }
  743. /* USER CODE BEGIN 1 */
  744. /* USER CODE END 1 */