stm32f1xx_hal_msp.c 13 KB

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