stm32l4xx_hal_msp.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  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 Ultimate Liberty license
  14. * SLA0044, the "License"; You may not use this file except in compliance with
  15. * the License. You may obtain a copy of the License at:
  16. * www.st.com/SLA0044
  17. *
  18. ******************************************************************************
  19. */
  20. /* USER CODE END Header */
  21. /* Includes ------------------------------------------------------------------*/
  22. #include "main.h"
  23. /* USER CODE BEGIN Includes */
  24. /* USER CODE END Includes */
  25. /* Private typedef -----------------------------------------------------------*/
  26. /* USER CODE BEGIN TD */
  27. /* USER CODE END TD */
  28. /* Private define ------------------------------------------------------------*/
  29. /* USER CODE BEGIN Define */
  30. /* USER CODE END Define */
  31. /* Private macro -------------------------------------------------------------*/
  32. /* USER CODE BEGIN Macro */
  33. /* USER CODE END Macro */
  34. /* Private variables ---------------------------------------------------------*/
  35. /* USER CODE BEGIN PV */
  36. /* USER CODE END PV */
  37. /* Private function prototypes -----------------------------------------------*/
  38. /* USER CODE BEGIN PFP */
  39. /* USER CODE END PFP */
  40. /* External functions --------------------------------------------------------*/
  41. /* USER CODE BEGIN ExternalFunctions */
  42. /* USER CODE END ExternalFunctions */
  43. /* USER CODE BEGIN 0 */
  44. /* USER CODE END 0 */
  45. void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim);
  46. /**
  47. * Initializes the Global MSP.
  48. */
  49. void HAL_MspInit(void) {
  50. /* USER CODE BEGIN MspInit 0 */
  51. /* USER CODE END MspInit 0 */
  52. __HAL_RCC_SYSCFG_CLK_ENABLE();
  53. __HAL_RCC_PWR_CLK_ENABLE();
  54. /* System interrupt init*/
  55. /* PendSV_IRQn interrupt configuration */
  56. HAL_NVIC_SetPriority(PendSV_IRQn, 15, 0);
  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. GPIO_InitTypeDef GPIO_InitStruct = {0};
  68. if(hadc->Instance == ADC1) {
  69. /* USER CODE BEGIN ADC1_MspInit 0 */
  70. /* USER CODE END ADC1_MspInit 0 */
  71. /* Peripheral clock enable */
  72. __HAL_RCC_ADC_CLK_ENABLE();
  73. __HAL_RCC_GPIOC_CLK_ENABLE();
  74. __HAL_RCC_GPIOA_CLK_ENABLE();
  75. /**ADC1 GPIO Configuration
  76. PC3 ------> ADC1_IN4
  77. PA0 ------> ADC1_IN5
  78. */
  79. GPIO_InitStruct.Pin = BATT_V_Pin;
  80. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG_ADC_CONTROL;
  81. GPIO_InitStruct.Pull = GPIO_NOPULL;
  82. HAL_GPIO_Init(BATT_V_GPIO_Port, &GPIO_InitStruct);
  83. GPIO_InitStruct.Pin = IR_RX_Pin;
  84. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG_ADC_CONTROL;
  85. GPIO_InitStruct.Pull = GPIO_NOPULL;
  86. HAL_GPIO_Init(IR_RX_GPIO_Port, &GPIO_InitStruct);
  87. /* USER CODE BEGIN ADC1_MspInit 1 */
  88. /* USER CODE END ADC1_MspInit 1 */
  89. }
  90. }
  91. /**
  92. * @brief ADC MSP De-Initialization
  93. * This function freeze the hardware resources used in this example
  94. * @param hadc: ADC handle pointer
  95. * @retval None
  96. */
  97. void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc) {
  98. if(hadc->Instance == ADC1) {
  99. /* USER CODE BEGIN ADC1_MspDeInit 0 */
  100. /* USER CODE END ADC1_MspDeInit 0 */
  101. /* Peripheral clock disable */
  102. __HAL_RCC_ADC_CLK_DISABLE();
  103. /**ADC1 GPIO Configuration
  104. PC3 ------> ADC1_IN4
  105. PA0 ------> ADC1_IN5
  106. */
  107. HAL_GPIO_DeInit(BATT_V_GPIO_Port, BATT_V_Pin);
  108. HAL_GPIO_DeInit(IR_RX_GPIO_Port, IR_RX_Pin);
  109. /* USER CODE BEGIN ADC1_MspDeInit 1 */
  110. /* USER CODE END ADC1_MspDeInit 1 */
  111. }
  112. }
  113. /**
  114. * @brief COMP MSP Initialization
  115. * This function configures the hardware resources used in this example
  116. * @param hcomp: COMP handle pointer
  117. * @retval None
  118. */
  119. void HAL_COMP_MspInit(COMP_HandleTypeDef* hcomp) {
  120. GPIO_InitTypeDef GPIO_InitStruct = {0};
  121. if(hcomp->Instance == COMP1) {
  122. /* USER CODE BEGIN COMP1_MspInit 0 */
  123. /* USER CODE END COMP1_MspInit 0 */
  124. __HAL_RCC_GPIOC_CLK_ENABLE();
  125. /**COMP1 GPIO Configuration
  126. PC5 ------> COMP1_INP
  127. */
  128. GPIO_InitStruct.Pin = RFID_RF_IN_Pin;
  129. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  130. GPIO_InitStruct.Pull = GPIO_NOPULL;
  131. HAL_GPIO_Init(RFID_RF_IN_GPIO_Port, &GPIO_InitStruct);
  132. /* USER CODE BEGIN COMP1_MspInit 1 */
  133. /* USER CODE END COMP1_MspInit 1 */
  134. }
  135. }
  136. /**
  137. * @brief COMP MSP De-Initialization
  138. * This function freeze the hardware resources used in this example
  139. * @param hcomp: COMP handle pointer
  140. * @retval None
  141. */
  142. void HAL_COMP_MspDeInit(COMP_HandleTypeDef* hcomp) {
  143. if(hcomp->Instance == COMP1) {
  144. /* USER CODE BEGIN COMP1_MspDeInit 0 */
  145. /* USER CODE END COMP1_MspDeInit 0 */
  146. /**COMP1 GPIO Configuration
  147. PC5 ------> COMP1_INP
  148. */
  149. HAL_GPIO_DeInit(RFID_RF_IN_GPIO_Port, RFID_RF_IN_Pin);
  150. /* USER CODE BEGIN COMP1_MspDeInit 1 */
  151. /* USER CODE END COMP1_MspDeInit 1 */
  152. }
  153. }
  154. /**
  155. * @brief SPI MSP Initialization
  156. * This function configures the hardware resources used in this example
  157. * @param hspi: SPI handle pointer
  158. * @retval None
  159. */
  160. void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi) {
  161. GPIO_InitTypeDef GPIO_InitStruct = {0};
  162. if(hspi->Instance == SPI1) {
  163. /* USER CODE BEGIN SPI1_MspInit 0 */
  164. /* USER CODE END SPI1_MspInit 0 */
  165. /* Peripheral clock enable */
  166. __HAL_RCC_SPI1_CLK_ENABLE();
  167. __HAL_RCC_GPIOB_CLK_ENABLE();
  168. /**SPI1 GPIO Configuration
  169. PB3 (JTDO-TRACESWO) ------> SPI1_SCK
  170. PB5 ------> SPI1_MOSI
  171. */
  172. GPIO_InitStruct.Pin = GPIO_PIN_3 | GPIO_PIN_5;
  173. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  174. GPIO_InitStruct.Pull = GPIO_NOPULL;
  175. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  176. GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
  177. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  178. /* USER CODE BEGIN SPI1_MspInit 1 */
  179. /* USER CODE END SPI1_MspInit 1 */
  180. } else if(hspi->Instance == SPI3) {
  181. /* USER CODE BEGIN SPI3_MspInit 0 */
  182. /* USER CODE END SPI3_MspInit 0 */
  183. /* Peripheral clock enable */
  184. __HAL_RCC_SPI3_CLK_ENABLE();
  185. __HAL_RCC_GPIOC_CLK_ENABLE();
  186. /**SPI3 GPIO Configuration
  187. PC10 ------> SPI3_SCK
  188. PC11 ------> SPI3_MISO
  189. PC12 ------> SPI3_MOSI
  190. */
  191. GPIO_InitStruct.Pin = GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12;
  192. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  193. GPIO_InitStruct.Pull = GPIO_NOPULL;
  194. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  195. GPIO_InitStruct.Alternate = GPIO_AF6_SPI3;
  196. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  197. /* USER CODE BEGIN SPI3_MspInit 1 */
  198. /* USER CODE END SPI3_MspInit 1 */
  199. }
  200. }
  201. /**
  202. * @brief SPI MSP De-Initialization
  203. * This function freeze the hardware resources used in this example
  204. * @param hspi: SPI handle pointer
  205. * @retval None
  206. */
  207. void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi) {
  208. if(hspi->Instance == SPI1) {
  209. /* USER CODE BEGIN SPI1_MspDeInit 0 */
  210. /* USER CODE END SPI1_MspDeInit 0 */
  211. /* Peripheral clock disable */
  212. __HAL_RCC_SPI1_CLK_DISABLE();
  213. /**SPI1 GPIO Configuration
  214. PB3 (JTDO-TRACESWO) ------> SPI1_SCK
  215. PB5 ------> SPI1_MOSI
  216. */
  217. HAL_GPIO_DeInit(GPIOB, GPIO_PIN_3 | GPIO_PIN_5);
  218. /* USER CODE BEGIN SPI1_MspDeInit 1 */
  219. /* USER CODE END SPI1_MspDeInit 1 */
  220. } else if(hspi->Instance == SPI3) {
  221. /* USER CODE BEGIN SPI3_MspDeInit 0 */
  222. /* USER CODE END SPI3_MspDeInit 0 */
  223. /* Peripheral clock disable */
  224. __HAL_RCC_SPI3_CLK_DISABLE();
  225. /**SPI3 GPIO Configuration
  226. PC10 ------> SPI3_SCK
  227. PC11 ------> SPI3_MISO
  228. PC12 ------> SPI3_MOSI
  229. */
  230. HAL_GPIO_DeInit(GPIOC, GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12);
  231. /* USER CODE BEGIN SPI3_MspDeInit 1 */
  232. /* USER CODE END SPI3_MspDeInit 1 */
  233. }
  234. }
  235. /**
  236. * @brief TIM_PWM MSP Initialization
  237. * This function configures the hardware resources used in this example
  238. * @param htim_pwm: TIM_PWM handle pointer
  239. * @retval None
  240. */
  241. void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef* htim_pwm) {
  242. if(htim_pwm->Instance == TIM5) {
  243. /* USER CODE BEGIN TIM5_MspInit 0 */
  244. /* USER CODE END TIM5_MspInit 0 */
  245. /* Peripheral clock enable */
  246. __HAL_RCC_TIM5_CLK_ENABLE();
  247. /* USER CODE BEGIN TIM5_MspInit 1 */
  248. /* USER CODE END TIM5_MspInit 1 */
  249. }
  250. }
  251. /**
  252. * @brief TIM_Base MSP Initialization
  253. * This function configures the hardware resources used in this example
  254. * @param htim_base: TIM_Base handle pointer
  255. * @retval None
  256. */
  257. void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base) {
  258. GPIO_InitTypeDef GPIO_InitStruct = {0};
  259. if(htim_base->Instance == TIM8) {
  260. /* USER CODE BEGIN TIM8_MspInit 0 */
  261. /* USER CODE END TIM8_MspInit 0 */
  262. /* Peripheral clock enable */
  263. __HAL_RCC_TIM8_CLK_ENABLE();
  264. __HAL_RCC_GPIOC_CLK_ENABLE();
  265. /**TIM8 GPIO Configuration
  266. PC7 ------> TIM8_CH2
  267. */
  268. GPIO_InitStruct.Pin = iButton_Pin;
  269. GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
  270. GPIO_InitStruct.Pull = GPIO_NOPULL;
  271. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
  272. GPIO_InitStruct.Alternate = GPIO_AF3_TIM8;
  273. HAL_GPIO_Init(iButton_GPIO_Port, &GPIO_InitStruct);
  274. /* TIM8 interrupt Init */
  275. HAL_NVIC_SetPriority(TIM8_CC_IRQn, 5, 0);
  276. HAL_NVIC_EnableIRQ(TIM8_CC_IRQn);
  277. /* USER CODE BEGIN TIM8_MspInit 1 */
  278. /* USER CODE END TIM8_MspInit 1 */
  279. }
  280. }
  281. /**
  282. * @brief TIM_OC MSP Initialization
  283. * This function configures the hardware resources used in this example
  284. * @param htim_oc: TIM_OC handle pointer
  285. * @retval None
  286. */
  287. void HAL_TIM_OC_MspInit(TIM_HandleTypeDef* htim_oc) {
  288. if(htim_oc->Instance == TIM15) {
  289. /* USER CODE BEGIN TIM15_MspInit 0 */
  290. /* USER CODE END TIM15_MspInit 0 */
  291. /* Peripheral clock enable */
  292. __HAL_RCC_TIM15_CLK_ENABLE();
  293. /* USER CODE BEGIN TIM15_MspInit 1 */
  294. /* USER CODE END TIM15_MspInit 1 */
  295. }
  296. }
  297. void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim) {
  298. GPIO_InitTypeDef GPIO_InitStruct = {0};
  299. if(htim->Instance == TIM5) {
  300. /* USER CODE BEGIN TIM5_MspPostInit 0 */
  301. /* USER CODE END TIM5_MspPostInit 0 */
  302. __HAL_RCC_GPIOA_CLK_ENABLE();
  303. /**TIM5 GPIO Configuration
  304. PA3 ------> TIM5_CH4
  305. */
  306. GPIO_InitStruct.Pin = SPEAKER_Pin;
  307. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  308. GPIO_InitStruct.Pull = GPIO_NOPULL;
  309. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  310. GPIO_InitStruct.Alternate = GPIO_AF2_TIM5;
  311. HAL_GPIO_Init(SPEAKER_GPIO_Port, &GPIO_InitStruct);
  312. /* USER CODE BEGIN TIM5_MspPostInit 1 */
  313. /* USER CODE END TIM5_MspPostInit 1 */
  314. } else if(htim->Instance == TIM15) {
  315. /* USER CODE BEGIN TIM15_MspPostInit 0 */
  316. /* USER CODE END TIM15_MspPostInit 0 */
  317. __HAL_RCC_GPIOB_CLK_ENABLE();
  318. /**TIM15 GPIO Configuration
  319. PB13 ------> TIM15_CH1N
  320. PB15 ------> TIM15_CH2
  321. */
  322. GPIO_InitStruct.Pin = RFID_OUT_Pin | RFID_PULL_Pin;
  323. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  324. GPIO_InitStruct.Pull = GPIO_NOPULL;
  325. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  326. GPIO_InitStruct.Alternate = GPIO_AF14_TIM15;
  327. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  328. /* USER CODE BEGIN TIM15_MspPostInit 1 */
  329. /* USER CODE END TIM15_MspPostInit 1 */
  330. }
  331. }
  332. /**
  333. * @brief TIM_PWM MSP De-Initialization
  334. * This function freeze the hardware resources used in this example
  335. * @param htim_pwm: TIM_PWM handle pointer
  336. * @retval None
  337. */
  338. void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef* htim_pwm) {
  339. if(htim_pwm->Instance == TIM5) {
  340. /* USER CODE BEGIN TIM5_MspDeInit 0 */
  341. /* USER CODE END TIM5_MspDeInit 0 */
  342. /* Peripheral clock disable */
  343. __HAL_RCC_TIM5_CLK_DISABLE();
  344. /* USER CODE BEGIN TIM5_MspDeInit 1 */
  345. /* USER CODE END TIM5_MspDeInit 1 */
  346. }
  347. }
  348. /**
  349. * @brief TIM_Base MSP De-Initialization
  350. * This function freeze the hardware resources used in this example
  351. * @param htim_base: TIM_Base handle pointer
  352. * @retval None
  353. */
  354. void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base) {
  355. if(htim_base->Instance == TIM8) {
  356. /* USER CODE BEGIN TIM8_MspDeInit 0 */
  357. /* USER CODE END TIM8_MspDeInit 0 */
  358. /* Peripheral clock disable */
  359. __HAL_RCC_TIM8_CLK_DISABLE();
  360. /**TIM8 GPIO Configuration
  361. PC7 ------> TIM8_CH2
  362. */
  363. HAL_GPIO_DeInit(iButton_GPIO_Port, iButton_Pin);
  364. /* TIM8 interrupt DeInit */
  365. HAL_NVIC_DisableIRQ(TIM8_CC_IRQn);
  366. /* USER CODE BEGIN TIM8_MspDeInit 1 */
  367. /* USER CODE END TIM8_MspDeInit 1 */
  368. }
  369. }
  370. /**
  371. * @brief TIM_OC MSP De-Initialization
  372. * This function freeze the hardware resources used in this example
  373. * @param htim_oc: TIM_OC handle pointer
  374. * @retval None
  375. */
  376. void HAL_TIM_OC_MspDeInit(TIM_HandleTypeDef* htim_oc) {
  377. if(htim_oc->Instance == TIM15) {
  378. /* USER CODE BEGIN TIM15_MspDeInit 0 */
  379. /* USER CODE END TIM15_MspDeInit 0 */
  380. /* Peripheral clock disable */
  381. __HAL_RCC_TIM15_CLK_DISABLE();
  382. /* USER CODE BEGIN TIM15_MspDeInit 1 */
  383. /* USER CODE END TIM15_MspDeInit 1 */
  384. }
  385. }
  386. /**
  387. * @brief UART MSP Initialization
  388. * This function configures the hardware resources used in this example
  389. * @param huart: UART handle pointer
  390. * @retval None
  391. */
  392. void HAL_UART_MspInit(UART_HandleTypeDef* huart) {
  393. GPIO_InitTypeDef GPIO_InitStruct = {0};
  394. if(huart->Instance == USART1) {
  395. /* USER CODE BEGIN USART1_MspInit 0 */
  396. /* USER CODE END USART1_MspInit 0 */
  397. /* Peripheral clock enable */
  398. __HAL_RCC_USART1_CLK_ENABLE();
  399. __HAL_RCC_GPIOA_CLK_ENABLE();
  400. /**USART1 GPIO Configuration
  401. PA9 ------> USART1_TX
  402. PA10 ------> USART1_RX
  403. */
  404. GPIO_InitStruct.Pin = GPIO_PIN_9 | GPIO_PIN_10;
  405. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  406. GPIO_InitStruct.Pull = GPIO_NOPULL;
  407. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  408. GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
  409. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  410. /* USER CODE BEGIN USART1_MspInit 1 */
  411. /* USER CODE END USART1_MspInit 1 */
  412. }
  413. }
  414. /**
  415. * @brief UART MSP De-Initialization
  416. * This function freeze the hardware resources used in this example
  417. * @param huart: UART handle pointer
  418. * @retval None
  419. */
  420. void HAL_UART_MspDeInit(UART_HandleTypeDef* huart) {
  421. if(huart->Instance == USART1) {
  422. /* USER CODE BEGIN USART1_MspDeInit 0 */
  423. /* USER CODE END USART1_MspDeInit 0 */
  424. /* Peripheral clock disable */
  425. __HAL_RCC_USART1_CLK_DISABLE();
  426. /**USART1 GPIO Configuration
  427. PA9 ------> USART1_TX
  428. PA10 ------> USART1_RX
  429. */
  430. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9 | GPIO_PIN_10);
  431. /* USER CODE BEGIN USART1_MspDeInit 1 */
  432. /* USER CODE END USART1_MspDeInit 1 */
  433. }
  434. }
  435. /* USER CODE BEGIN 1 */
  436. /* USER CODE END 1 */
  437. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/