stm32f1xx_hal_msp.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * File Name : stm32f1xx_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) 2019 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. /**
  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_AFIO_CLK_ENABLE();
  74. __HAL_RCC_PWR_CLK_ENABLE();
  75. /* System interrupt init*/
  76. /**NOJTAG: JTAG-DP Disabled and SW-DP Enabled
  77. */
  78. __HAL_AFIO_REMAP_SWJ_NOJTAG();
  79. /* USER CODE BEGIN MspInit 1 */
  80. /* USER CODE END MspInit 1 */
  81. }
  82. /**
  83. * @brief ADC MSP Initialization
  84. * This function configures the hardware resources used in this example
  85. * @param hadc: ADC handle pointer
  86. * @retval None
  87. */
  88. void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
  89. {
  90. GPIO_InitTypeDef GPIO_InitStruct = {0};
  91. if(hadc->Instance==ADC1)
  92. {
  93. /* USER CODE BEGIN ADC1_MspInit 0 */
  94. /* USER CODE END ADC1_MspInit 0 */
  95. /* Peripheral clock enable */
  96. __HAL_RCC_ADC1_CLK_ENABLE();
  97. __HAL_RCC_GPIOC_CLK_ENABLE();
  98. /**ADC1 GPIO Configuration
  99. PC0 ------> ADC1_IN10
  100. PC1 ------> ADC1_IN11
  101. */
  102. GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1;
  103. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  104. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  105. /* USER CODE BEGIN ADC1_MspInit 1 */
  106. /* USER CODE END ADC1_MspInit 1 */
  107. }
  108. }
  109. /**
  110. * @brief ADC MSP De-Initialization
  111. * This function freeze the hardware resources used in this example
  112. * @param hadc: ADC handle pointer
  113. * @retval None
  114. */
  115. void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
  116. {
  117. if(hadc->Instance==ADC1)
  118. {
  119. /* USER CODE BEGIN ADC1_MspDeInit 0 */
  120. /* USER CODE END ADC1_MspDeInit 0 */
  121. /* Peripheral clock disable */
  122. __HAL_RCC_ADC1_CLK_DISABLE();
  123. /**ADC1 GPIO Configuration
  124. PC0 ------> ADC1_IN10
  125. PC1 ------> ADC1_IN11
  126. */
  127. HAL_GPIO_DeInit(GPIOC, GPIO_PIN_0|GPIO_PIN_1);
  128. /* USER CODE BEGIN ADC1_MspDeInit 1 */
  129. /* USER CODE END ADC1_MspDeInit 1 */
  130. }
  131. }
  132. /**
  133. * @brief RTC MSP Initialization
  134. * This function configures the hardware resources used in this example
  135. * @param hrtc: RTC handle pointer
  136. * @retval None
  137. */
  138. void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc)
  139. {
  140. if(hrtc->Instance==RTC)
  141. {
  142. /* USER CODE BEGIN RTC_MspInit 0 */
  143. /* USER CODE END RTC_MspInit 0 */
  144. HAL_PWR_EnableBkUpAccess();
  145. /* Enable BKP CLK enable for backup registers */
  146. __HAL_RCC_BKP_CLK_ENABLE();
  147. /* Peripheral clock enable */
  148. __HAL_RCC_RTC_ENABLE();
  149. /* USER CODE BEGIN RTC_MspInit 1 */
  150. /* USER CODE END RTC_MspInit 1 */
  151. }
  152. }
  153. /**
  154. * @brief RTC MSP De-Initialization
  155. * This function freeze the hardware resources used in this example
  156. * @param hrtc: RTC handle pointer
  157. * @retval None
  158. */
  159. void HAL_RTC_MspDeInit(RTC_HandleTypeDef* hrtc)
  160. {
  161. if(hrtc->Instance==RTC)
  162. {
  163. /* USER CODE BEGIN RTC_MspDeInit 0 */
  164. /* USER CODE END RTC_MspDeInit 0 */
  165. /* Peripheral clock disable */
  166. __HAL_RCC_RTC_DISABLE();
  167. /* USER CODE BEGIN RTC_MspDeInit 1 */
  168. /* USER CODE END RTC_MspDeInit 1 */
  169. }
  170. }
  171. /**
  172. * @brief SPI MSP Initialization
  173. * This function configures the hardware resources used in this example
  174. * @param hspi: SPI handle pointer
  175. * @retval None
  176. */
  177. void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
  178. {
  179. GPIO_InitTypeDef GPIO_InitStruct = {0};
  180. if(hspi->Instance==SPI1)
  181. {
  182. /* USER CODE BEGIN SPI1_MspInit 0 */
  183. /* USER CODE END SPI1_MspInit 0 */
  184. /* Peripheral clock enable */
  185. __HAL_RCC_SPI1_CLK_ENABLE();
  186. __HAL_RCC_GPIOA_CLK_ENABLE();
  187. /**SPI1 GPIO Configuration
  188. PA5 ------> SPI1_SCK
  189. PA6 ------> SPI1_MISO
  190. PA7 ------> SPI1_MOSI
  191. */
  192. GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_7;
  193. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  194. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  195. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  196. GPIO_InitStruct.Pin = GPIO_PIN_6;
  197. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  198. GPIO_InitStruct.Pull = GPIO_NOPULL;
  199. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  200. /* USER CODE BEGIN SPI1_MspInit 1 */
  201. /* USER CODE END SPI1_MspInit 1 */
  202. }
  203. else if(hspi->Instance==SPI2)
  204. {
  205. /* USER CODE BEGIN SPI2_MspInit 0 */
  206. /* USER CODE END SPI2_MspInit 0 */
  207. /* Peripheral clock enable */
  208. __HAL_RCC_SPI2_CLK_ENABLE();
  209. __HAL_RCC_GPIOB_CLK_ENABLE();
  210. /**SPI2 GPIO Configuration
  211. PB13 ------> SPI2_SCK
  212. PB14 ------> SPI2_MISO
  213. PB15 ------> SPI2_MOSI
  214. */
  215. GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_15;
  216. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  217. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  218. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  219. GPIO_InitStruct.Pin = GPIO_PIN_14;
  220. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  221. GPIO_InitStruct.Pull = GPIO_NOPULL;
  222. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  223. /* USER CODE BEGIN SPI2_MspInit 1 */
  224. /* USER CODE END SPI2_MspInit 1 */
  225. }
  226. }
  227. /**
  228. * @brief SPI MSP De-Initialization
  229. * This function freeze the hardware resources used in this example
  230. * @param hspi: SPI handle pointer
  231. * @retval None
  232. */
  233. void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
  234. {
  235. if(hspi->Instance==SPI1)
  236. {
  237. /* USER CODE BEGIN SPI1_MspDeInit 0 */
  238. /* USER CODE END SPI1_MspDeInit 0 */
  239. /* Peripheral clock disable */
  240. __HAL_RCC_SPI1_CLK_DISABLE();
  241. /**SPI1 GPIO Configuration
  242. PA5 ------> SPI1_SCK
  243. PA6 ------> SPI1_MISO
  244. PA7 ------> SPI1_MOSI
  245. */
  246. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7);
  247. /* USER CODE BEGIN SPI1_MspDeInit 1 */
  248. /* USER CODE END SPI1_MspDeInit 1 */
  249. }
  250. else if(hspi->Instance==SPI2)
  251. {
  252. /* USER CODE BEGIN SPI2_MspDeInit 0 */
  253. /* USER CODE END SPI2_MspDeInit 0 */
  254. /* Peripheral clock disable */
  255. __HAL_RCC_SPI2_CLK_DISABLE();
  256. /**SPI2 GPIO Configuration
  257. PB13 ------> SPI2_SCK
  258. PB14 ------> SPI2_MISO
  259. PB15 ------> SPI2_MOSI
  260. */
  261. HAL_GPIO_DeInit(GPIOB, GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15);
  262. /* USER CODE BEGIN SPI2_MspDeInit 1 */
  263. /* USER CODE END SPI2_MspDeInit 1 */
  264. }
  265. }
  266. /**
  267. * @brief UART MSP Initialization
  268. * This function configures the hardware resources used in this example
  269. * @param huart: UART handle pointer
  270. * @retval None
  271. */
  272. void HAL_UART_MspInit(UART_HandleTypeDef* huart)
  273. {
  274. GPIO_InitTypeDef GPIO_InitStruct = {0};
  275. if(huart->Instance==UART4)
  276. {
  277. /* USER CODE BEGIN UART4_MspInit 0 */
  278. /* USER CODE END UART4_MspInit 0 */
  279. /* Peripheral clock enable */
  280. __HAL_RCC_UART4_CLK_ENABLE();
  281. __HAL_RCC_GPIOC_CLK_ENABLE();
  282. /**UART4 GPIO Configuration
  283. PC10 ------> UART4_TX
  284. PC11 ------> UART4_RX
  285. */
  286. GPIO_InitStruct.Pin = GPIO_PIN_10;
  287. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  288. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  289. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  290. GPIO_InitStruct.Pin = GPIO_PIN_11;
  291. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  292. GPIO_InitStruct.Pull = GPIO_PULLUP;
  293. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  294. /* USER CODE BEGIN UART4_MspInit 1 */
  295. /* USER CODE END UART4_MspInit 1 */
  296. }
  297. else if(huart->Instance==USART1)
  298. {
  299. /* USER CODE BEGIN USART1_MspInit 0 */
  300. /* USER CODE END USART1_MspInit 0 */
  301. /* Peripheral clock enable */
  302. __HAL_RCC_USART1_CLK_ENABLE();
  303. __HAL_RCC_GPIOA_CLK_ENABLE();
  304. /**USART1 GPIO Configuration
  305. PA9 ------> USART1_TX
  306. PA10 ------> USART1_RX
  307. */
  308. GPIO_InitStruct.Pin = GPIO_PIN_9;
  309. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  310. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  311. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  312. GPIO_InitStruct.Pin = GPIO_PIN_10;
  313. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  314. GPIO_InitStruct.Pull = GPIO_PULLUP;
  315. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  316. /* USER CODE BEGIN USART1_MspInit 1 */
  317. /* USER CODE END USART1_MspInit 1 */
  318. }
  319. else if(huart->Instance==USART2)
  320. {
  321. /* USER CODE BEGIN USART2_MspInit 0 */
  322. /* USER CODE END USART2_MspInit 0 */
  323. /* Peripheral clock enable */
  324. __HAL_RCC_USART2_CLK_ENABLE();
  325. __HAL_RCC_GPIOA_CLK_ENABLE();
  326. /**USART2 GPIO Configuration
  327. PA2 ------> USART2_TX
  328. PA3 ------> USART2_RX
  329. */
  330. GPIO_InitStruct.Pin = GPIO_PIN_2;
  331. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  332. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  333. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  334. GPIO_InitStruct.Pin = GPIO_PIN_3;
  335. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  336. GPIO_InitStruct.Pull = GPIO_PULLUP;
  337. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  338. /* USER CODE BEGIN USART2_MspInit 1 */
  339. /* USER CODE END USART2_MspInit 1 */
  340. }
  341. else if(huart->Instance==USART3)
  342. {
  343. /* USER CODE BEGIN USART3_MspInit 0 */
  344. /* USER CODE END USART3_MspInit 0 */
  345. /* Peripheral clock enable */
  346. __HAL_RCC_USART3_CLK_ENABLE();
  347. __HAL_RCC_GPIOB_CLK_ENABLE();
  348. /**USART3 GPIO Configuration
  349. PB10 ------> USART3_TX
  350. PB11 ------> USART3_RX
  351. */
  352. GPIO_InitStruct.Pin = GPIO_PIN_10;
  353. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  354. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  355. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  356. GPIO_InitStruct.Pin = GPIO_PIN_11;
  357. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  358. GPIO_InitStruct.Pull = GPIO_PULLUP;
  359. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  360. /* USER CODE BEGIN USART3_MspInit 1 */
  361. /* USER CODE END USART3_MspInit 1 */
  362. }
  363. }
  364. /**
  365. * @brief UART MSP De-Initialization
  366. * This function freeze the hardware resources used in this example
  367. * @param huart: UART handle pointer
  368. * @retval None
  369. */
  370. void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
  371. {
  372. if(huart->Instance==UART4)
  373. {
  374. /* USER CODE BEGIN UART4_MspDeInit 0 */
  375. /* USER CODE END UART4_MspDeInit 0 */
  376. /* Peripheral clock disable */
  377. __HAL_RCC_UART4_CLK_DISABLE();
  378. /**UART4 GPIO Configuration
  379. PC10 ------> UART4_TX
  380. PC11 ------> UART4_RX
  381. */
  382. HAL_GPIO_DeInit(GPIOC, GPIO_PIN_10|GPIO_PIN_11);
  383. /* USER CODE BEGIN UART4_MspDeInit 1 */
  384. /* USER CODE END UART4_MspDeInit 1 */
  385. }
  386. else if(huart->Instance==USART1)
  387. {
  388. /* USER CODE BEGIN USART1_MspDeInit 0 */
  389. /* USER CODE END USART1_MspDeInit 0 */
  390. /* Peripheral clock disable */
  391. __HAL_RCC_USART1_CLK_DISABLE();
  392. /**USART1 GPIO Configuration
  393. PA9 ------> USART1_TX
  394. PA10 ------> USART1_RX
  395. */
  396. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10);
  397. /* USER CODE BEGIN USART1_MspDeInit 1 */
  398. /* USER CODE END USART1_MspDeInit 1 */
  399. }
  400. else if(huart->Instance==USART2)
  401. {
  402. /* USER CODE BEGIN USART2_MspDeInit 0 */
  403. /* USER CODE END USART2_MspDeInit 0 */
  404. /* Peripheral clock disable */
  405. __HAL_RCC_USART2_CLK_DISABLE();
  406. /**USART2 GPIO Configuration
  407. PA2 ------> USART2_TX
  408. PA3 ------> USART2_RX
  409. */
  410. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3);
  411. /* USER CODE BEGIN USART2_MspDeInit 1 */
  412. /* USER CODE END USART2_MspDeInit 1 */
  413. }
  414. else if(huart->Instance==USART3)
  415. {
  416. /* USER CODE BEGIN USART3_MspDeInit 0 */
  417. /* USER CODE END USART3_MspDeInit 0 */
  418. /* Peripheral clock disable */
  419. __HAL_RCC_USART3_CLK_DISABLE();
  420. /**USART3 GPIO Configuration
  421. PB10 ------> USART3_TX
  422. PB11 ------> USART3_RX
  423. */
  424. HAL_GPIO_DeInit(GPIOB, GPIO_PIN_10|GPIO_PIN_11);
  425. /* USER CODE BEGIN USART3_MspDeInit 1 */
  426. /* USER CODE END USART3_MspDeInit 1 */
  427. }
  428. }
  429. /* USER CODE BEGIN 1 */
  430. /* USER CODE END 1 */
  431. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/