stm32f4xx_hal_msp.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * File Name : stm32f4xx_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. if(hadc->Instance==ADC1)
  90. {
  91. /* USER CODE BEGIN ADC1_MspInit 0 */
  92. /* USER CODE END ADC1_MspInit 0 */
  93. /* Peripheral clock enable */
  94. __HAL_RCC_ADC1_CLK_ENABLE();
  95. __HAL_RCC_GPIOC_CLK_ENABLE();
  96. __HAL_RCC_GPIOA_CLK_ENABLE();
  97. /**ADC1 GPIO Configuration
  98. PC0 ------> ADC1_IN10
  99. PC1 ------> ADC1_IN11
  100. PC3 ------> ADC1_IN13
  101. PA3 ------> ADC1_IN3
  102. PC4 ------> ADC1_IN14
  103. PC5 ------> ADC1_IN15
  104. */
  105. GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_3|GPIO_PIN_4
  106. |GPIO_PIN_5;
  107. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  108. GPIO_InitStruct.Pull = GPIO_NOPULL;
  109. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  110. GPIO_InitStruct.Pin = GPIO_PIN_3;
  111. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  112. GPIO_InitStruct.Pull = GPIO_NOPULL;
  113. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  114. /* USER CODE BEGIN ADC1_MspInit 1 */
  115. /* USER CODE END ADC1_MspInit 1 */
  116. }
  117. }
  118. /**
  119. * @brief ADC MSP De-Initialization
  120. * This function freeze the hardware resources used in this example
  121. * @param hadc: ADC handle pointer
  122. * @retval None
  123. */
  124. void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
  125. {
  126. if(hadc->Instance==ADC1)
  127. {
  128. /* USER CODE BEGIN ADC1_MspDeInit 0 */
  129. /* USER CODE END ADC1_MspDeInit 0 */
  130. /* Peripheral clock disable */
  131. __HAL_RCC_ADC1_CLK_DISABLE();
  132. /**ADC1 GPIO Configuration
  133. PC0 ------> ADC1_IN10
  134. PC1 ------> ADC1_IN11
  135. PC3 ------> ADC1_IN13
  136. PA3 ------> ADC1_IN3
  137. PC4 ------> ADC1_IN14
  138. PC5 ------> ADC1_IN15
  139. */
  140. HAL_GPIO_DeInit(GPIOC, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_3|GPIO_PIN_4
  141. |GPIO_PIN_5);
  142. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_3);
  143. /* USER CODE BEGIN ADC1_MspDeInit 1 */
  144. /* USER CODE END ADC1_MspDeInit 1 */
  145. }
  146. }
  147. /**
  148. * @brief TIM_Base MSP Initialization
  149. * This function configures the hardware resources used in this example
  150. * @param htim_base: TIM_Base handle pointer
  151. * @retval None
  152. */
  153. void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
  154. {
  155. if(htim_base->Instance==TIM1)
  156. {
  157. /* USER CODE BEGIN TIM1_MspInit 0 */
  158. /* USER CODE END TIM1_MspInit 0 */
  159. /* Peripheral clock enable */
  160. __HAL_RCC_TIM1_CLK_ENABLE();
  161. /* USER CODE BEGIN TIM1_MspInit 1 */
  162. /* USER CODE END TIM1_MspInit 1 */
  163. }
  164. else if(htim_base->Instance==TIM4)
  165. {
  166. /* USER CODE BEGIN TIM4_MspInit 0 */
  167. /* USER CODE END TIM4_MspInit 0 */
  168. /* Peripheral clock enable */
  169. __HAL_RCC_TIM4_CLK_ENABLE();
  170. /* USER CODE BEGIN TIM4_MspInit 1 */
  171. /* USER CODE END TIM4_MspInit 1 */
  172. }
  173. else if(htim_base->Instance==TIM6)
  174. {
  175. /* USER CODE BEGIN TIM6_MspInit 0 */
  176. /* USER CODE END TIM6_MspInit 0 */
  177. /* Peripheral clock enable */
  178. __HAL_RCC_TIM6_CLK_ENABLE();
  179. /* USER CODE BEGIN TIM6_MspInit 1 */
  180. /* USER CODE END TIM6_MspInit 1 */
  181. }
  182. else if(htim_base->Instance==TIM14)
  183. {
  184. /* USER CODE BEGIN TIM14_MspInit 0 */
  185. /* USER CODE END TIM14_MspInit 0 */
  186. /* Peripheral clock enable */
  187. __HAL_RCC_TIM14_CLK_ENABLE();
  188. /* USER CODE BEGIN TIM14_MspInit 1 */
  189. /* USER CODE END TIM14_MspInit 1 */
  190. }
  191. }
  192. void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
  193. {
  194. GPIO_InitTypeDef GPIO_InitStruct = {0};
  195. if(htim->Instance==TIM1)
  196. {
  197. /* USER CODE BEGIN TIM1_MspPostInit 0 */
  198. /* USER CODE END TIM1_MspPostInit 0 */
  199. __HAL_RCC_GPIOE_CLK_ENABLE();
  200. /**TIM1 GPIO Configuration
  201. PE9 ------> TIM1_CH1
  202. PE11 ------> TIM1_CH2
  203. PE13 ------> TIM1_CH3
  204. */
  205. GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_11|GPIO_PIN_13;
  206. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  207. GPIO_InitStruct.Pull = GPIO_NOPULL;
  208. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  209. GPIO_InitStruct.Alternate = GPIO_AF1_TIM1;
  210. HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
  211. /* USER CODE BEGIN TIM1_MspPostInit 1 */
  212. /* USER CODE END TIM1_MspPostInit 1 */
  213. }
  214. else if(htim->Instance==TIM4)
  215. {
  216. /* USER CODE BEGIN TIM4_MspPostInit 0 */
  217. /* USER CODE END TIM4_MspPostInit 0 */
  218. __HAL_RCC_GPIOD_CLK_ENABLE();
  219. /**TIM4 GPIO Configuration
  220. PD14 ------> TIM4_CH3
  221. PD15 ------> TIM4_CH4
  222. */
  223. GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_15;
  224. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  225. GPIO_InitStruct.Pull = GPIO_NOPULL;
  226. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  227. GPIO_InitStruct.Alternate = GPIO_AF2_TIM4;
  228. HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  229. /* USER CODE BEGIN TIM4_MspPostInit 1 */
  230. /* USER CODE END TIM4_MspPostInit 1 */
  231. }
  232. else if(htim->Instance==TIM14)
  233. {
  234. /* USER CODE BEGIN TIM14_MspPostInit 0 */
  235. /* USER CODE END TIM14_MspPostInit 0 */
  236. __HAL_RCC_GPIOA_CLK_ENABLE();
  237. /**TIM14 GPIO Configuration
  238. PA7 ------> TIM14_CH1
  239. */
  240. GPIO_InitStruct.Pin = GPIO_PIN_7;
  241. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  242. GPIO_InitStruct.Pull = GPIO_NOPULL;
  243. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  244. GPIO_InitStruct.Alternate = GPIO_AF9_TIM14;
  245. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  246. /* USER CODE BEGIN TIM14_MspPostInit 1 */
  247. /* USER CODE END TIM14_MspPostInit 1 */
  248. }
  249. }
  250. /**
  251. * @brief TIM_Base MSP De-Initialization
  252. * This function freeze the hardware resources used in this example
  253. * @param htim_base: TIM_Base handle pointer
  254. * @retval None
  255. */
  256. void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
  257. {
  258. if(htim_base->Instance==TIM1)
  259. {
  260. /* USER CODE BEGIN TIM1_MspDeInit 0 */
  261. /* USER CODE END TIM1_MspDeInit 0 */
  262. /* Peripheral clock disable */
  263. __HAL_RCC_TIM1_CLK_DISABLE();
  264. /* USER CODE BEGIN TIM1_MspDeInit 1 */
  265. /* USER CODE END TIM1_MspDeInit 1 */
  266. }
  267. else if(htim_base->Instance==TIM4)
  268. {
  269. /* USER CODE BEGIN TIM4_MspDeInit 0 */
  270. /* USER CODE END TIM4_MspDeInit 0 */
  271. /* Peripheral clock disable */
  272. __HAL_RCC_TIM4_CLK_DISABLE();
  273. /* USER CODE BEGIN TIM4_MspDeInit 1 */
  274. /* USER CODE END TIM4_MspDeInit 1 */
  275. }
  276. else if(htim_base->Instance==TIM6)
  277. {
  278. /* USER CODE BEGIN TIM6_MspDeInit 0 */
  279. /* USER CODE END TIM6_MspDeInit 0 */
  280. /* Peripheral clock disable */
  281. __HAL_RCC_TIM6_CLK_DISABLE();
  282. /* USER CODE BEGIN TIM6_MspDeInit 1 */
  283. /* USER CODE END TIM6_MspDeInit 1 */
  284. }
  285. else if(htim_base->Instance==TIM14)
  286. {
  287. /* USER CODE BEGIN TIM14_MspDeInit 0 */
  288. /* USER CODE END TIM14_MspDeInit 0 */
  289. /* Peripheral clock disable */
  290. __HAL_RCC_TIM14_CLK_DISABLE();
  291. /* USER CODE BEGIN TIM14_MspDeInit 1 */
  292. /* USER CODE END TIM14_MspDeInit 1 */
  293. }
  294. }
  295. /**
  296. * @brief UART MSP Initialization
  297. * This function configures the hardware resources used in this example
  298. * @param huart: UART handle pointer
  299. * @retval None
  300. */
  301. void HAL_UART_MspInit(UART_HandleTypeDef* huart)
  302. {
  303. GPIO_InitTypeDef GPIO_InitStruct = {0};
  304. if(huart->Instance==USART3)
  305. {
  306. /* USER CODE BEGIN USART3_MspInit 0 */
  307. /* USER CODE END USART3_MspInit 0 */
  308. /* Peripheral clock enable */
  309. __HAL_RCC_USART3_CLK_ENABLE();
  310. __HAL_RCC_GPIOD_CLK_ENABLE();
  311. /**USART3 GPIO Configuration
  312. PD8 ------> USART3_TX
  313. PD9 ------> USART3_RX
  314. */
  315. GPIO_InitStruct.Pin = STLK_RX_Pin|STLK_TX_Pin;
  316. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  317. GPIO_InitStruct.Pull = GPIO_NOPULL;
  318. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  319. GPIO_InitStruct.Alternate = GPIO_AF7_USART3;
  320. HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  321. /* USER CODE BEGIN USART3_MspInit 1 */
  322. /* USER CODE END USART3_MspInit 1 */
  323. }
  324. }
  325. /**
  326. * @brief UART MSP De-Initialization
  327. * This function freeze the hardware resources used in this example
  328. * @param huart: UART handle pointer
  329. * @retval None
  330. */
  331. void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
  332. {
  333. if(huart->Instance==USART3)
  334. {
  335. /* USER CODE BEGIN USART3_MspDeInit 0 */
  336. /* USER CODE END USART3_MspDeInit 0 */
  337. /* Peripheral clock disable */
  338. __HAL_RCC_USART3_CLK_DISABLE();
  339. /**USART3 GPIO Configuration
  340. PD8 ------> USART3_TX
  341. PD9 ------> USART3_RX
  342. */
  343. HAL_GPIO_DeInit(GPIOD, STLK_RX_Pin|STLK_TX_Pin);
  344. /* USER CODE BEGIN USART3_MspDeInit 1 */
  345. /* USER CODE END USART3_MspDeInit 1 */
  346. }
  347. }
  348. /**
  349. * @brief PCD MSP Initialization
  350. * This function configures the hardware resources used in this example
  351. * @param hpcd: PCD handle pointer
  352. * @retval None
  353. */
  354. void HAL_PCD_MspInit(PCD_HandleTypeDef* hpcd)
  355. {
  356. GPIO_InitTypeDef GPIO_InitStruct = {0};
  357. RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
  358. if(hpcd->Instance==USB_OTG_FS)
  359. {
  360. /* USER CODE BEGIN USB_OTG_FS_MspInit 0 */
  361. /* USER CODE END USB_OTG_FS_MspInit 0 */
  362. /** Initializes the peripherals clock
  363. */
  364. PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_CLK48;
  365. PeriphClkInitStruct.Clk48ClockSelection = RCC_CLK48CLKSOURCE_PLLQ;
  366. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
  367. {
  368. Error_Handler();
  369. }
  370. __HAL_RCC_GPIOA_CLK_ENABLE();
  371. /**USB_OTG_FS GPIO Configuration
  372. PA8 ------> USB_OTG_FS_SOF
  373. PA10 ------> USB_OTG_FS_ID
  374. PA11 ------> USB_OTG_FS_DM
  375. PA12 ------> USB_OTG_FS_DP
  376. */
  377. GPIO_InitStruct.Pin = USB_SOF_Pin|USB_ID_Pin|USB_DM_Pin|USB_DP_Pin;
  378. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  379. GPIO_InitStruct.Pull = GPIO_NOPULL;
  380. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  381. GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
  382. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  383. /* Peripheral clock enable */
  384. __HAL_RCC_USB_OTG_FS_CLK_ENABLE();
  385. /* USER CODE BEGIN USB_OTG_FS_MspInit 1 */
  386. /* USER CODE END USB_OTG_FS_MspInit 1 */
  387. }
  388. }
  389. /**
  390. * @brief PCD MSP De-Initialization
  391. * This function freeze the hardware resources used in this example
  392. * @param hpcd: PCD handle pointer
  393. * @retval None
  394. */
  395. void HAL_PCD_MspDeInit(PCD_HandleTypeDef* hpcd)
  396. {
  397. if(hpcd->Instance==USB_OTG_FS)
  398. {
  399. /* USER CODE BEGIN USB_OTG_FS_MspDeInit 0 */
  400. /* USER CODE END USB_OTG_FS_MspDeInit 0 */
  401. /* Peripheral clock disable */
  402. __HAL_RCC_USB_OTG_FS_CLK_DISABLE();
  403. /**USB_OTG_FS GPIO Configuration
  404. PA8 ------> USB_OTG_FS_SOF
  405. PA10 ------> USB_OTG_FS_ID
  406. PA11 ------> USB_OTG_FS_DM
  407. PA12 ------> USB_OTG_FS_DP
  408. */
  409. HAL_GPIO_DeInit(GPIOA, USB_SOF_Pin|USB_ID_Pin|USB_DM_Pin|USB_DP_Pin);
  410. /* USER CODE BEGIN USB_OTG_FS_MspDeInit 1 */
  411. /* USER CODE END USB_OTG_FS_MspDeInit 1 */
  412. }
  413. }
  414. /* USER CODE BEGIN 1 */
  415. /* USER CODE END 1 */