stm32f4xx_hal_msp.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * File Name : stm32f4xx_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 International N.V.
  15. * All rights reserved.
  16. *
  17. * Redistribution and use in source and binary forms, with or without
  18. * modification, are permitted, provided that the following conditions are met:
  19. *
  20. * 1. Redistribution of source code must retain the above copyright notice,
  21. * this list of conditions and the following disclaimer.
  22. * 2. Redistributions in binary form must reproduce the above copyright notice,
  23. * this list of conditions and the following disclaimer in the documentation
  24. * and/or other materials provided with the distribution.
  25. * 3. Neither the name of STMicroelectronics nor the names of other
  26. * contributors to this software may be used to endorse or promote products
  27. * derived from this software without specific written permission.
  28. * 4. This software, including modifications and/or derivative works of this
  29. * software, must execute solely and exclusively on microcontroller or
  30. * microprocessor devices manufactured by or for STMicroelectronics.
  31. * 5. Redistribution and use of this software other than as permitted under
  32. * this license is void and will automatically terminate your rights under
  33. * this license.
  34. *
  35. * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
  36. * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
  37. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  38. * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
  39. * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
  40. * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  41. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  43. * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  44. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  45. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  46. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  47. *
  48. ******************************************************************************
  49. */
  50. /* USER CODE END Header */
  51. /* Includes ------------------------------------------------------------------*/
  52. #include "main.h"
  53. /* USER CODE BEGIN Includes */
  54. /* USER CODE END Includes */
  55. /* Private typedef -----------------------------------------------------------*/
  56. /* USER CODE BEGIN TD */
  57. /* USER CODE END TD */
  58. /* Private define ------------------------------------------------------------*/
  59. /* USER CODE BEGIN Define */
  60. /* USER CODE END Define */
  61. /* Private macro -------------------------------------------------------------*/
  62. /* USER CODE BEGIN Macro */
  63. /* USER CODE END Macro */
  64. /* Private variables ---------------------------------------------------------*/
  65. /* USER CODE BEGIN PV */
  66. /* USER CODE END PV */
  67. /* Private function prototypes -----------------------------------------------*/
  68. /* USER CODE BEGIN PFP */
  69. /* USER CODE END PFP */
  70. /* External functions --------------------------------------------------------*/
  71. /* USER CODE BEGIN ExternalFunctions */
  72. /* USER CODE END ExternalFunctions */
  73. /* USER CODE BEGIN 0 */
  74. /* USER CODE END 0 */
  75. /**
  76. * Initializes the Global MSP.
  77. */
  78. void HAL_MspInit(void)
  79. {
  80. /* USER CODE BEGIN MspInit 0 */
  81. /* USER CODE END MspInit 0 */
  82. __HAL_RCC_SYSCFG_CLK_ENABLE();
  83. __HAL_RCC_PWR_CLK_ENABLE();
  84. HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_0);
  85. /* System interrupt init*/
  86. /* USER CODE BEGIN MspInit 1 */
  87. /* USER CODE END MspInit 1 */
  88. }
  89. /**
  90. * @brief SPI MSP Initialization
  91. * This function configures the hardware resources used in this example
  92. * @param hspi: SPI handle pointer
  93. * @retval None
  94. */
  95. void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
  96. {
  97. GPIO_InitTypeDef GPIO_InitStruct = {0};
  98. if(hspi->Instance==SPI1)
  99. {
  100. /* USER CODE BEGIN SPI1_MspInit 0 */
  101. /* USER CODE END SPI1_MspInit 0 */
  102. /* Peripheral clock enable */
  103. __HAL_RCC_SPI1_CLK_ENABLE();
  104. __HAL_RCC_GPIOA_CLK_ENABLE();
  105. /**SPI1 GPIO Configuration
  106. PA5 ------> SPI1_SCK
  107. PA6 ------> SPI1_MISO
  108. PA7 ------> SPI1_MOSI
  109. */
  110. GPIO_InitStruct.Pin = SPI1_SCK_Pin|SPI1_MISO_Pin|SPI1_MOSI_Pin;
  111. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  112. GPIO_InitStruct.Pull = GPIO_NOPULL;
  113. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  114. GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
  115. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  116. /* USER CODE BEGIN SPI1_MspInit 1 */
  117. /* USER CODE END SPI1_MspInit 1 */
  118. }
  119. }
  120. /**
  121. * @brief SPI MSP De-Initialization
  122. * This function freeze the hardware resources used in this example
  123. * @param hspi: SPI handle pointer
  124. * @retval None
  125. */
  126. void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
  127. {
  128. if(hspi->Instance==SPI1)
  129. {
  130. /* USER CODE BEGIN SPI1_MspDeInit 0 */
  131. /* USER CODE END SPI1_MspDeInit 0 */
  132. /* Peripheral clock disable */
  133. __HAL_RCC_SPI1_CLK_DISABLE();
  134. /**SPI1 GPIO Configuration
  135. PA5 ------> SPI1_SCK
  136. PA6 ------> SPI1_MISO
  137. PA7 ------> SPI1_MOSI
  138. */
  139. HAL_GPIO_DeInit(GPIOA, SPI1_SCK_Pin|SPI1_MISO_Pin|SPI1_MOSI_Pin);
  140. /* USER CODE BEGIN SPI1_MspDeInit 1 */
  141. /* USER CODE END SPI1_MspDeInit 1 */
  142. }
  143. }
  144. /**
  145. * @brief UART MSP Initialization
  146. * This function configures the hardware resources used in this example
  147. * @param huart: UART handle pointer
  148. * @retval None
  149. */
  150. void HAL_UART_MspInit(UART_HandleTypeDef* huart)
  151. {
  152. GPIO_InitTypeDef GPIO_InitStruct = {0};
  153. if(huart->Instance==USART1)
  154. {
  155. /* USER CODE BEGIN USART1_MspInit 0 */
  156. /* USER CODE END USART1_MspInit 0 */
  157. /* Peripheral clock enable */
  158. __HAL_RCC_USART1_CLK_ENABLE();
  159. __HAL_RCC_GPIOB_CLK_ENABLE();
  160. /**USART1 GPIO Configuration
  161. PB6 ------> USART1_TX
  162. PB7 ------> USART1_RX
  163. */
  164. GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
  165. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  166. GPIO_InitStruct.Pull = GPIO_PULLUP;
  167. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  168. GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
  169. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  170. /* USER CODE BEGIN USART1_MspInit 1 */
  171. /* USER CODE END USART1_MspInit 1 */
  172. }
  173. }
  174. /**
  175. * @brief UART MSP De-Initialization
  176. * This function freeze the hardware resources used in this example
  177. * @param huart: UART handle pointer
  178. * @retval None
  179. */
  180. void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
  181. {
  182. if(huart->Instance==USART1)
  183. {
  184. /* USER CODE BEGIN USART1_MspDeInit 0 */
  185. /* USER CODE END USART1_MspDeInit 0 */
  186. /* Peripheral clock disable */
  187. __HAL_RCC_USART1_CLK_DISABLE();
  188. /**USART1 GPIO Configuration
  189. PB6 ------> USART1_TX
  190. PB7 ------> USART1_RX
  191. */
  192. HAL_GPIO_DeInit(GPIOB, GPIO_PIN_6|GPIO_PIN_7);
  193. /* USER CODE BEGIN USART1_MspDeInit 1 */
  194. /* USER CODE END USART1_MspDeInit 1 */
  195. }
  196. }
  197. /* USER CODE BEGIN 1 */
  198. /* USER CODE END 1 */
  199. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/