source: ecs_cellMon/firmware/Core/Src/usart.c

Last change on this file was 3, checked in by f.jahn, 20 months ago

fw hinzugfügt-->zed

File size: 4.1 KB
Line 
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 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
20/* Includes ------------------------------------------------------------------*/
21#include "usart.h"
22
23/* USER CODE BEGIN 0 */
24
25/* USER CODE END 0 */
26
27UART_HandleTypeDef huart1;
28
29/* USART1 init function */
30
31void MX_USART1_UART_Init(void)
32{
33
34  /* USER CODE BEGIN USART1_Init 0 */
35
36  /* USER CODE END USART1_Init 0 */
37
38  /* USER CODE BEGIN USART1_Init 1 */
39
40  /* USER CODE END USART1_Init 1 */
41  huart1.Instance = USART1;
42  huart1.Init.BaudRate = 19200;
43  huart1.Init.WordLength = UART_WORDLENGTH_9B;
44  huart1.Init.StopBits = UART_STOPBITS_1;
45  huart1.Init.Parity = UART_PARITY_EVEN;
46  huart1.Init.Mode = UART_MODE_TX_RX;
47  huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
48  huart1.Init.OverSampling = UART_OVERSAMPLING_16;
49  huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
50  huart1.Init.ClockPrescaler = UART_PRESCALER_DIV1;
51  huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
52  if (HAL_RS485Ex_Init(&huart1, UART_DE_POLARITY_HIGH, 0, 0) != HAL_OK)
53  {
54    Error_Handler();
55  }
56  if (HAL_UARTEx_SetTxFifoThreshold(&huart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
57  {
58    Error_Handler();
59  }
60  if (HAL_UARTEx_SetRxFifoThreshold(&huart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
61  {
62    Error_Handler();
63  }
64  if (HAL_UARTEx_DisableFifoMode(&huart1) != HAL_OK)
65  {
66    Error_Handler();
67  }
68  /* USER CODE BEGIN USART1_Init 2 */
69
70  /* USER CODE END USART1_Init 2 */
71
72}
73
74void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)
75{
76
77  GPIO_InitTypeDef GPIO_InitStruct = {0};
78  if(uartHandle->Instance==USART1)
79  {
80  /* USER CODE BEGIN USART1_MspInit 0 */
81
82  /* USER CODE END USART1_MspInit 0 */
83    /* USART1 clock enable */
84    __HAL_RCC_USART1_CLK_ENABLE();
85
86    __HAL_RCC_GPIOA_CLK_ENABLE();
87    /**USART1 GPIO Configuration
88    PA9     ------> USART1_TX
89    PA10     ------> USART1_RX
90    PA12 [PA10]     ------> USART1_DE
91    */
92    GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_12;
93    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
94    GPIO_InitStruct.Pull = GPIO_NOPULL;
95    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
96    GPIO_InitStruct.Alternate = GPIO_AF1_USART1;
97    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
98
99    GPIO_InitStruct.Pin = GPIO_PIN_10;
100    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
101    GPIO_InitStruct.Pull = GPIO_PULLUP;
102    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
103    GPIO_InitStruct.Alternate = GPIO_AF1_USART1;
104    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
105
106    /* USART1 interrupt Init */
107    HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);
108    HAL_NVIC_EnableIRQ(USART1_IRQn);
109  /* USER CODE BEGIN USART1_MspInit 1 */
110
111  /* USER CODE END USART1_MspInit 1 */
112  }
113}
114
115void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle)
116{
117
118  if(uartHandle->Instance==USART1)
119  {
120  /* USER CODE BEGIN USART1_MspDeInit 0 */
121
122  /* USER CODE END USART1_MspDeInit 0 */
123    /* Peripheral clock disable */
124    __HAL_RCC_USART1_CLK_DISABLE();
125
126    /**USART1 GPIO Configuration
127    PA9     ------> USART1_TX
128    PA10     ------> USART1_RX
129    PA12 [PA10]     ------> USART1_DE
130    */
131    HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_12);
132
133    /* USART1 interrupt Deinit */
134    HAL_NVIC_DisableIRQ(USART1_IRQn);
135  /* USER CODE BEGIN USART1_MspDeInit 1 */
136
137  /* USER CODE END USART1_MspDeInit 1 */
138  }
139}
140
141/* USER CODE BEGIN 1 */
142
143/* USER CODE END 1 */
144
145/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Note: See TracBrowser for help on using the repository browser.