stm32f7xx_hal_msp.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * File Name : stm32f7xx_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. /**
  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_PWR_CLK_ENABLE();
  74. __HAL_RCC_SYSCFG_CLK_ENABLE();
  75. /* System interrupt init*/
  76. /* USER CODE BEGIN MspInit 1 */
  77. /* USER CODE END MspInit 1 */
  78. }
  79. /**
  80. * @brief ETH MSP Initialization
  81. * This function configures the hardware resources used in this example
  82. * @param heth: ETH handle pointer
  83. * @retval None
  84. */
  85. void HAL_ETH_MspInit(ETH_HandleTypeDef* heth)
  86. {
  87. GPIO_InitTypeDef GPIO_InitStruct = {0};
  88. if(heth->Instance==ETH)
  89. {
  90. /* USER CODE BEGIN ETH_MspInit 0 */
  91. /* USER CODE END ETH_MspInit 0 */
  92. /* Peripheral clock enable */
  93. __HAL_RCC_ETH_CLK_ENABLE();
  94. __HAL_RCC_GPIOC_CLK_ENABLE();
  95. __HAL_RCC_GPIOA_CLK_ENABLE();
  96. __HAL_RCC_GPIOB_CLK_ENABLE();
  97. __HAL_RCC_GPIOG_CLK_ENABLE();
  98. /**ETH GPIO Configuration
  99. PC1 ------> ETH_MDC
  100. PA1 ------> ETH_REF_CLK
  101. PA2 ------> ETH_MDIO
  102. PA7 ------> ETH_CRS_DV
  103. PC4 ------> ETH_RXD0
  104. PC5 ------> ETH_RXD1
  105. PB13 ------> ETH_TXD1
  106. PG11 ------> ETH_TX_EN
  107. PG13 ------> ETH_TXD0
  108. */
  109. GPIO_InitStruct.Pin = RMII_MDC_Pin|RMII_RXD0_Pin|RMII_RXD1_Pin;
  110. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  111. GPIO_InitStruct.Pull = GPIO_NOPULL;
  112. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  113. GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
  114. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  115. GPIO_InitStruct.Pin = RMII_REF_CLK_Pin|RMII_MDIO_Pin|RMII_CRS_DV_Pin;
  116. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  117. GPIO_InitStruct.Pull = GPIO_NOPULL;
  118. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  119. GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
  120. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  121. GPIO_InitStruct.Pin = RMII_TXD1_Pin;
  122. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  123. GPIO_InitStruct.Pull = GPIO_NOPULL;
  124. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  125. GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
  126. HAL_GPIO_Init(RMII_TXD1_GPIO_Port, &GPIO_InitStruct);
  127. GPIO_InitStruct.Pin = RMII_TX_EN_Pin|RMII_TXD0_Pin;
  128. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  129. GPIO_InitStruct.Pull = GPIO_NOPULL;
  130. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  131. GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
  132. HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
  133. /* USER CODE BEGIN ETH_MspInit 1 */
  134. /* USER CODE END ETH_MspInit 1 */
  135. }
  136. }
  137. /**
  138. * @brief ETH MSP De-Initialization
  139. * This function freeze the hardware resources used in this example
  140. * @param heth: ETH handle pointer
  141. * @retval None
  142. */
  143. void HAL_ETH_MspDeInit(ETH_HandleTypeDef* heth)
  144. {
  145. if(heth->Instance==ETH)
  146. {
  147. /* USER CODE BEGIN ETH_MspDeInit 0 */
  148. /* USER CODE END ETH_MspDeInit 0 */
  149. /* Peripheral clock disable */
  150. __HAL_RCC_ETH_CLK_DISABLE();
  151. /**ETH GPIO Configuration
  152. PC1 ------> ETH_MDC
  153. PA1 ------> ETH_REF_CLK
  154. PA2 ------> ETH_MDIO
  155. PA7 ------> ETH_CRS_DV
  156. PC4 ------> ETH_RXD0
  157. PC5 ------> ETH_RXD1
  158. PB13 ------> ETH_TXD1
  159. PG11 ------> ETH_TX_EN
  160. PG13 ------> ETH_TXD0
  161. */
  162. HAL_GPIO_DeInit(GPIOC, RMII_MDC_Pin|RMII_RXD0_Pin|RMII_RXD1_Pin);
  163. HAL_GPIO_DeInit(GPIOA, RMII_REF_CLK_Pin|RMII_MDIO_Pin|RMII_CRS_DV_Pin);
  164. HAL_GPIO_DeInit(RMII_TXD1_GPIO_Port, RMII_TXD1_Pin);
  165. HAL_GPIO_DeInit(GPIOG, RMII_TX_EN_Pin|RMII_TXD0_Pin);
  166. /* USER CODE BEGIN ETH_MspDeInit 1 */
  167. /* USER CODE END ETH_MspDeInit 1 */
  168. }
  169. }
  170. /**
  171. * @brief UART MSP Initialization
  172. * This function configures the hardware resources used in this example
  173. * @param huart: UART handle pointer
  174. * @retval None
  175. */
  176. void HAL_UART_MspInit(UART_HandleTypeDef* huart)
  177. {
  178. GPIO_InitTypeDef GPIO_InitStruct = {0};
  179. if(huart->Instance==USART3)
  180. {
  181. /* USER CODE BEGIN USART3_MspInit 0 */
  182. /* USER CODE END USART3_MspInit 0 */
  183. /* Peripheral clock enable */
  184. __HAL_RCC_USART3_CLK_ENABLE();
  185. __HAL_RCC_GPIOD_CLK_ENABLE();
  186. /**USART3 GPIO Configuration
  187. PD8 ------> USART3_TX
  188. PD9 ------> USART3_RX
  189. */
  190. GPIO_InitStruct.Pin = STLK_RX_Pin|STLK_TX_Pin;
  191. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  192. GPIO_InitStruct.Pull = GPIO_PULLUP;
  193. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  194. GPIO_InitStruct.Alternate = GPIO_AF7_USART3;
  195. HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  196. /* USER CODE BEGIN USART3_MspInit 1 */
  197. /* USER CODE END USART3_MspInit 1 */
  198. }
  199. }
  200. /**
  201. * @brief UART MSP De-Initialization
  202. * This function freeze the hardware resources used in this example
  203. * @param huart: UART handle pointer
  204. * @retval None
  205. */
  206. void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
  207. {
  208. if(huart->Instance==USART3)
  209. {
  210. /* USER CODE BEGIN USART3_MspDeInit 0 */
  211. /* USER CODE END USART3_MspDeInit 0 */
  212. /* Peripheral clock disable */
  213. __HAL_RCC_USART3_CLK_DISABLE();
  214. /**USART3 GPIO Configuration
  215. PD8 ------> USART3_TX
  216. PD9 ------> USART3_RX
  217. */
  218. HAL_GPIO_DeInit(GPIOD, STLK_RX_Pin|STLK_TX_Pin);
  219. /* USER CODE BEGIN USART3_MspDeInit 1 */
  220. /* USER CODE END USART3_MspDeInit 1 */
  221. }
  222. }
  223. /**
  224. * @brief PCD MSP Initialization
  225. * This function configures the hardware resources used in this example
  226. * @param hpcd: PCD handle pointer
  227. * @retval None
  228. */
  229. void HAL_PCD_MspInit(PCD_HandleTypeDef* hpcd)
  230. {
  231. GPIO_InitTypeDef GPIO_InitStruct = {0};
  232. if(hpcd->Instance==USB_OTG_FS)
  233. {
  234. /* USER CODE BEGIN USB_OTG_FS_MspInit 0 */
  235. /* USER CODE END USB_OTG_FS_MspInit 0 */
  236. __HAL_RCC_GPIOA_CLK_ENABLE();
  237. /**USB_OTG_FS GPIO Configuration
  238. PA8 ------> USB_OTG_FS_SOF
  239. PA9 ------> USB_OTG_FS_VBUS
  240. PA10 ------> USB_OTG_FS_ID
  241. PA11 ------> USB_OTG_FS_DM
  242. PA12 ------> USB_OTG_FS_DP
  243. */
  244. GPIO_InitStruct.Pin = USB_SOF_Pin|USB_ID_Pin|USB_DM_Pin|USB_DP_Pin;
  245. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  246. GPIO_InitStruct.Pull = GPIO_NOPULL;
  247. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  248. GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
  249. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  250. GPIO_InitStruct.Pin = USB_VBUS_Pin;
  251. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  252. GPIO_InitStruct.Pull = GPIO_NOPULL;
  253. HAL_GPIO_Init(USB_VBUS_GPIO_Port, &GPIO_InitStruct);
  254. /* Peripheral clock enable */
  255. __HAL_RCC_USB_OTG_FS_CLK_ENABLE();
  256. /* USER CODE BEGIN USB_OTG_FS_MspInit 1 */
  257. /* USER CODE END USB_OTG_FS_MspInit 1 */
  258. }
  259. }
  260. /**
  261. * @brief PCD MSP De-Initialization
  262. * This function freeze the hardware resources used in this example
  263. * @param hpcd: PCD handle pointer
  264. * @retval None
  265. */
  266. void HAL_PCD_MspDeInit(PCD_HandleTypeDef* hpcd)
  267. {
  268. if(hpcd->Instance==USB_OTG_FS)
  269. {
  270. /* USER CODE BEGIN USB_OTG_FS_MspDeInit 0 */
  271. /* USER CODE END USB_OTG_FS_MspDeInit 0 */
  272. /* Peripheral clock disable */
  273. __HAL_RCC_USB_OTG_FS_CLK_DISABLE();
  274. /**USB_OTG_FS GPIO Configuration
  275. PA8 ------> USB_OTG_FS_SOF
  276. PA9 ------> USB_OTG_FS_VBUS
  277. PA10 ------> USB_OTG_FS_ID
  278. PA11 ------> USB_OTG_FS_DM
  279. PA12 ------> USB_OTG_FS_DP
  280. */
  281. HAL_GPIO_DeInit(GPIOA, USB_SOF_Pin|USB_VBUS_Pin|USB_ID_Pin|USB_DM_Pin
  282. |USB_DP_Pin);
  283. /* USER CODE BEGIN USB_OTG_FS_MspDeInit 1 */
  284. /* USER CODE END USB_OTG_FS_MspDeInit 1 */
  285. }
  286. }
  287. /* USER CODE BEGIN 1 */
  288. /* USER CODE END 1 */
  289. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/