1
0

stm32u5xx_hal_msp.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file stm32u5xx_hal_msp.c
  5. * @brief This file provides code for the MSP Initialization
  6. * and de-Initialization codes.
  7. ******************************************************************************
  8. * @attention
  9. *
  10. * <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
  11. * All rights reserved.</center></h2>
  12. *
  13. * This software component is licensed by ST under BSD 3-Clause license,
  14. * the "License"; You may not use this file except in compliance with the
  15. * License. You may obtain a copy of the License at:
  16. * opensource.org/licenses/BSD-3-Clause
  17. *
  18. ******************************************************************************
  19. */
  20. /* USER CODE END Header */
  21. /* Includes ------------------------------------------------------------------*/
  22. #include "main.h"
  23. /* USER CODE BEGIN Includes */
  24. /* USER CODE END Includes */
  25. /* Private typedef -----------------------------------------------------------*/
  26. /* USER CODE BEGIN TD */
  27. /* USER CODE END TD */
  28. /* Private define ------------------------------------------------------------*/
  29. /* USER CODE BEGIN Define */
  30. /* USER CODE END Define */
  31. /* Private macro -------------------------------------------------------------*/
  32. /* USER CODE BEGIN Macro */
  33. /* USER CODE END Macro */
  34. /* Private variables ---------------------------------------------------------*/
  35. /* USER CODE BEGIN PV */
  36. /* USER CODE END PV */
  37. /* Private function prototypes -----------------------------------------------*/
  38. /* USER CODE BEGIN PFP */
  39. /* USER CODE END PFP */
  40. /* External functions --------------------------------------------------------*/
  41. /* USER CODE BEGIN ExternalFunctions */
  42. /* USER CODE END ExternalFunctions */
  43. /* USER CODE BEGIN 0 */
  44. /* USER CODE END 0 */
  45. /**
  46. * Initializes the Global MSP.
  47. */
  48. void HAL_MspInit(void)
  49. {
  50. /* USER CODE BEGIN MspInit 0 */
  51. /* USER CODE END MspInit 0 */
  52. __HAL_RCC_PWR_CLK_ENABLE();
  53. HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_3);
  54. /* System interrupt init*/
  55. HAL_PWREx_EnableVddIO2();
  56. /* USER CODE BEGIN MspInit 1 */
  57. /* Configure ICACHE associativity mode */
  58. HAL_ICACHE_ConfigAssociativityMode(ICACHE_1WAY);
  59. /* Enable ICACHE */
  60. HAL_ICACHE_Enable();
  61. /* USER CODE END MspInit 1 */
  62. }
  63. /**
  64. * @brief ADC MSP Initialization
  65. * This function configures the hardware resources used in this example
  66. * @param hadc: ADC handle pointer
  67. * @retval None
  68. */
  69. void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
  70. {
  71. GPIO_InitTypeDef GPIO_InitStruct = {0};
  72. RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
  73. if(hadc->Instance==ADC1)
  74. {
  75. /* USER CODE BEGIN ADC1_MspInit 0 */
  76. /* USER CODE END ADC1_MspInit 0 */
  77. /** Initializes the peripherals clock
  78. */
  79. PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADCDAC;
  80. PeriphClkInit.AdcDacClockSelection = RCC_ADCDACCLKSOURCE_HSI;
  81. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  82. {
  83. Error_Handler();
  84. }
  85. /* Peripheral clock enable */
  86. __HAL_RCC_ADC1_CLK_ENABLE();
  87. __HAL_RCC_GPIOC_CLK_ENABLE();
  88. /**ADC1 GPIO Configuration
  89. PC2 ------> ADC1_IN3
  90. */
  91. GPIO_InitStruct.Pin = VBUS_SENSE_Pin;
  92. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  93. GPIO_InitStruct.Pull = GPIO_NOPULL;
  94. HAL_GPIO_Init(VBUS_SENSE_GPIO_Port, &GPIO_InitStruct);
  95. /* USER CODE BEGIN ADC1_MspInit 1 */
  96. /* USER CODE END ADC1_MspInit 1 */
  97. }
  98. }
  99. /**
  100. * @brief ADC MSP De-Initialization
  101. * This function freeze the hardware resources used in this example
  102. * @param hadc: ADC handle pointer
  103. * @retval None
  104. */
  105. void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
  106. {
  107. if(hadc->Instance==ADC1)
  108. {
  109. /* USER CODE BEGIN ADC1_MspDeInit 0 */
  110. /* USER CODE END ADC1_MspDeInit 0 */
  111. /* Peripheral clock disable */
  112. __HAL_RCC_ADC1_CLK_DISABLE();
  113. /**ADC1 GPIO Configuration
  114. PC2 ------> ADC1_IN3
  115. */
  116. HAL_GPIO_DeInit(VBUS_SENSE_GPIO_Port, VBUS_SENSE_Pin);
  117. /* USER CODE BEGIN ADC1_MspDeInit 1 */
  118. /* USER CODE END ADC1_MspDeInit 1 */
  119. }
  120. }
  121. /**
  122. * @brief UART MSP Initialization
  123. * This function configures the hardware resources used in this example
  124. * @param huart: UART handle pointer
  125. * @retval None
  126. */
  127. void HAL_UART_MspInit(UART_HandleTypeDef* huart)
  128. {
  129. GPIO_InitTypeDef GPIO_InitStruct = {0};
  130. RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
  131. if(huart->Instance==USART1)
  132. {
  133. /* USER CODE BEGIN USART1_MspInit 0 */
  134. /* USER CODE END USART1_MspInit 0 */
  135. /** Initializes the peripherals clock
  136. */
  137. PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1;
  138. PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2;
  139. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  140. {
  141. Error_Handler();
  142. }
  143. /* Peripheral clock enable */
  144. __HAL_RCC_USART1_CLK_ENABLE();
  145. __HAL_RCC_GPIOA_CLK_ENABLE();
  146. /**USART1 GPIO Configuration
  147. PA9 ------> USART1_TX
  148. PA10 ------> USART1_RX
  149. */
  150. GPIO_InitStruct.Pin = USART1_TX_Pin|USART1_RX_Pin;
  151. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  152. GPIO_InitStruct.Pull = GPIO_PULLDOWN;
  153. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  154. GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
  155. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  156. /* USER CODE BEGIN USART1_MspInit 1 */
  157. /* USER CODE END USART1_MspInit 1 */
  158. }
  159. }
  160. /**
  161. * @brief UART MSP De-Initialization
  162. * This function freeze the hardware resources used in this example
  163. * @param huart: UART handle pointer
  164. * @retval None
  165. */
  166. void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
  167. {
  168. if(huart->Instance==USART1)
  169. {
  170. /* USER CODE BEGIN USART1_MspDeInit 0 */
  171. /* USER CODE END USART1_MspDeInit 0 */
  172. /* Peripheral clock disable */
  173. __HAL_RCC_USART1_CLK_DISABLE();
  174. /**USART1 GPIO Configuration
  175. PA9 ------> USART1_TX
  176. PA10 ------> USART1_RX
  177. */
  178. HAL_GPIO_DeInit(GPIOA, USART1_TX_Pin|USART1_RX_Pin);
  179. /* USER CODE BEGIN USART1_MspDeInit 1 */
  180. /* USER CODE END USART1_MspDeInit 1 */
  181. }
  182. }
  183. /**
  184. * @brief PCD MSP Initialization
  185. * This function configures the hardware resources used in this example
  186. * @param hpcd: PCD handle pointer
  187. * @retval None
  188. */
  189. void HAL_PCD_MspInit(PCD_HandleTypeDef* hpcd)
  190. {
  191. GPIO_InitTypeDef GPIO_InitStruct = {0};
  192. RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
  193. if(hpcd->Instance==USB_OTG_FS)
  194. {
  195. /* USER CODE BEGIN USB_OTG_FS_MspInit 0 */
  196. /* USER CODE END USB_OTG_FS_MspInit 0 */
  197. /** Initializes the peripherals clock
  198. */
  199. PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_CLK48;
  200. PeriphClkInit.Clk48ClockSelection = RCC_CLK48CLKSOURCE_HSI48;
  201. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  202. {
  203. Error_Handler();
  204. }
  205. __HAL_RCC_GPIOA_CLK_ENABLE();
  206. /**USB_OTG_FS GPIO Configuration
  207. PA11 ------> USB_OTG_FS_DM
  208. PA12 ------> USB_OTG_FS_DP
  209. */
  210. GPIO_InitStruct.Pin = USB_OTG_FS_DM_Pin|USB_OTG_FS_DP_Pin;
  211. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  212. GPIO_InitStruct.Pull = GPIO_NOPULL;
  213. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  214. GPIO_InitStruct.Alternate = GPIO_AF10_USB;
  215. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  216. /* Peripheral clock enable */
  217. __HAL_RCC_USB_CLK_ENABLE();
  218. /* Enable VDDUSB */
  219. if(__HAL_RCC_PWR_IS_CLK_DISABLED())
  220. {
  221. __HAL_RCC_PWR_CLK_ENABLE();
  222. HAL_PWREx_EnableVddUSB();
  223. __HAL_RCC_PWR_CLK_DISABLE();
  224. }
  225. else
  226. {
  227. HAL_PWREx_EnableVddUSB();
  228. }
  229. /* USB_OTG_FS interrupt Init */
  230. HAL_NVIC_SetPriority(OTG_FS_IRQn, 0, 0);
  231. HAL_NVIC_EnableIRQ(OTG_FS_IRQn);
  232. /* USER CODE BEGIN USB_OTG_FS_MspInit 1 */
  233. /* USER CODE END USB_OTG_FS_MspInit 1 */
  234. }
  235. }
  236. /**
  237. * @brief PCD MSP De-Initialization
  238. * This function freeze the hardware resources used in this example
  239. * @param hpcd: PCD handle pointer
  240. * @retval None
  241. */
  242. void HAL_PCD_MspDeInit(PCD_HandleTypeDef* hpcd)
  243. {
  244. if(hpcd->Instance==USB_OTG_FS)
  245. {
  246. /* USER CODE BEGIN USB_OTG_FS_MspDeInit 0 */
  247. /* USER CODE END USB_OTG_FS_MspDeInit 0 */
  248. /* Peripheral clock disable */
  249. __HAL_RCC_USB_CLK_DISABLE();
  250. /**USB_OTG_FS GPIO Configuration
  251. PA11 ------> USB_OTG_FS_DM
  252. PA12 ------> USB_OTG_FS_DP
  253. */
  254. HAL_GPIO_DeInit(GPIOA, USB_OTG_FS_DM_Pin|USB_OTG_FS_DP_Pin);
  255. /* USB_OTG_FS interrupt DeInit */
  256. HAL_NVIC_DisableIRQ(OTG_FS_IRQn);
  257. /* USER CODE BEGIN USB_OTG_FS_MspDeInit 1 */
  258. /* USER CODE END USB_OTG_FS_MspDeInit 1 */
  259. }
  260. }
  261. /* USER CODE BEGIN 1 */
  262. void Error_Handler()
  263. {
  264. while(1);
  265. }
  266. /* USER CODE END 1 */
  267. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/