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. #include <drv_common.h>
  55. /* USER CODE END Includes */
  56. /* Private typedef -----------------------------------------------------------*/
  57. /* USER CODE BEGIN TD */
  58. /* USER CODE END TD */
  59. /* Private define ------------------------------------------------------------*/
  60. /* USER CODE BEGIN Define */
  61. /* USER CODE END Define */
  62. /* Private macro -------------------------------------------------------------*/
  63. /* USER CODE BEGIN Macro */
  64. /* USER CODE END Macro */
  65. /* Private variables ---------------------------------------------------------*/
  66. /* USER CODE BEGIN PV */
  67. /* USER CODE END PV */
  68. /* Private function prototypes -----------------------------------------------*/
  69. /* USER CODE BEGIN PFP */
  70. /* USER CODE END PFP */
  71. /* External functions --------------------------------------------------------*/
  72. /* USER CODE BEGIN ExternalFunctions */
  73. /* USER CODE END ExternalFunctions */
  74. /* USER CODE BEGIN 0 */
  75. /* USER CODE END 0 */
  76. /**
  77. * Initializes the Global MSP.
  78. */
  79. void HAL_MspInit(void)
  80. {
  81. /* USER CODE BEGIN MspInit 0 */
  82. /* USER CODE END MspInit 0 */
  83. __HAL_RCC_SYSCFG_CLK_ENABLE();
  84. __HAL_RCC_PWR_CLK_ENABLE();
  85. HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_0);
  86. /* System interrupt init*/
  87. /* USER CODE BEGIN MspInit 1 */
  88. /* USER CODE END MspInit 1 */
  89. }
  90. /**
  91. * @brief SPI MSP Initialization
  92. * This function configures the hardware resources used in this example
  93. * @param hspi: SPI handle pointer
  94. * @retval None
  95. */
  96. void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
  97. {
  98. GPIO_InitTypeDef GPIO_InitStruct = {0};
  99. if(hspi->Instance==SPI1)
  100. {
  101. /* USER CODE BEGIN SPI1_MspInit 0 */
  102. /* USER CODE END SPI1_MspInit 0 */
  103. /* Peripheral clock enable */
  104. __HAL_RCC_SPI1_CLK_ENABLE();
  105. __HAL_RCC_GPIOA_CLK_ENABLE();
  106. /**SPI1 GPIO Configuration
  107. PA5 ------> SPI1_SCK
  108. PA6 ------> SPI1_MISO
  109. PA7 ------> SPI1_MOSI
  110. */
  111. GPIO_InitStruct.Pin = SPI1_SCK_Pin|SPI1_MISO_Pin|SPI1_MOSI_Pin;
  112. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  113. GPIO_InitStruct.Pull = GPIO_NOPULL;
  114. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  115. GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
  116. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  117. /* USER CODE BEGIN SPI1_MspInit 1 */
  118. /* USER CODE END SPI1_MspInit 1 */
  119. }
  120. }
  121. /**
  122. * @brief SPI MSP De-Initialization
  123. * This function freeze the hardware resources used in this example
  124. * @param hspi: SPI handle pointer
  125. * @retval None
  126. */
  127. void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
  128. {
  129. if(hspi->Instance==SPI1)
  130. {
  131. /* USER CODE BEGIN SPI1_MspDeInit 0 */
  132. /* USER CODE END SPI1_MspDeInit 0 */
  133. /* Peripheral clock disable */
  134. __HAL_RCC_SPI1_CLK_DISABLE();
  135. /**SPI1 GPIO Configuration
  136. PA5 ------> SPI1_SCK
  137. PA6 ------> SPI1_MISO
  138. PA7 ------> SPI1_MOSI
  139. */
  140. HAL_GPIO_DeInit(GPIOA, SPI1_SCK_Pin|SPI1_MISO_Pin|SPI1_MOSI_Pin);
  141. /* USER CODE BEGIN SPI1_MspDeInit 1 */
  142. /* USER CODE END SPI1_MspDeInit 1 */
  143. }
  144. }
  145. /**
  146. * @brief UART MSP Initialization
  147. * This function configures the hardware resources used in this example
  148. * @param huart: UART handle pointer
  149. * @retval None
  150. */
  151. void HAL_UART_MspInit(UART_HandleTypeDef* huart)
  152. {
  153. GPIO_InitTypeDef GPIO_InitStruct = {0};
  154. if(huart->Instance==USART1)
  155. {
  156. /* USER CODE BEGIN USART1_MspInit 0 */
  157. /* USER CODE END USART1_MspInit 0 */
  158. /* Peripheral clock enable */
  159. __HAL_RCC_USART1_CLK_ENABLE();
  160. __HAL_RCC_GPIOB_CLK_ENABLE();
  161. /**USART1 GPIO Configuration
  162. PB6 ------> USART1_TX
  163. PB7 ------> USART1_RX
  164. */
  165. GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
  166. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  167. GPIO_InitStruct.Pull = GPIO_PULLUP;
  168. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  169. GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
  170. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  171. /* USER CODE BEGIN USART1_MspInit 1 */
  172. /* USER CODE END USART1_MspInit 1 */
  173. }
  174. }
  175. /**
  176. * @brief UART MSP De-Initialization
  177. * This function freeze the hardware resources used in this example
  178. * @param huart: UART handle pointer
  179. * @retval None
  180. */
  181. void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
  182. {
  183. if(huart->Instance==USART1)
  184. {
  185. /* USER CODE BEGIN USART1_MspDeInit 0 */
  186. /* USER CODE END USART1_MspDeInit 0 */
  187. /* Peripheral clock disable */
  188. __HAL_RCC_USART1_CLK_DISABLE();
  189. /**USART1 GPIO Configuration
  190. PB6 ------> USART1_TX
  191. PB7 ------> USART1_RX
  192. */
  193. HAL_GPIO_DeInit(GPIOB, GPIO_PIN_6|GPIO_PIN_7);
  194. /* USER CODE BEGIN USART1_MspDeInit 1 */
  195. /* USER CODE END USART1_MspDeInit 1 */
  196. }
  197. }
  198. /* USER CODE BEGIN 1 */
  199. /* USER CODE END 1 */
  200. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/