usart.c 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. /* USER CODE BEGIN USART1_Init 0 */
  26. /* USER CODE END USART1_Init 0 */
  27. LL_USART_InitTypeDef USART_InitStruct = {0};
  28. LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
  29. /* Peripheral clock enable */
  30. LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART1);
  31. LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB);
  32. /**USART1 GPIO Configuration
  33. PB6 ------> USART1_TX
  34. PB7 ------> USART1_RX
  35. */
  36. GPIO_InitStruct.Pin = LL_GPIO_PIN_6 | LL_GPIO_PIN_7;
  37. GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
  38. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
  39. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  40. GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
  41. GPIO_InitStruct.Alternate = LL_GPIO_AF_7;
  42. LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  43. /* USER CODE BEGIN USART1_Init 1 */
  44. /* USER CODE END USART1_Init 1 */
  45. USART_InitStruct.PrescalerValue = LL_USART_PRESCALER_DIV1;
  46. USART_InitStruct.BaudRate = 115200;
  47. USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B;
  48. USART_InitStruct.StopBits = LL_USART_STOPBITS_1;
  49. USART_InitStruct.Parity = LL_USART_PARITY_NONE;
  50. USART_InitStruct.TransferDirection = LL_USART_DIRECTION_TX;
  51. USART_InitStruct.HardwareFlowControl = LL_USART_HWCONTROL_NONE;
  52. USART_InitStruct.OverSampling = LL_USART_OVERSAMPLING_16;
  53. LL_USART_Init(USART1, &USART_InitStruct);
  54. LL_USART_SetTXFIFOThreshold(USART1, LL_USART_FIFOTHRESHOLD_1_8);
  55. LL_USART_SetRXFIFOThreshold(USART1, LL_USART_FIFOTHRESHOLD_1_8);
  56. LL_USART_DisableFIFO(USART1);
  57. LL_USART_EnableAutoBaudRate(USART1);
  58. LL_USART_SetAutoBaudRateMode(USART1, LL_USART_AUTOBAUD_DETECT_ON_STARTBIT);
  59. LL_USART_ConfigAsyncMode(USART1);
  60. /* USER CODE BEGIN WKUPType USART1 */
  61. /* USER CODE END WKUPType USART1 */
  62. LL_USART_Enable(USART1);
  63. /* Polling USART1 initialisation */
  64. while(!(LL_USART_IsActiveFlag_TEACK(USART1))) {
  65. }
  66. /* USER CODE BEGIN USART1_Init 2 */
  67. /* USER CODE END USART1_Init 2 */
  68. }
  69. /* USER CODE BEGIN 1 */
  70. /* USER CODE END 1 */
  71. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/