/ST/STM32F429/cmsis_lib/UART/example/UART_Hyperterminal_IT/Src/stm32f4xx_hal_msp.c

https://github.com/clarenceliu/Mplib · C · 139 lines · 27 code · 19 blank · 93 comment · 0 complexity · a5b1a685d3e23f7603bf6529ea1142fa MD5 · raw file

  1. /**
  2. ******************************************************************************
  3. * @file UART/UART_Hyperterminal_IT/Src/stm32f4xx_hal_msp.c
  4. * @author MCD Application Team
  5. * @version V1.0.1
  6. * @date 26-February-2014
  7. * @brief HAL MSP module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
  12. *
  13. * Redistribution and use in source and binary forms, with or without modification,
  14. * are permitted provided that the following conditions are met:
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  21. * may be used to endorse or promote products derived from this software
  22. * without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  28. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  31. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  32. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. ******************************************************************************
  36. */
  37. /* Includes ------------------------------------------------------------------*/
  38. #include "main.h"
  39. /** @addtogroup STM32F4xx_HAL_Examples
  40. * @{
  41. */
  42. /** @defgroup HAL_MSP
  43. * @brief HAL MSP module.
  44. * @{
  45. */
  46. /* Private typedef -----------------------------------------------------------*/
  47. /* Private define ------------------------------------------------------------*/
  48. /* Private macro -------------------------------------------------------------*/
  49. /* Private variables ---------------------------------------------------------*/
  50. /* Private function prototypes -----------------------------------------------*/
  51. /* Private functions ---------------------------------------------------------*/
  52. /** @defgroup HAL_MSP_Private_Functions
  53. * @{
  54. */
  55. /**
  56. * @brief UART MSP Initialization
  57. * This function configures the hardware resources used in this example:
  58. * - Peripheral's clock enable
  59. * - Peripheral's GPIO Configuration
  60. * - NVIC configuration for UART interrupt request enable
  61. * @param huart: UART handle pointer
  62. * @retval None
  63. */
  64. void HAL_UART_MspInit(UART_HandleTypeDef *huart)
  65. {
  66. GPIO_InitTypeDef GPIO_InitStruct;
  67. /*##-1- Enable peripherals and GPIO Clocks #################################*/
  68. /* Enable GPIO TX/RX clock */
  69. USARTx_TX_GPIO_CLK_ENABLE();
  70. USARTx_RX_GPIO_CLK_ENABLE();
  71. /* Enable USART1 clock */
  72. USARTx_CLK_ENABLE();
  73. /*##-2- Configure peripheral GPIO ##########################################*/
  74. /* UART TX GPIO pin configuration */
  75. GPIO_InitStruct.Pin = USARTx_TX_PIN;
  76. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  77. GPIO_InitStruct.Pull = GPIO_PULLUP;
  78. GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
  79. GPIO_InitStruct.Alternate = USARTx_TX_AF;
  80. HAL_GPIO_Init(USARTx_TX_GPIO_PORT, &GPIO_InitStruct);
  81. /* UART RX GPIO pin configuration */
  82. GPIO_InitStruct.Pin = USARTx_RX_PIN;
  83. GPIO_InitStruct.Alternate = USARTx_RX_AF;
  84. HAL_GPIO_Init(USARTx_RX_GPIO_PORT, &GPIO_InitStruct);
  85. /*##-3- Configure the NVIC for UART ########################################*/
  86. /* NVIC for USART1 */
  87. HAL_NVIC_SetPriority(USARTx_IRQn, 0, 1);
  88. HAL_NVIC_EnableIRQ(USARTx_IRQn);
  89. }
  90. /**
  91. * @brief UART MSP De-Initialization
  92. * This function frees the hardware resources used in this example:
  93. * - Disable the Peripheral's clock
  94. * - Revert GPIO and NVIC configuration to their default state
  95. * @param huart: UART handle pointer
  96. * @retval None
  97. */
  98. void HAL_UART_MspDeInit(UART_HandleTypeDef *huart)
  99. {
  100. /*##-1- Reset peripherals ##################################################*/
  101. USARTx_FORCE_RESET();
  102. USARTx_RELEASE_RESET();
  103. /*##-2- Disable peripherals and GPIO Clocks #################################*/
  104. /* Configure UART Tx as alternate function */
  105. HAL_GPIO_DeInit(USARTx_TX_GPIO_PORT, USARTx_TX_PIN);
  106. /* Configure UART Rx as alternate function */
  107. HAL_GPIO_DeInit(USARTx_RX_GPIO_PORT, USARTx_RX_PIN);
  108. /*##-3- Disable the NVIC for UART ##########################################*/
  109. HAL_NVIC_DisableIRQ(USARTx_IRQn);
  110. }
  111. /**
  112. * @}
  113. */
  114. /**
  115. * @}
  116. */
  117. /**
  118. * @}
  119. */
  120. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/