stm32f4xx_hal_msp.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /**
  2. ******************************************************************************
  3. * File Name : stm32f4xx_hal_msp.c
  4. * Description : This file provides code for the MSP Initialization
  5. * and de-Initialization codes.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. #include "main.h"
  20. void HAL_MspInit(void)
  21. {
  22. __HAL_RCC_SYSCFG_CLK_ENABLE();
  23. __HAL_RCC_PWR_CLK_ENABLE();
  24. }
  25. /**
  26. * @brief UART MSP Initialization
  27. * This function configures the hardware resources used in this example
  28. * @param huart: UART handle pointer
  29. * @retval None
  30. */
  31. void HAL_UART_MspInit(UART_HandleTypeDef* huart)
  32. {
  33. GPIO_InitTypeDef GPIO_InitStruct = {0};
  34. if(huart->Instance==USART1)
  35. {
  36. /* Peripheral clock enable */
  37. __HAL_RCC_USART1_CLK_ENABLE();
  38. __HAL_RCC_GPIOB_CLK_ENABLE();
  39. /**USART1 GPIO Configuration
  40. PB6 ------> USART1_TX
  41. PB7 ------> USART1_RX
  42. */
  43. GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
  44. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  45. GPIO_InitStruct.Pull = GPIO_NOPULL;
  46. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  47. GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
  48. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  49. }
  50. else if(huart->Instance==USART2)
  51. {
  52. /* Peripheral clock enable */
  53. __HAL_RCC_USART2_CLK_ENABLE();
  54. __HAL_RCC_GPIOD_CLK_ENABLE();
  55. /**USART2 GPIO Configuration
  56. PD5 ------> USART2_TX
  57. PD6 ------> USART2_RX
  58. */
  59. GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_6;
  60. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  61. GPIO_InitStruct.Pull = GPIO_NOPULL;
  62. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  63. GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
  64. HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  65. }
  66. }
  67. /**
  68. * @brief UART MSP De-Initialization
  69. * This function freeze the hardware resources used in this example
  70. * @param huart: UART handle pointer
  71. * @retval None
  72. */
  73. void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
  74. {
  75. if(huart->Instance==USART1)
  76. {
  77. /* Peripheral clock disable */
  78. __HAL_RCC_USART1_CLK_DISABLE();
  79. /**USART1 GPIO Configuration
  80. PB6 ------> USART1_TX
  81. PB7 ------> USART1_RX
  82. */
  83. HAL_GPIO_DeInit(GPIOB, GPIO_PIN_6|GPIO_PIN_7);
  84. }
  85. else if(huart->Instance==USART2)
  86. {
  87. /* Peripheral clock disable */
  88. __HAL_RCC_USART2_CLK_DISABLE();
  89. /**USART2 GPIO Configuration
  90. PD5 ------> USART2_TX
  91. PD6 ------> USART2_RX
  92. */
  93. HAL_GPIO_DeInit(GPIOD, GPIO_PIN_5|GPIO_PIN_6);
  94. }
  95. }
  96. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/