usart.c 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. ******************************************************************************
  3. * @file usart.c
  4. * @brief This file provides code for the configuration
  5. * of the USART instances.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under Ultimate Liberty license
  13. * SLA0044, the "License"; You may not use this file except in compliance with
  14. * the License. You may obtain a copy of the License at:
  15. * www.st.com/SLA0044
  16. *
  17. ******************************************************************************
  18. */
  19. /* Includes ------------------------------------------------------------------*/
  20. #include "usart.h"
  21. /* USER CODE BEGIN 0 */
  22. /* USER CODE END 0 */
  23. /* USART1 init function */
  24. void MX_USART1_UART_Init(void)
  25. {
  26. /* USER CODE BEGIN USART1_Init 0 */
  27. /* USER CODE END USART1_Init 0 */
  28. LL_USART_InitTypeDef USART_InitStruct = {0};
  29. LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
  30. /* Peripheral clock enable */
  31. LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART1);
  32. LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB);
  33. /**USART1 GPIO Configuration
  34. PB6 ------> USART1_TX
  35. PB7 ------> USART1_RX
  36. */
  37. GPIO_InitStruct.Pin = LL_GPIO_PIN_6|LL_GPIO_PIN_7;
  38. GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
  39. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
  40. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  41. GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
  42. GPIO_InitStruct.Alternate = LL_GPIO_AF_7;
  43. LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  44. /* USER CODE BEGIN USART1_Init 1 */
  45. /* USER CODE END USART1_Init 1 */
  46. USART_InitStruct.PrescalerValue = LL_USART_PRESCALER_DIV1;
  47. USART_InitStruct.BaudRate = 115200;
  48. USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B;
  49. USART_InitStruct.StopBits = LL_USART_STOPBITS_1;
  50. USART_InitStruct.Parity = LL_USART_PARITY_NONE;
  51. USART_InitStruct.TransferDirection = LL_USART_DIRECTION_TX;
  52. USART_InitStruct.HardwareFlowControl = LL_USART_HWCONTROL_NONE;
  53. USART_InitStruct.OverSampling = LL_USART_OVERSAMPLING_16;
  54. LL_USART_Init(USART1, &USART_InitStruct);
  55. LL_USART_SetTXFIFOThreshold(USART1, LL_USART_FIFOTHRESHOLD_1_8);
  56. LL_USART_SetRXFIFOThreshold(USART1, LL_USART_FIFOTHRESHOLD_1_8);
  57. LL_USART_DisableFIFO(USART1);
  58. LL_USART_EnableAutoBaudRate(USART1);
  59. LL_USART_SetAutoBaudRateMode(USART1, LL_USART_AUTOBAUD_DETECT_ON_STARTBIT);
  60. LL_USART_ConfigAsyncMode(USART1);
  61. /* USER CODE BEGIN WKUPType USART1 */
  62. /* USER CODE END WKUPType USART1 */
  63. LL_USART_Enable(USART1);
  64. /* Polling USART1 initialisation */
  65. while(!(LL_USART_IsActiveFlag_TEACK(USART1)))
  66. {
  67. }
  68. /* USER CODE BEGIN USART1_Init 2 */
  69. /* USER CODE END USART1_Init 2 */
  70. }
  71. /* USER CODE BEGIN 1 */
  72. /* USER CODE END 1 */
  73. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/