1
0

stm32f4xx_hal_msp.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  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. /* USER CODE END Includes */
  45. /* Private typedef -----------------------------------------------------------*/
  46. /* USER CODE BEGIN TD */
  47. /* USER CODE END TD */
  48. /* Private define ------------------------------------------------------------*/
  49. /* USER CODE BEGIN Define */
  50. /* USER CODE END Define */
  51. /* Private macro -------------------------------------------------------------*/
  52. /* USER CODE BEGIN Macro */
  53. /* USER CODE END Macro */
  54. /* Private variables ---------------------------------------------------------*/
  55. /* USER CODE BEGIN PV */
  56. /* USER CODE END PV */
  57. /* Private function prototypes -----------------------------------------------*/
  58. /* USER CODE BEGIN PFP */
  59. /* USER CODE END PFP */
  60. /* External functions --------------------------------------------------------*/
  61. /* USER CODE BEGIN ExternalFunctions */
  62. /* USER CODE END ExternalFunctions */
  63. /* USER CODE BEGIN 0 */
  64. /* USER CODE END 0 */
  65. void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);
  66. /**
  67. * Initializes the Global MSP.
  68. */
  69. void HAL_MspInit(void)
  70. {
  71. /* USER CODE BEGIN MspInit 0 */
  72. /* USER CODE END MspInit 0 */
  73. __HAL_RCC_SYSCFG_CLK_ENABLE();
  74. __HAL_RCC_PWR_CLK_ENABLE();
  75. /* System interrupt init*/
  76. /* USER CODE BEGIN MspInit 1 */
  77. /* USER CODE END MspInit 1 */
  78. }
  79. /**
  80. * @brief ADC MSP Initialization
  81. * This function configures the hardware resources used in this example
  82. * @param hadc: ADC handle pointer
  83. * @retval None
  84. */
  85. void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
  86. {
  87. GPIO_InitTypeDef GPIO_InitStruct = {0};
  88. if(hadc->Instance==ADC1)
  89. {
  90. /* USER CODE BEGIN ADC1_MspInit 0 */
  91. /* USER CODE END ADC1_MspInit 0 */
  92. /* Peripheral clock enable */
  93. __HAL_RCC_ADC1_CLK_ENABLE();
  94. __HAL_RCC_GPIOC_CLK_ENABLE();
  95. __HAL_RCC_GPIOA_CLK_ENABLE();
  96. __HAL_RCC_GPIOB_CLK_ENABLE();
  97. /**ADC1 GPIO Configuration
  98. PC0 ------> ADC1_IN10
  99. PC1 ------> ADC1_IN11
  100. PA0-WKUP ------> ADC1_IN0
  101. PA1 ------> ADC1_IN1
  102. PA4 ------> ADC1_IN4
  103. PB0 ------> ADC1_IN8
  104. */
  105. GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1;
  106. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  107. GPIO_InitStruct.Pull = GPIO_NOPULL;
  108. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  109. GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_4;
  110. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  111. GPIO_InitStruct.Pull = GPIO_NOPULL;
  112. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  113. GPIO_InitStruct.Pin = GPIO_PIN_0;
  114. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  115. GPIO_InitStruct.Pull = GPIO_NOPULL;
  116. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  117. /* USER CODE BEGIN ADC1_MspInit 1 */
  118. /* USER CODE END ADC1_MspInit 1 */
  119. }
  120. }
  121. /**
  122. * @brief ADC MSP De-Initialization
  123. * This function freeze the hardware resources used in this example
  124. * @param hadc: ADC handle pointer
  125. * @retval None
  126. */
  127. void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
  128. {
  129. if(hadc->Instance==ADC1)
  130. {
  131. /* USER CODE BEGIN ADC1_MspDeInit 0 */
  132. /* USER CODE END ADC1_MspDeInit 0 */
  133. /* Peripheral clock disable */
  134. __HAL_RCC_ADC1_CLK_DISABLE();
  135. /**ADC1 GPIO Configuration
  136. PC0 ------> ADC1_IN10
  137. PC1 ------> ADC1_IN11
  138. PA0-WKUP ------> ADC1_IN0
  139. PA1 ------> ADC1_IN1
  140. PA4 ------> ADC1_IN4
  141. PB0 ------> ADC1_IN8
  142. */
  143. HAL_GPIO_DeInit(GPIOC, GPIO_PIN_0|GPIO_PIN_1);
  144. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_4);
  145. HAL_GPIO_DeInit(GPIOB, GPIO_PIN_0);
  146. /* USER CODE BEGIN ADC1_MspDeInit 1 */
  147. /* USER CODE END ADC1_MspDeInit 1 */
  148. }
  149. }
  150. /**
  151. * @brief SPI MSP Initialization
  152. * This function configures the hardware resources used in this example
  153. * @param hspi: SPI handle pointer
  154. * @retval None
  155. */
  156. void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
  157. {
  158. GPIO_InitTypeDef GPIO_InitStruct = {0};
  159. if(hspi->Instance==SPI1)
  160. {
  161. /* USER CODE BEGIN SPI1_MspInit 0 */
  162. /* USER CODE END SPI1_MspInit 0 */
  163. /* Peripheral clock enable */
  164. __HAL_RCC_SPI1_CLK_ENABLE();
  165. __HAL_RCC_GPIOA_CLK_ENABLE();
  166. /**SPI1 GPIO Configuration
  167. PA5 ------> SPI1_SCK
  168. PA6 ------> SPI1_MISO
  169. PA7 ------> SPI1_MOSI
  170. */
  171. GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7;
  172. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  173. GPIO_InitStruct.Pull = GPIO_NOPULL;
  174. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  175. GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
  176. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  177. /* USER CODE BEGIN SPI1_MspInit 1 */
  178. /* USER CODE END SPI1_MspInit 1 */
  179. }
  180. }
  181. /**
  182. * @brief SPI MSP De-Initialization
  183. * This function freeze the hardware resources used in this example
  184. * @param hspi: SPI handle pointer
  185. * @retval None
  186. */
  187. void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
  188. {
  189. if(hspi->Instance==SPI1)
  190. {
  191. /* USER CODE BEGIN SPI1_MspDeInit 0 */
  192. /* USER CODE END SPI1_MspDeInit 0 */
  193. /* Peripheral clock disable */
  194. __HAL_RCC_SPI1_CLK_DISABLE();
  195. /**SPI1 GPIO Configuration
  196. PA5 ------> SPI1_SCK
  197. PA6 ------> SPI1_MISO
  198. PA7 ------> SPI1_MOSI
  199. */
  200. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7);
  201. /* USER CODE BEGIN SPI1_MspDeInit 1 */
  202. /* USER CODE END SPI1_MspDeInit 1 */
  203. }
  204. }
  205. /**
  206. * @brief TIM_PWM MSP Initialization
  207. * This function configures the hardware resources used in this example
  208. * @param htim_pwm: TIM_PWM handle pointer
  209. * @retval None
  210. */
  211. void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef* htim_pwm)
  212. {
  213. if(htim_pwm->Instance==TIM2)
  214. {
  215. /* USER CODE BEGIN TIM2_MspInit 0 */
  216. /* USER CODE END TIM2_MspInit 0 */
  217. /* Peripheral clock enable */
  218. __HAL_RCC_TIM2_CLK_ENABLE();
  219. /* USER CODE BEGIN TIM2_MspInit 1 */
  220. /* USER CODE END TIM2_MspInit 1 */
  221. }
  222. else if(htim_pwm->Instance==TIM3)
  223. {
  224. /* USER CODE BEGIN TIM3_MspInit 0 */
  225. /* USER CODE END TIM3_MspInit 0 */
  226. /* Peripheral clock enable */
  227. __HAL_RCC_TIM3_CLK_ENABLE();
  228. /* USER CODE BEGIN TIM3_MspInit 1 */
  229. /* USER CODE END TIM3_MspInit 1 */
  230. }
  231. }
  232. void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
  233. {
  234. GPIO_InitTypeDef GPIO_InitStruct = {0};
  235. if(htim->Instance==TIM2)
  236. {
  237. /* USER CODE BEGIN TIM2_MspPostInit 0 */
  238. /* USER CODE END TIM2_MspPostInit 0 */
  239. __HAL_RCC_GPIOB_CLK_ENABLE();
  240. /**TIM2 GPIO Configuration
  241. PB10 ------> TIM2_CH3
  242. PB3 ------> TIM2_CH2
  243. */
  244. GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_3;
  245. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  246. GPIO_InitStruct.Pull = GPIO_NOPULL;
  247. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  248. GPIO_InitStruct.Alternate = GPIO_AF1_TIM2;
  249. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  250. /* USER CODE BEGIN TIM2_MspPostInit 1 */
  251. /* USER CODE END TIM2_MspPostInit 1 */
  252. }
  253. else if(htim->Instance==TIM3)
  254. {
  255. /* USER CODE BEGIN TIM3_MspPostInit 0 */
  256. /* USER CODE END TIM3_MspPostInit 0 */
  257. __HAL_RCC_GPIOC_CLK_ENABLE();
  258. __HAL_RCC_GPIOB_CLK_ENABLE();
  259. /**TIM3 GPIO Configuration
  260. PC7 ------> TIM3_CH2
  261. PB4 ------> TIM3_CH1
  262. */
  263. GPIO_InitStruct.Pin = GPIO_PIN_7;
  264. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  265. GPIO_InitStruct.Pull = GPIO_NOPULL;
  266. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  267. GPIO_InitStruct.Alternate = GPIO_AF2_TIM3;
  268. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  269. GPIO_InitStruct.Pin = GPIO_PIN_4;
  270. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  271. GPIO_InitStruct.Pull = GPIO_NOPULL;
  272. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  273. GPIO_InitStruct.Alternate = GPIO_AF2_TIM3;
  274. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  275. /* USER CODE BEGIN TIM3_MspPostInit 1 */
  276. /* USER CODE END TIM3_MspPostInit 1 */
  277. }
  278. }
  279. /**
  280. * @brief TIM_PWM MSP De-Initialization
  281. * This function freeze the hardware resources used in this example
  282. * @param htim_pwm: TIM_PWM handle pointer
  283. * @retval None
  284. */
  285. void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef* htim_pwm)
  286. {
  287. if(htim_pwm->Instance==TIM2)
  288. {
  289. /* USER CODE BEGIN TIM2_MspDeInit 0 */
  290. /* USER CODE END TIM2_MspDeInit 0 */
  291. /* Peripheral clock disable */
  292. __HAL_RCC_TIM2_CLK_DISABLE();
  293. /* USER CODE BEGIN TIM2_MspDeInit 1 */
  294. /* USER CODE END TIM2_MspDeInit 1 */
  295. }
  296. else if(htim_pwm->Instance==TIM3)
  297. {
  298. /* USER CODE BEGIN TIM3_MspDeInit 0 */
  299. /* USER CODE END TIM3_MspDeInit 0 */
  300. /* Peripheral clock disable */
  301. __HAL_RCC_TIM3_CLK_DISABLE();
  302. /* USER CODE BEGIN TIM3_MspDeInit 1 */
  303. /* USER CODE END TIM3_MspDeInit 1 */
  304. }
  305. }
  306. /**
  307. * @brief UART MSP Initialization
  308. * This function configures the hardware resources used in this example
  309. * @param huart: UART handle pointer
  310. * @retval None
  311. */
  312. void HAL_UART_MspInit(UART_HandleTypeDef* huart)
  313. {
  314. GPIO_InitTypeDef GPIO_InitStruct = {0};
  315. if(huart->Instance==USART2)
  316. {
  317. /* USER CODE BEGIN USART2_MspInit 0 */
  318. /* USER CODE END USART2_MspInit 0 */
  319. /* Peripheral clock enable */
  320. __HAL_RCC_USART2_CLK_ENABLE();
  321. __HAL_RCC_GPIOA_CLK_ENABLE();
  322. /**USART2 GPIO Configuration
  323. PA2 ------> USART2_TX
  324. PA3 ------> USART2_RX
  325. */
  326. GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3;
  327. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  328. GPIO_InitStruct.Pull = GPIO_PULLUP;
  329. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  330. GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
  331. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  332. /* USER CODE BEGIN USART2_MspInit 1 */
  333. /* USER CODE END USART2_MspInit 1 */
  334. }
  335. }
  336. /**
  337. * @brief UART MSP De-Initialization
  338. * This function freeze the hardware resources used in this example
  339. * @param huart: UART handle pointer
  340. * @retval None
  341. */
  342. void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
  343. {
  344. if(huart->Instance==USART2)
  345. {
  346. /* USER CODE BEGIN USART2_MspDeInit 0 */
  347. /* USER CODE END USART2_MspDeInit 0 */
  348. /* Peripheral clock disable */
  349. __HAL_RCC_USART2_CLK_DISABLE();
  350. /**USART2 GPIO Configuration
  351. PA2 ------> USART2_TX
  352. PA3 ------> USART2_RX
  353. */
  354. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3);
  355. /* USER CODE BEGIN USART2_MspDeInit 1 */
  356. /* USER CODE END USART2_MspDeInit 1 */
  357. }
  358. }
  359. /* USER CODE BEGIN 1 */
  360. /* USER CODE END 1 */