|
|
|
/* USER CODE BEGIN Header */
|
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
* @file usart.c
|
|
|
|
* @brief This file provides code for the configuration
|
|
|
|
* of the USART instances.
|
|
|
|
******************************************************************************
|
|
|
|
* @attention
|
|
|
|
*
|
|
|
|
* Copyright (c) 2022 STMicroelectronics.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This software is licensed under terms that can be found in the LICENSE file
|
|
|
|
* in the root directory of this software component.
|
|
|
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
|
|
|
*
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
|
|
|
/* USER CODE END Header */
|
|
|
|
/* Includes ------------------------------------------------------------------*/
|
|
|
|
#include "usart.h"
|
|
|
|
|
|
|
|
/* USER CODE BEGIN 0 */
|
|
|
|
|
|
|
|
/* USER CODE END 0 */
|
|
|
|
|
|
|
|
UART_HandleTypeDef huart3;
|
|
|
|
UART_HandleTypeDef huart6;
|
|
|
|
|
|
|
|
/* USART3 init function */
|
|
|
|
|
|
|
|
void MX_USART3_UART_Init(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* USER CODE BEGIN USART3_Init 0 */
|
|
|
|
|
|
|
|
/* USER CODE END USART3_Init 0 */
|
|
|
|
|
|
|
|
/* USER CODE BEGIN USART3_Init 1 */
|
|
|
|
|
|
|
|
/* USER CODE END USART3_Init 1 */
|
|
|
|
huart3.Instance = USART3;
|
|
|
|
huart3.Init.BaudRate = 115200;
|
|
|
|
huart3.Init.WordLength = UART_WORDLENGTH_8B;
|
|
|
|
huart3.Init.StopBits = UART_STOPBITS_1;
|
|
|
|
huart3.Init.Parity = UART_PARITY_NONE;
|
|
|
|
huart3.Init.Mode = UART_MODE_TX_RX;
|
|
|
|
huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
|
|
|
huart3.Init.OverSampling = UART_OVERSAMPLING_16;
|
|
|
|
huart3.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
|
|
|
|
huart3.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
|
|
|
|
if (HAL_UART_Init(&huart3) != HAL_OK)
|
|
|
|
{
|
|
|
|
Error_Handler();
|
|
|
|
}
|
|
|
|
/* USER CODE BEGIN USART3_Init 2 */
|
|
|
|
|
|
|
|
/* USER CODE END USART3_Init 2 */
|
|
|
|
|
|
|
|
}
|
|
|
|
/* USART6 init function */
|
|
|
|
|
|
|
|
void MX_USART6_UART_Init(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* USER CODE BEGIN USART6_Init 0 */
|
|
|
|
|
|
|
|
/* USER CODE END USART6_Init 0 */
|
|
|
|
|
|
|
|
/* USER CODE BEGIN USART6_Init 1 */
|
|
|
|
|
|
|
|
/* USER CODE END USART6_Init 1 */
|
|
|
|
huart6.Instance = USART6;
|
|
|
|
huart6.Init.BaudRate = 115200;
|
|
|
|
huart6.Init.WordLength = UART_WORDLENGTH_8B;
|
|
|
|
huart6.Init.StopBits = UART_STOPBITS_1;
|
|
|
|
huart6.Init.Parity = UART_PARITY_NONE;
|
|
|
|
huart6.Init.Mode = UART_MODE_TX_RX;
|
|
|
|
huart6.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
|
|
|
huart6.Init.OverSampling = UART_OVERSAMPLING_16;
|
|
|
|
huart6.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
|
|
|
|
huart6.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
|
|
|
|
if (HAL_UART_Init(&huart6) != HAL_OK)
|
|
|
|
{
|
|
|
|
Error_Handler();
|
|
|
|
}
|
|
|
|
/* USER CODE BEGIN USART6_Init 2 */
|
|
|
|
|
|
|
|
/* USER CODE END USART6_Init 2 */
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)
|
|
|
|
{
|
|
|
|
|
|
|
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
|
|
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
|
|
|
|
if(uartHandle->Instance==USART3)
|
|
|
|
{
|
|
|
|
/* USER CODE BEGIN USART3_MspInit 0 */
|
|
|
|
|
|
|
|
/* USER CODE END USART3_MspInit 0 */
|
|
|
|
|
|
|
|
/** Initializes the peripherals clock
|
|
|
|
*/
|
|
|
|
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USART3;
|
|
|
|
PeriphClkInitStruct.Usart3ClockSelection = RCC_USART3CLKSOURCE_PCLK1;
|
|
|
|
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
|
|
|
|
{
|
|
|
|
Error_Handler();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* USART3 clock enable */
|
|
|
|
__HAL_RCC_USART3_CLK_ENABLE();
|
|
|
|
|
|
|
|
__HAL_RCC_GPIOB_CLK_ENABLE();
|
|
|
|
/**USART3 GPIO Configuration
|
|
|
|
PB10 ------> USART3_TX
|
|
|
|
PB11 ------> USART3_RX
|
|
|
|
*/
|
|
|
|
GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11;
|
|
|
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
|
|
|
GPIO_InitStruct.Alternate = GPIO_AF7_USART3;
|
|
|
|
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
|
|
|
|
|
|
|
/* USER CODE BEGIN USART3_MspInit 1 */
|
|
|
|
|
|
|
|
/* USER CODE END USART3_MspInit 1 */
|
|
|
|
}
|
|
|
|
else if(uartHandle->Instance==USART6)
|
|
|
|
{
|
|
|
|
/* USER CODE BEGIN USART6_MspInit 0 */
|
|
|
|
|
|
|
|
/* USER CODE END USART6_MspInit 0 */
|
|
|
|
|
|
|
|
/** Initializes the peripherals clock
|
|
|
|
*/
|
|
|
|
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USART6;
|
|
|
|
PeriphClkInitStruct.Usart6ClockSelection = RCC_USART6CLKSOURCE_PCLK2;
|
|
|
|
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
|
|
|
|
{
|
|
|
|
Error_Handler();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* USART6 clock enable */
|
|
|
|
__HAL_RCC_USART6_CLK_ENABLE();
|
|
|
|
|
|
|
|
__HAL_RCC_GPIOC_CLK_ENABLE();
|
|
|
|
/**USART6 GPIO Configuration
|
|
|
|
PC7 ------> USART6_RX
|
|
|
|
PC6 ------> USART6_TX
|
|
|
|
*/
|
|
|
|
GPIO_InitStruct.Pin = ARDUINO_RX_D0_Pin|ARDUINO_TX_D1_Pin;
|
|
|
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
|
|
|
GPIO_InitStruct.Alternate = GPIO_AF8_USART6;
|
|
|
|
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
|
|
|
|
|
|
|
/* USER CODE BEGIN USART6_MspInit 1 */
|
|
|
|
|
|
|
|
/* USER CODE END USART6_MspInit 1 */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle)
|
|
|
|
{
|
|
|
|
|
|
|
|
if(uartHandle->Instance==USART3)
|
|
|
|
{
|
|
|
|
/* USER CODE BEGIN USART3_MspDeInit 0 */
|
|
|
|
|
|
|
|
/* USER CODE END USART3_MspDeInit 0 */
|
|
|
|
/* Peripheral clock disable */
|
|
|
|
__HAL_RCC_USART3_CLK_DISABLE();
|
|
|
|
|
|
|
|
/**USART3 GPIO Configuration
|
|
|
|
PB10 ------> USART3_TX
|
|
|
|
PB11 ------> USART3_RX
|
|
|
|
*/
|
|
|
|
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_10|GPIO_PIN_11);
|
|
|
|
|
|
|
|
/* USER CODE BEGIN USART3_MspDeInit 1 */
|
|
|
|
|
|
|
|
/* USER CODE END USART3_MspDeInit 1 */
|
|
|
|
}
|
|
|
|
else if(uartHandle->Instance==USART6)
|
|
|
|
{
|
|
|
|
/* USER CODE BEGIN USART6_MspDeInit 0 */
|
|
|
|
|
|
|
|
/* USER CODE END USART6_MspDeInit 0 */
|
|
|
|
/* Peripheral clock disable */
|
|
|
|
__HAL_RCC_USART6_CLK_DISABLE();
|
|
|
|
|
|
|
|
/**USART6 GPIO Configuration
|
|
|
|
PC7 ------> USART6_RX
|
|
|
|
PC6 ------> USART6_TX
|
|
|
|
*/
|
|
|
|
HAL_GPIO_DeInit(GPIOC, ARDUINO_RX_D0_Pin|ARDUINO_TX_D1_Pin);
|
|
|
|
|
|
|
|
/* USER CODE BEGIN USART6_MspDeInit 1 */
|
|
|
|
|
|
|
|
/* USER CODE END USART6_MspDeInit 1 */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* USER CODE BEGIN 1 */
|
|
|
|
|
|
|
|
/* USER CODE END 1 */
|