stm32f1xx_hal_msp.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  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. #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_AFIO_CLK_ENABLE();
  75. __HAL_RCC_PWR_CLK_ENABLE();
  76. /* System interrupt init*/
  77. /**NOJTAG: JTAG-DP Disabled and SW-DP Enabled
  78. */
  79. __HAL_AFIO_REMAP_SWJ_NOJTAG();
  80. /* USER CODE BEGIN MspInit 1 */
  81. /* USER CODE END MspInit 1 */
  82. }
  83. /**
  84. * @brief ADC MSP Initialization
  85. * This function configures the hardware resources used in this example
  86. * @param hadc: ADC handle pointer
  87. * @retval None
  88. */
  89. void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
  90. {
  91. GPIO_InitTypeDef GPIO_InitStruct = {0};
  92. if(hadc->Instance==ADC1)
  93. {
  94. /* USER CODE BEGIN ADC1_MspInit 0 */
  95. /* USER CODE END ADC1_MspInit 0 */
  96. /* Peripheral clock enable */
  97. __HAL_RCC_ADC1_CLK_ENABLE();
  98. __HAL_RCC_GPIOB_CLK_ENABLE();
  99. /**ADC1 GPIO Configuration
  100. PB1 ------> ADC1_IN9
  101. */
  102. GPIO_InitStruct.Pin = GPIO_PIN_1;
  103. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  104. HAL_GPIO_Init(GPIOB, &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. PB1 ------> ADC1_IN9
  125. */
  126. HAL_GPIO_DeInit(GPIOB, GPIO_PIN_1);
  127. /* USER CODE BEGIN ADC1_MspDeInit 1 */
  128. /* USER CODE END ADC1_MspDeInit 1 */
  129. }
  130. }
  131. /**
  132. * @brief RTC MSP Initialization
  133. * This function configures the hardware resources used in this example
  134. * @param hrtc: RTC handle pointer
  135. * @retval None
  136. */
  137. void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc)
  138. {
  139. if(hrtc->Instance==RTC)
  140. {
  141. /* USER CODE BEGIN RTC_MspInit 0 */
  142. /* USER CODE END RTC_MspInit 0 */
  143. HAL_PWR_EnableBkUpAccess();
  144. /* Enable BKP CLK enable for backup registers */
  145. __HAL_RCC_BKP_CLK_ENABLE();
  146. /* Peripheral clock enable */
  147. __HAL_RCC_RTC_ENABLE();
  148. /* USER CODE BEGIN RTC_MspInit 1 */
  149. /* USER CODE END RTC_MspInit 1 */
  150. }
  151. }
  152. /**
  153. * @brief RTC MSP De-Initialization
  154. * This function freeze the hardware resources used in this example
  155. * @param hrtc: RTC handle pointer
  156. * @retval None
  157. */
  158. void HAL_RTC_MspDeInit(RTC_HandleTypeDef* hrtc)
  159. {
  160. if(hrtc->Instance==RTC)
  161. {
  162. /* USER CODE BEGIN RTC_MspDeInit 0 */
  163. /* USER CODE END RTC_MspDeInit 0 */
  164. /* Peripheral clock disable */
  165. __HAL_RCC_RTC_DISABLE();
  166. /* USER CODE BEGIN RTC_MspDeInit 1 */
  167. /* USER CODE END RTC_MspDeInit 1 */
  168. }
  169. }
  170. /**
  171. * @brief SPI MSP Initialization
  172. * This function configures the hardware resources used in this example
  173. * @param hspi: SPI handle pointer
  174. * @retval None
  175. */
  176. void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
  177. {
  178. GPIO_InitTypeDef GPIO_InitStruct = {0};
  179. if(hspi->Instance==SPI2)
  180. {
  181. /* USER CODE BEGIN SPI2_MspInit 0 */
  182. /* USER CODE END SPI2_MspInit 0 */
  183. /* Peripheral clock enable */
  184. __HAL_RCC_SPI2_CLK_ENABLE();
  185. __HAL_RCC_GPIOB_CLK_ENABLE();
  186. /**SPI2 GPIO Configuration
  187. PB13 ------> SPI2_SCK
  188. PB14 ------> SPI2_MISO
  189. PB15 ------> SPI2_MOSI
  190. */
  191. GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_15;
  192. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  193. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  194. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  195. GPIO_InitStruct.Pin = GPIO_PIN_14;
  196. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  197. GPIO_InitStruct.Pull = GPIO_NOPULL;
  198. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  199. /* USER CODE BEGIN SPI2_MspInit 1 */
  200. /* USER CODE END SPI2_MspInit 1 */
  201. }
  202. }
  203. /**
  204. * @brief SPI MSP De-Initialization
  205. * This function freeze the hardware resources used in this example
  206. * @param hspi: SPI handle pointer
  207. * @retval None
  208. */
  209. void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
  210. {
  211. if(hspi->Instance==SPI2)
  212. {
  213. /* USER CODE BEGIN SPI2_MspDeInit 0 */
  214. /* USER CODE END SPI2_MspDeInit 0 */
  215. /* Peripheral clock disable */
  216. __HAL_RCC_SPI2_CLK_DISABLE();
  217. /**SPI2 GPIO Configuration
  218. PB13 ------> SPI2_SCK
  219. PB14 ------> SPI2_MISO
  220. PB15 ------> SPI2_MOSI
  221. */
  222. HAL_GPIO_DeInit(GPIOB, GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15);
  223. /* USER CODE BEGIN SPI2_MspDeInit 1 */
  224. /* USER CODE END SPI2_MspDeInit 1 */
  225. }
  226. }
  227. /**
  228. * @brief TIM_Base MSP Initialization
  229. * This function configures the hardware resources used in this example
  230. * @param htim_base: TIM_Base handle pointer
  231. * @retval None
  232. */
  233. void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
  234. {
  235. if(htim_base->Instance==TIM2)
  236. {
  237. /* USER CODE BEGIN TIM2_MspInit 0 */
  238. /* USER CODE END TIM2_MspInit 0 */
  239. /* Peripheral clock enable */
  240. __HAL_RCC_TIM2_CLK_ENABLE();
  241. /* USER CODE BEGIN TIM2_MspInit 1 */
  242. /* USER CODE END TIM2_MspInit 1 */
  243. }
  244. else if(htim_base->Instance==TIM3)
  245. {
  246. /* USER CODE BEGIN TIM3_MspInit 0 */
  247. /* USER CODE END TIM3_MspInit 0 */
  248. /* Peripheral clock enable */
  249. __HAL_RCC_TIM3_CLK_ENABLE();
  250. /* USER CODE BEGIN TIM3_MspInit 1 */
  251. /* USER CODE END TIM3_MspInit 1 */
  252. }
  253. else if(htim_base->Instance==TIM4)
  254. {
  255. /* USER CODE BEGIN TIM4_MspInit 0 */
  256. /* USER CODE END TIM4_MspInit 0 */
  257. /* Peripheral clock enable */
  258. __HAL_RCC_TIM4_CLK_ENABLE();
  259. /* USER CODE BEGIN TIM4_MspInit 1 */
  260. /* USER CODE END TIM4_MspInit 1 */
  261. }
  262. }
  263. void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
  264. {
  265. GPIO_InitTypeDef GPIO_InitStruct = {0};
  266. if(htim->Instance==TIM3)
  267. {
  268. /* USER CODE BEGIN TIM3_MspPostInit 0 */
  269. /* USER CODE END TIM3_MspPostInit 0 */
  270. __HAL_RCC_GPIOC_CLK_ENABLE();
  271. /**TIM3 GPIO Configuration
  272. PC6 ------> TIM3_CH1
  273. PC7 ------> TIM3_CH2
  274. */
  275. GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
  276. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  277. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  278. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  279. __HAL_AFIO_REMAP_TIM3_ENABLE();
  280. /* USER CODE BEGIN TIM3_MspPostInit 1 */
  281. /* USER CODE END TIM3_MspPostInit 1 */
  282. }
  283. }
  284. /**
  285. * @brief TIM_Base MSP De-Initialization
  286. * This function freeze the hardware resources used in this example
  287. * @param htim_base: TIM_Base handle pointer
  288. * @retval None
  289. */
  290. void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
  291. {
  292. if(htim_base->Instance==TIM2)
  293. {
  294. /* USER CODE BEGIN TIM2_MspDeInit 0 */
  295. /* USER CODE END TIM2_MspDeInit 0 */
  296. /* Peripheral clock disable */
  297. __HAL_RCC_TIM2_CLK_DISABLE();
  298. /* USER CODE BEGIN TIM2_MspDeInit 1 */
  299. /* USER CODE END TIM2_MspDeInit 1 */
  300. }
  301. else if(htim_base->Instance==TIM3)
  302. {
  303. /* USER CODE BEGIN TIM3_MspDeInit 0 */
  304. /* USER CODE END TIM3_MspDeInit 0 */
  305. /* Peripheral clock disable */
  306. __HAL_RCC_TIM3_CLK_DISABLE();
  307. /* USER CODE BEGIN TIM3_MspDeInit 1 */
  308. /* USER CODE END TIM3_MspDeInit 1 */
  309. }
  310. else if(htim_base->Instance==TIM4)
  311. {
  312. /* USER CODE BEGIN TIM4_MspDeInit 0 */
  313. /* USER CODE END TIM4_MspDeInit 0 */
  314. /* Peripheral clock disable */
  315. __HAL_RCC_TIM4_CLK_DISABLE();
  316. /* USER CODE BEGIN TIM4_MspDeInit 1 */
  317. /* USER CODE END TIM4_MspDeInit 1 */
  318. }
  319. }
  320. /**
  321. * @brief UART MSP Initialization
  322. * This function configures the hardware resources used in this example
  323. * @param huart: UART handle pointer
  324. * @retval None
  325. */
  326. void HAL_UART_MspInit(UART_HandleTypeDef* huart)
  327. {
  328. GPIO_InitTypeDef GPIO_InitStruct = {0};
  329. if(huart->Instance==USART1)
  330. {
  331. /* USER CODE BEGIN USART1_MspInit 0 */
  332. /* USER CODE END USART1_MspInit 0 */
  333. /* Peripheral clock enable */
  334. __HAL_RCC_USART1_CLK_ENABLE();
  335. __HAL_RCC_GPIOA_CLK_ENABLE();
  336. /**USART1 GPIO Configuration
  337. PA9 ------> USART1_TX
  338. PA10 ------> USART1_RX
  339. */
  340. GPIO_InitStruct.Pin = GPIO_PIN_9;
  341. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  342. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  343. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  344. GPIO_InitStruct.Pin = GPIO_PIN_10;
  345. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  346. GPIO_InitStruct.Pull = GPIO_PULLUP;
  347. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  348. /* USART1 interrupt Init */
  349. HAL_NVIC_SetPriority(USART1_IRQn, 5, 0);
  350. HAL_NVIC_EnableIRQ(USART1_IRQn);
  351. /* USER CODE BEGIN USART1_MspInit 1 */
  352. /* USER CODE END USART1_MspInit 1 */
  353. }
  354. }
  355. /**
  356. * @brief UART MSP De-Initialization
  357. * This function freeze the hardware resources used in this example
  358. * @param huart: UART handle pointer
  359. * @retval None
  360. */
  361. void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
  362. {
  363. if(huart->Instance==USART1)
  364. {
  365. /* USER CODE BEGIN USART1_MspDeInit 0 */
  366. /* USER CODE END USART1_MspDeInit 0 */
  367. /* Peripheral clock disable */
  368. __HAL_RCC_USART1_CLK_DISABLE();
  369. /**USART1 GPIO Configuration
  370. PA9 ------> USART1_TX
  371. PA10 ------> USART1_RX
  372. */
  373. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10);
  374. /* USART1 interrupt DeInit */
  375. HAL_NVIC_DisableIRQ(USART1_IRQn);
  376. /* USER CODE BEGIN USART1_MspDeInit 1 */
  377. /* USER CODE END USART1_MspDeInit 1 */
  378. }
  379. }
  380. /* USER CODE BEGIN 1 */
  381. /* USER CODE END 1 */
  382. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/