stm32f4xx_hal_msp.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  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==TIM14)
  174. {
  175. /* USER CODE BEGIN TIM14_MspInit 0 */
  176. /* USER CODE END TIM14_MspInit 0 */
  177. /* Peripheral clock enable */
  178. __HAL_RCC_TIM14_CLK_ENABLE();
  179. /* USER CODE BEGIN TIM14_MspInit 1 */
  180. /* USER CODE END TIM14_MspInit 1 */
  181. }
  182. }
  183. void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
  184. {
  185. GPIO_InitTypeDef GPIO_InitStruct = {0};
  186. if(htim->Instance==TIM1)
  187. {
  188. /* USER CODE BEGIN TIM1_MspPostInit 0 */
  189. /* USER CODE END TIM1_MspPostInit 0 */
  190. __HAL_RCC_GPIOE_CLK_ENABLE();
  191. /**TIM1 GPIO Configuration
  192. PE9 ------> TIM1_CH1
  193. PE11 ------> TIM1_CH2
  194. PE13 ------> TIM1_CH3
  195. */
  196. GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_11|GPIO_PIN_13;
  197. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  198. GPIO_InitStruct.Pull = GPIO_NOPULL;
  199. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  200. GPIO_InitStruct.Alternate = GPIO_AF1_TIM1;
  201. HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
  202. /* USER CODE BEGIN TIM1_MspPostInit 1 */
  203. /* USER CODE END TIM1_MspPostInit 1 */
  204. }
  205. else if(htim->Instance==TIM4)
  206. {
  207. /* USER CODE BEGIN TIM4_MspPostInit 0 */
  208. /* USER CODE END TIM4_MspPostInit 0 */
  209. __HAL_RCC_GPIOD_CLK_ENABLE();
  210. /**TIM4 GPIO Configuration
  211. PD14 ------> TIM4_CH3
  212. PD15 ------> TIM4_CH4
  213. */
  214. GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_15;
  215. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  216. GPIO_InitStruct.Pull = GPIO_NOPULL;
  217. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  218. GPIO_InitStruct.Alternate = GPIO_AF2_TIM4;
  219. HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  220. /* USER CODE BEGIN TIM4_MspPostInit 1 */
  221. /* USER CODE END TIM4_MspPostInit 1 */
  222. }
  223. else if(htim->Instance==TIM14)
  224. {
  225. /* USER CODE BEGIN TIM14_MspPostInit 0 */
  226. /* USER CODE END TIM14_MspPostInit 0 */
  227. __HAL_RCC_GPIOA_CLK_ENABLE();
  228. /**TIM14 GPIO Configuration
  229. PA7 ------> TIM14_CH1
  230. */
  231. GPIO_InitStruct.Pin = GPIO_PIN_7;
  232. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  233. GPIO_InitStruct.Pull = GPIO_NOPULL;
  234. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  235. GPIO_InitStruct.Alternate = GPIO_AF9_TIM14;
  236. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  237. /* USER CODE BEGIN TIM14_MspPostInit 1 */
  238. /* USER CODE END TIM14_MspPostInit 1 */
  239. }
  240. }
  241. /**
  242. * @brief TIM_Base MSP De-Initialization
  243. * This function freeze the hardware resources used in this example
  244. * @param htim_base: TIM_Base handle pointer
  245. * @retval None
  246. */
  247. void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
  248. {
  249. if(htim_base->Instance==TIM1)
  250. {
  251. /* USER CODE BEGIN TIM1_MspDeInit 0 */
  252. /* USER CODE END TIM1_MspDeInit 0 */
  253. /* Peripheral clock disable */
  254. __HAL_RCC_TIM1_CLK_DISABLE();
  255. /* USER CODE BEGIN TIM1_MspDeInit 1 */
  256. /* USER CODE END TIM1_MspDeInit 1 */
  257. }
  258. else if(htim_base->Instance==TIM4)
  259. {
  260. /* USER CODE BEGIN TIM4_MspDeInit 0 */
  261. /* USER CODE END TIM4_MspDeInit 0 */
  262. /* Peripheral clock disable */
  263. __HAL_RCC_TIM4_CLK_DISABLE();
  264. /* USER CODE BEGIN TIM4_MspDeInit 1 */
  265. /* USER CODE END TIM4_MspDeInit 1 */
  266. }
  267. else if(htim_base->Instance==TIM14)
  268. {
  269. /* USER CODE BEGIN TIM14_MspDeInit 0 */
  270. /* USER CODE END TIM14_MspDeInit 0 */
  271. /* Peripheral clock disable */
  272. __HAL_RCC_TIM14_CLK_DISABLE();
  273. /* USER CODE BEGIN TIM14_MspDeInit 1 */
  274. /* USER CODE END TIM14_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. if(huart->Instance==USART3)
  287. {
  288. /* USER CODE BEGIN USART3_MspInit 0 */
  289. /* USER CODE END USART3_MspInit 0 */
  290. /* Peripheral clock enable */
  291. __HAL_RCC_USART3_CLK_ENABLE();
  292. __HAL_RCC_GPIOD_CLK_ENABLE();
  293. /**USART3 GPIO Configuration
  294. PD8 ------> USART3_TX
  295. PD9 ------> USART3_RX
  296. */
  297. GPIO_InitStruct.Pin = STLK_RX_Pin|STLK_TX_Pin;
  298. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  299. GPIO_InitStruct.Pull = GPIO_NOPULL;
  300. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  301. GPIO_InitStruct.Alternate = GPIO_AF7_USART3;
  302. HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  303. /* USER CODE BEGIN USART3_MspInit 1 */
  304. /* USER CODE END USART3_MspInit 1 */
  305. }
  306. }
  307. /**
  308. * @brief UART MSP De-Initialization
  309. * This function freeze the hardware resources used in this example
  310. * @param huart: UART handle pointer
  311. * @retval None
  312. */
  313. void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
  314. {
  315. if(huart->Instance==USART3)
  316. {
  317. /* USER CODE BEGIN USART3_MspDeInit 0 */
  318. /* USER CODE END USART3_MspDeInit 0 */
  319. /* Peripheral clock disable */
  320. __HAL_RCC_USART3_CLK_DISABLE();
  321. /**USART3 GPIO Configuration
  322. PD8 ------> USART3_TX
  323. PD9 ------> USART3_RX
  324. */
  325. HAL_GPIO_DeInit(GPIOD, STLK_RX_Pin|STLK_TX_Pin);
  326. /* USER CODE BEGIN USART3_MspDeInit 1 */
  327. /* USER CODE END USART3_MspDeInit 1 */
  328. }
  329. }
  330. /**
  331. * @brief PCD MSP Initialization
  332. * This function configures the hardware resources used in this example
  333. * @param hpcd: PCD handle pointer
  334. * @retval None
  335. */
  336. void HAL_PCD_MspInit(PCD_HandleTypeDef* hpcd)
  337. {
  338. GPIO_InitTypeDef GPIO_InitStruct = {0};
  339. RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
  340. if(hpcd->Instance==USB_OTG_FS)
  341. {
  342. /* USER CODE BEGIN USB_OTG_FS_MspInit 0 */
  343. /* USER CODE END USB_OTG_FS_MspInit 0 */
  344. /** Initializes the peripherals clock
  345. */
  346. PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_CLK48;
  347. PeriphClkInitStruct.Clk48ClockSelection = RCC_CLK48CLKSOURCE_PLLQ;
  348. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
  349. {
  350. Error_Handler();
  351. }
  352. __HAL_RCC_GPIOA_CLK_ENABLE();
  353. /**USB_OTG_FS GPIO Configuration
  354. PA8 ------> USB_OTG_FS_SOF
  355. PA10 ------> USB_OTG_FS_ID
  356. PA11 ------> USB_OTG_FS_DM
  357. PA12 ------> USB_OTG_FS_DP
  358. */
  359. GPIO_InitStruct.Pin = USB_SOF_Pin|USB_ID_Pin|USB_DM_Pin|USB_DP_Pin;
  360. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  361. GPIO_InitStruct.Pull = GPIO_NOPULL;
  362. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  363. GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
  364. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  365. /* Peripheral clock enable */
  366. __HAL_RCC_USB_OTG_FS_CLK_ENABLE();
  367. /* USER CODE BEGIN USB_OTG_FS_MspInit 1 */
  368. /* USER CODE END USB_OTG_FS_MspInit 1 */
  369. }
  370. }
  371. /**
  372. * @brief PCD MSP De-Initialization
  373. * This function freeze the hardware resources used in this example
  374. * @param hpcd: PCD handle pointer
  375. * @retval None
  376. */
  377. void HAL_PCD_MspDeInit(PCD_HandleTypeDef* hpcd)
  378. {
  379. if(hpcd->Instance==USB_OTG_FS)
  380. {
  381. /* USER CODE BEGIN USB_OTG_FS_MspDeInit 0 */
  382. /* USER CODE END USB_OTG_FS_MspDeInit 0 */
  383. /* Peripheral clock disable */
  384. __HAL_RCC_USB_OTG_FS_CLK_DISABLE();
  385. /**USB_OTG_FS GPIO Configuration
  386. PA8 ------> USB_OTG_FS_SOF
  387. PA10 ------> USB_OTG_FS_ID
  388. PA11 ------> USB_OTG_FS_DM
  389. PA12 ------> USB_OTG_FS_DP
  390. */
  391. HAL_GPIO_DeInit(GPIOA, USB_SOF_Pin|USB_ID_Pin|USB_DM_Pin|USB_DP_Pin);
  392. /* USER CODE BEGIN USB_OTG_FS_MspDeInit 1 */
  393. /* USER CODE END USB_OTG_FS_MspDeInit 1 */
  394. }
  395. }
  396. /* USER CODE BEGIN 1 */
  397. /* USER CODE END 1 */