stm32l4xx_hal_msp.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979
  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. else if(huart->Instance==USART2)
  317. {
  318. /* USER CODE BEGIN USART2_MspInit 0 */
  319. /* USER CODE END USART2_MspInit 0 */
  320. /** Initializes the peripherals clock
  321. */
  322. PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART2;
  323. PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;
  324. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  325. {
  326. Error_Handler();
  327. }
  328. /* Peripheral clock enable */
  329. __HAL_RCC_USART2_CLK_ENABLE();
  330. __HAL_RCC_GPIOD_CLK_ENABLE();
  331. /**USART2 GPIO Configuration
  332. PD4 ------> USART2_RTS
  333. PD5 ------> USART2_TX
  334. PD6 ------> USART2_RX
  335. */
  336. GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6;
  337. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  338. GPIO_InitStruct.Pull = GPIO_NOPULL;
  339. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  340. GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
  341. HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  342. /* USART2 interrupt Init */
  343. HAL_NVIC_SetPriority(USART2_IRQn, 0, 0);
  344. HAL_NVIC_EnableIRQ(USART2_IRQn);
  345. /* USER CODE BEGIN USART2_MspInit 1 */
  346. /* USER CODE END USART2_MspInit 1 */
  347. }
  348. }
  349. /**
  350. * @brief UART MSP De-Initialization
  351. * This function freeze the hardware resources used in this example
  352. * @param huart: UART handle pointer
  353. * @retval None
  354. */
  355. void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
  356. {
  357. if(huart->Instance==LPUART1)
  358. {
  359. /* USER CODE BEGIN LPUART1_MspDeInit 0 */
  360. /* USER CODE END LPUART1_MspDeInit 0 */
  361. /* Peripheral clock disable */
  362. __HAL_RCC_LPUART1_CLK_DISABLE();
  363. /**LPUART1 GPIO Configuration
  364. PG7 ------> LPUART1_TX
  365. PG8 ------> LPUART1_RX
  366. */
  367. HAL_GPIO_DeInit(GPIOG, STLK_RX_Pin|STLK_TX_Pin);
  368. /* USER CODE BEGIN LPUART1_MspDeInit 1 */
  369. /* USER CODE END LPUART1_MspDeInit 1 */
  370. }
  371. else if(huart->Instance==USART2)
  372. {
  373. /* USER CODE BEGIN USART2_MspDeInit 0 */
  374. /* USER CODE END USART2_MspDeInit 0 */
  375. /* Peripheral clock disable */
  376. __HAL_RCC_USART2_CLK_DISABLE();
  377. /**USART2 GPIO Configuration
  378. PD4 ------> USART2_RTS
  379. PD5 ------> USART2_TX
  380. PD6 ------> USART2_RX
  381. */
  382. HAL_GPIO_DeInit(GPIOD, GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6);
  383. /* USART2 interrupt DeInit */
  384. HAL_NVIC_DisableIRQ(USART2_IRQn);
  385. /* USER CODE BEGIN USART2_MspDeInit 1 */
  386. /* USER CODE END USART2_MspDeInit 1 */
  387. }
  388. }
  389. /**
  390. * @brief QSPI MSP Initialization
  391. * This function configures the hardware resources used in this example
  392. * @param hqspi: QSPI handle pointer
  393. * @retval None
  394. */
  395. void HAL_QSPI_MspInit(QSPI_HandleTypeDef* hqspi)
  396. {
  397. GPIO_InitTypeDef GPIO_InitStruct = {0};
  398. if(hqspi->Instance==QUADSPI)
  399. {
  400. /* USER CODE BEGIN QUADSPI_MspInit 0 */
  401. /* USER CODE END QUADSPI_MspInit 0 */
  402. /* Peripheral clock enable */
  403. __HAL_RCC_QSPI_CLK_ENABLE();
  404. __HAL_RCC_GPIOF_CLK_ENABLE();
  405. __HAL_RCC_GPIOE_CLK_ENABLE();
  406. /**QUADSPI GPIO Configuration
  407. PF8 ------> QUADSPI_BK1_IO0
  408. PF9 ------> QUADSPI_BK1_IO1
  409. PF10 ------> QUADSPI_CLK
  410. PE11 ------> QUADSPI_BK1_NCS
  411. */
  412. GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9;
  413. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  414. GPIO_InitStruct.Pull = GPIO_NOPULL;
  415. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  416. GPIO_InitStruct.Alternate = GPIO_AF10_QUADSPI;
  417. HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
  418. GPIO_InitStruct.Pin = GPIO_PIN_10;
  419. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  420. GPIO_InitStruct.Pull = GPIO_NOPULL;
  421. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  422. GPIO_InitStruct.Alternate = GPIO_AF3_QUADSPI;
  423. HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
  424. GPIO_InitStruct.Pin = GPIO_PIN_11;
  425. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  426. GPIO_InitStruct.Pull = GPIO_NOPULL;
  427. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  428. GPIO_InitStruct.Alternate = GPIO_AF10_QUADSPI;
  429. HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
  430. /* USER CODE BEGIN QUADSPI_MspInit 1 */
  431. /* USER CODE END QUADSPI_MspInit 1 */
  432. }
  433. }
  434. /**
  435. * @brief QSPI MSP De-Initialization
  436. * This function freeze the hardware resources used in this example
  437. * @param hqspi: QSPI handle pointer
  438. * @retval None
  439. */
  440. void HAL_QSPI_MspDeInit(QSPI_HandleTypeDef* hqspi)
  441. {
  442. if(hqspi->Instance==QUADSPI)
  443. {
  444. /* USER CODE BEGIN QUADSPI_MspDeInit 0 */
  445. /* USER CODE END QUADSPI_MspDeInit 0 */
  446. /* Peripheral clock disable */
  447. __HAL_RCC_QSPI_CLK_DISABLE();
  448. /**QUADSPI GPIO Configuration
  449. PF8 ------> QUADSPI_BK1_IO0
  450. PF9 ------> QUADSPI_BK1_IO1
  451. PF10 ------> QUADSPI_CLK
  452. PE11 ------> QUADSPI_BK1_NCS
  453. */
  454. HAL_GPIO_DeInit(GPIOF, GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10);
  455. HAL_GPIO_DeInit(GPIOE, GPIO_PIN_11);
  456. /* USER CODE BEGIN QUADSPI_MspDeInit 1 */
  457. /* USER CODE END QUADSPI_MspDeInit 1 */
  458. }
  459. }
  460. /**
  461. * @brief RTC MSP Initialization
  462. * This function configures the hardware resources used in this example
  463. * @param hrtc: RTC handle pointer
  464. * @retval None
  465. */
  466. void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc)
  467. {
  468. RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
  469. if(hrtc->Instance==RTC)
  470. {
  471. /* USER CODE BEGIN RTC_MspInit 0 */
  472. /* USER CODE END RTC_MspInit 0 */
  473. /** Initializes the peripherals clock
  474. */
  475. PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC;
  476. PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
  477. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  478. {
  479. Error_Handler();
  480. }
  481. /* Peripheral clock enable */
  482. __HAL_RCC_RTC_ENABLE();
  483. /* USER CODE BEGIN RTC_MspInit 1 */
  484. /* USER CODE END RTC_MspInit 1 */
  485. }
  486. }
  487. /**
  488. * @brief RTC MSP De-Initialization
  489. * This function freeze the hardware resources used in this example
  490. * @param hrtc: RTC handle pointer
  491. * @retval None
  492. */
  493. void HAL_RTC_MspDeInit(RTC_HandleTypeDef* hrtc)
  494. {
  495. if(hrtc->Instance==RTC)
  496. {
  497. /* USER CODE BEGIN RTC_MspDeInit 0 */
  498. /* USER CODE END RTC_MspDeInit 0 */
  499. /* Peripheral clock disable */
  500. __HAL_RCC_RTC_DISABLE();
  501. /* USER CODE BEGIN RTC_MspDeInit 1 */
  502. /* USER CODE END RTC_MspDeInit 1 */
  503. }
  504. }
  505. /**
  506. * @brief SPI MSP Initialization
  507. * This function configures the hardware resources used in this example
  508. * @param hspi: SPI handle pointer
  509. * @retval None
  510. */
  511. void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
  512. {
  513. GPIO_InitTypeDef GPIO_InitStruct = {0};
  514. if(hspi->Instance==SPI1)
  515. {
  516. /* USER CODE BEGIN SPI1_MspInit 0 */
  517. /* USER CODE END SPI1_MspInit 0 */
  518. /* Peripheral clock enable */
  519. __HAL_RCC_SPI1_CLK_ENABLE();
  520. __HAL_RCC_GPIOA_CLK_ENABLE();
  521. /**SPI1 GPIO Configuration
  522. PA1 ------> SPI1_SCK
  523. PA6 ------> SPI1_MISO
  524. PA7 ------> SPI1_MOSI
  525. */
  526. GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_6|GPIO_PIN_7;
  527. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  528. GPIO_InitStruct.Pull = GPIO_NOPULL;
  529. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  530. GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
  531. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  532. /* USER CODE BEGIN SPI1_MspInit 1 */
  533. /* USER CODE END SPI1_MspInit 1 */
  534. }
  535. }
  536. /**
  537. * @brief SPI MSP De-Initialization
  538. * This function freeze the hardware resources used in this example
  539. * @param hspi: SPI handle pointer
  540. * @retval None
  541. */
  542. void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
  543. {
  544. if(hspi->Instance==SPI1)
  545. {
  546. /* USER CODE BEGIN SPI1_MspDeInit 0 */
  547. /* USER CODE END SPI1_MspDeInit 0 */
  548. /* Peripheral clock disable */
  549. __HAL_RCC_SPI1_CLK_DISABLE();
  550. /**SPI1 GPIO Configuration
  551. PA1 ------> SPI1_SCK
  552. PA6 ------> SPI1_MISO
  553. PA7 ------> SPI1_MOSI
  554. */
  555. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_1|GPIO_PIN_6|GPIO_PIN_7);
  556. /* USER CODE BEGIN SPI1_MspDeInit 1 */
  557. /* USER CODE END SPI1_MspDeInit 1 */
  558. }
  559. }
  560. /**
  561. * @brief TIM_PWM MSP Initialization
  562. * This function configures the hardware resources used in this example
  563. * @param htim_pwm: TIM_PWM handle pointer
  564. * @retval None
  565. */
  566. void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef* htim_pwm)
  567. {
  568. if(htim_pwm->Instance==TIM2)
  569. {
  570. /* USER CODE BEGIN TIM2_MspInit 0 */
  571. /* USER CODE END TIM2_MspInit 0 */
  572. /* Peripheral clock enable */
  573. __HAL_RCC_TIM2_CLK_ENABLE();
  574. /* USER CODE BEGIN TIM2_MspInit 1 */
  575. /* USER CODE END TIM2_MspInit 1 */
  576. }
  577. else if(htim_pwm->Instance==TIM4)
  578. {
  579. /* USER CODE BEGIN TIM4_MspInit 0 */
  580. /* USER CODE END TIM4_MspInit 0 */
  581. /* Peripheral clock enable */
  582. __HAL_RCC_TIM4_CLK_ENABLE();
  583. /* USER CODE BEGIN TIM4_MspInit 1 */
  584. /* USER CODE END TIM4_MspInit 1 */
  585. }
  586. }
  587. void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
  588. {
  589. GPIO_InitTypeDef GPIO_InitStruct = {0};
  590. if(htim->Instance==TIM2)
  591. {
  592. /* USER CODE BEGIN TIM2_MspPostInit 0 */
  593. /* USER CODE END TIM2_MspPostInit 0 */
  594. __HAL_RCC_GPIOA_CLK_ENABLE();
  595. /**TIM2 GPIO Configuration
  596. PA2 ------> TIM2_CH3
  597. PA3 ------> TIM2_CH4
  598. */
  599. GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3;
  600. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  601. GPIO_InitStruct.Pull = GPIO_NOPULL;
  602. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  603. GPIO_InitStruct.Alternate = GPIO_AF1_TIM2;
  604. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  605. /* USER CODE BEGIN TIM2_MspPostInit 1 */
  606. /* USER CODE END TIM2_MspPostInit 1 */
  607. }
  608. else if(htim->Instance==TIM4)
  609. {
  610. /* USER CODE BEGIN TIM4_MspPostInit 0 */
  611. /* USER CODE END TIM4_MspPostInit 0 */
  612. __HAL_RCC_GPIOD_CLK_ENABLE();
  613. /**TIM4 GPIO Configuration
  614. PD12 ------> TIM4_CH1
  615. PD13 ------> TIM4_CH2
  616. PD14 ------> TIM4_CH3
  617. PD15 ------> TIM4_CH4
  618. */
  619. GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
  620. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  621. GPIO_InitStruct.Pull = GPIO_NOPULL;
  622. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  623. GPIO_InitStruct.Alternate = GPIO_AF2_TIM4;
  624. HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  625. /* USER CODE BEGIN TIM4_MspPostInit 1 */
  626. /* USER CODE END TIM4_MspPostInit 1 */
  627. }
  628. }
  629. /**
  630. * @brief TIM_PWM MSP De-Initialization
  631. * This function freeze the hardware resources used in this example
  632. * @param htim_pwm: TIM_PWM handle pointer
  633. * @retval None
  634. */
  635. void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef* htim_pwm)
  636. {
  637. if(htim_pwm->Instance==TIM2)
  638. {
  639. /* USER CODE BEGIN TIM2_MspDeInit 0 */
  640. /* USER CODE END TIM2_MspDeInit 0 */
  641. /* Peripheral clock disable */
  642. __HAL_RCC_TIM2_CLK_DISABLE();
  643. /* USER CODE BEGIN TIM2_MspDeInit 1 */
  644. /* USER CODE END TIM2_MspDeInit 1 */
  645. }
  646. else if(htim_pwm->Instance==TIM4)
  647. {
  648. /* USER CODE BEGIN TIM4_MspDeInit 0 */
  649. /* USER CODE END TIM4_MspDeInit 0 */
  650. /* Peripheral clock disable */
  651. __HAL_RCC_TIM4_CLK_DISABLE();
  652. /* USER CODE BEGIN TIM4_MspDeInit 1 */
  653. /* USER CODE END TIM4_MspDeInit 1 */
  654. }
  655. }
  656. /**
  657. * @brief PCD MSP Initialization
  658. * This function configures the hardware resources used in this example
  659. * @param hpcd: PCD handle pointer
  660. * @retval None
  661. */
  662. void HAL_PCD_MspInit(PCD_HandleTypeDef* hpcd)
  663. {
  664. GPIO_InitTypeDef GPIO_InitStruct = {0};
  665. if(hpcd->Instance==USB_OTG_FS)
  666. {
  667. /* USER CODE BEGIN USB_OTG_FS_MspInit 0 */
  668. /* USER CODE END USB_OTG_FS_MspInit 0 */
  669. __HAL_RCC_GPIOA_CLK_ENABLE();
  670. /**USB_OTG_FS GPIO Configuration
  671. PA8 ------> USB_OTG_FS_SOF
  672. PA9 ------> USB_OTG_FS_VBUS
  673. PA10 ------> USB_OTG_FS_ID
  674. PA11 ------> USB_OTG_FS_DM
  675. PA12 ------> USB_OTG_FS_DP
  676. */
  677. GPIO_InitStruct.Pin = USB_SOF_Pin|USB_ID_Pin|USB_DM_Pin|USB_DP_Pin;
  678. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  679. GPIO_InitStruct.Pull = GPIO_NOPULL;
  680. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  681. GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
  682. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  683. GPIO_InitStruct.Pin = USB_VBUS_Pin;
  684. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  685. GPIO_InitStruct.Pull = GPIO_NOPULL;
  686. HAL_GPIO_Init(USB_VBUS_GPIO_Port, &GPIO_InitStruct);
  687. /* Peripheral clock enable */
  688. __HAL_RCC_USB_OTG_FS_CLK_ENABLE();
  689. /* Enable VDDUSB */
  690. if(__HAL_RCC_PWR_IS_CLK_DISABLED())
  691. {
  692. __HAL_RCC_PWR_CLK_ENABLE();
  693. HAL_PWREx_EnableVddUSB();
  694. __HAL_RCC_PWR_CLK_DISABLE();
  695. }
  696. else
  697. {
  698. HAL_PWREx_EnableVddUSB();
  699. }
  700. /* USB_OTG_FS interrupt Init */
  701. HAL_NVIC_SetPriority(OTG_FS_IRQn, 0, 0);
  702. HAL_NVIC_EnableIRQ(OTG_FS_IRQn);
  703. /* USER CODE BEGIN USB_OTG_FS_MspInit 1 */
  704. /* USER CODE END USB_OTG_FS_MspInit 1 */
  705. }
  706. }
  707. /**
  708. * @brief PCD MSP De-Initialization
  709. * This function freeze the hardware resources used in this example
  710. * @param hpcd: PCD handle pointer
  711. * @retval None
  712. */
  713. void HAL_PCD_MspDeInit(PCD_HandleTypeDef* hpcd)
  714. {
  715. if(hpcd->Instance==USB_OTG_FS)
  716. {
  717. /* USER CODE BEGIN USB_OTG_FS_MspDeInit 0 */
  718. /* USER CODE END USB_OTG_FS_MspDeInit 0 */
  719. /* Peripheral clock disable */
  720. __HAL_RCC_USB_OTG_FS_CLK_DISABLE();
  721. /**USB_OTG_FS GPIO Configuration
  722. PA8 ------> USB_OTG_FS_SOF
  723. PA9 ------> USB_OTG_FS_VBUS
  724. PA10 ------> USB_OTG_FS_ID
  725. PA11 ------> USB_OTG_FS_DM
  726. PA12 ------> USB_OTG_FS_DP
  727. */
  728. HAL_GPIO_DeInit(GPIOA, USB_SOF_Pin|USB_VBUS_Pin|USB_ID_Pin|USB_DM_Pin
  729. |USB_DP_Pin);
  730. /* Disable VDDUSB */
  731. if(__HAL_RCC_PWR_IS_CLK_DISABLED())
  732. {
  733. __HAL_RCC_PWR_CLK_ENABLE();
  734. HAL_PWREx_DisableVddUSB();
  735. __HAL_RCC_PWR_CLK_DISABLE();
  736. }
  737. else
  738. {
  739. HAL_PWREx_DisableVddUSB();
  740. }
  741. /* USB_OTG_FS interrupt DeInit */
  742. HAL_NVIC_DisableIRQ(OTG_FS_IRQn);
  743. /* USER CODE BEGIN USB_OTG_FS_MspDeInit 1 */
  744. /* USER CODE END USB_OTG_FS_MspDeInit 1 */
  745. }
  746. }
  747. static uint32_t SAI1_client =0;
  748. void HAL_SAI_MspInit(SAI_HandleTypeDef* hsai)
  749. {
  750. GPIO_InitTypeDef GPIO_InitStruct;
  751. /* SAI1 */
  752. if(hsai->Instance==SAI1_Block_A)
  753. {
  754. /* Peripheral clock enable */
  755. if (SAI1_client == 0)
  756. {
  757. __HAL_RCC_SAI1_CLK_ENABLE();
  758. }
  759. SAI1_client ++;
  760. /**SAI1_A_Block_A GPIO Configuration
  761. PE4 ------> SAI1_FS_A
  762. PE5 ------> SAI1_SCK_A
  763. PE6 ------> SAI1_SD_A
  764. */
  765. GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6;
  766. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  767. GPIO_InitStruct.Pull = GPIO_NOPULL;
  768. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  769. GPIO_InitStruct.Alternate = GPIO_AF13_SAI1;
  770. HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
  771. }
  772. }
  773. void HAL_SAI_MspDeInit(SAI_HandleTypeDef* hsai)
  774. {
  775. /* SAI1 */
  776. if(hsai->Instance==SAI1_Block_A)
  777. {
  778. SAI1_client --;
  779. if (SAI1_client == 0)
  780. {
  781. /* Peripheral clock disable */
  782. __HAL_RCC_SAI1_CLK_DISABLE();
  783. }
  784. /**SAI1_A_Block_A GPIO Configuration
  785. PE4 ------> SAI1_FS_A
  786. PE5 ------> SAI1_SCK_A
  787. PE6 ------> SAI1_SD_A
  788. */
  789. HAL_GPIO_DeInit(GPIOE, GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6);
  790. }
  791. }
  792. /* USER CODE BEGIN 1 */
  793. /* USER CODE END 1 */