added rs485 usart1

stable
Penguin 3 years ago
parent ce63792708
commit a6db0bddef

@ -9,17 +9,17 @@ CDefines=USE_HAL_DRIVER;STM32L432xx;USE_HAL_DRIVER;USE_HAL_DRIVER;
[PreviousGenFiles]
AdvancedFolderStructure=true
HeaderFileListSize=3
HeaderFiles#0=/storage/Shared/Projects/stm32_projects/motor_controller/Core/Inc/stm32l4xx_it.h
HeaderFiles#1=/storage/Shared/Projects/stm32_projects/motor_controller/Core/Inc/stm32l4xx_hal_conf.h
HeaderFiles#2=/storage/Shared/Projects/stm32_projects/motor_controller/Core/Inc/main.h
HeaderFiles#0=/storage/Shared/Projects/Penguinator/motor_controller/Core/Inc/stm32l4xx_it.h
HeaderFiles#1=/storage/Shared/Projects/Penguinator/motor_controller/Core/Inc/stm32l4xx_hal_conf.h
HeaderFiles#2=/storage/Shared/Projects/Penguinator/motor_controller/Core/Inc/main.h
HeaderFolderListSize=1
HeaderPath#0=/storage/Shared/Projects/stm32_projects/motor_controller/Core/Inc
HeaderPath#0=/storage/Shared/Projects/Penguinator/motor_controller/Core/Inc
HeaderFiles=;
SourceFileListSize=3
SourceFiles#0=/storage/Shared/Projects/stm32_projects/motor_controller/Core/Src/stm32l4xx_it.c
SourceFiles#1=/storage/Shared/Projects/stm32_projects/motor_controller/Core/Src/stm32l4xx_hal_msp.c
SourceFiles#2=/storage/Shared/Projects/stm32_projects/motor_controller/Core/Src/main.c
SourceFiles#0=/storage/Shared/Projects/Penguinator/motor_controller/Core/Src/stm32l4xx_it.c
SourceFiles#1=/storage/Shared/Projects/Penguinator/motor_controller/Core/Src/stm32l4xx_hal_msp.c
SourceFiles#2=/storage/Shared/Projects/Penguinator/motor_controller/Core/Src/main.c
SourceFolderListSize=1
SourcePath#0=/storage/Shared/Projects/stm32_projects/motor_controller/Core/Src
SourcePath#0=/storage/Shared/Projects/Penguinator/motor_controller/Core/Src
SourceFiles=;

@ -73,8 +73,6 @@ void setPWM(TIM_HandleTypeDef *timer, uint32_t channel, uint8_t dc_percent);
#define SWCLK_GPIO_Port GPIOA
#define VCP_RX_Pin GPIO_PIN_15
#define VCP_RX_GPIO_Port GPIOA
#define LD3_Pin GPIO_PIN_3
#define LD3_GPIO_Port GPIOB
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */

@ -44,9 +44,10 @@
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
TIM_HandleTypeDef htim2;
TIM_HandleTypeDef htim2;
TIM_HandleTypeDef htim6;
UART_HandleTypeDef huart1;
UART_HandleTypeDef huart2;
/* USER CODE BEGIN PV */
@ -64,6 +65,7 @@ static void MX_GPIO_Init(void);
static void MX_TIM2_Init(void);
static void MX_USART2_UART_Init(void);
static void MX_TIM6_Init(void);
static void MX_USART1_UART_Init(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
@ -104,6 +106,7 @@ int main(void)
MX_TIM2_Init();
MX_USART2_UART_Init();
MX_TIM6_Init();
MX_USART1_UART_Init();
/* USER CODE BEGIN 2 */
p_uart_init(&huart2);
@ -291,6 +294,41 @@ static void MX_TIM6_Init(void)
}
/**
* @brief USART1 Initialization Function
* @param None
* @retval None
*/
static void MX_USART1_UART_Init(void)
{
/* USER CODE BEGIN USART1_Init 0 */
/* USER CODE END USART1_Init 0 */
/* USER CODE BEGIN USART1_Init 1 */
/* USER CODE END USART1_Init 1 */
huart1.Instance = USART1;
huart1.Init.BaudRate = 115200;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;
huart1.Init.Mode = UART_MODE_TX_RX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_RS485Ex_Init(&huart1, UART_DE_POLARITY_HIGH, 0, 0) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN USART1_Init 2 */
/* USER CODE END USART1_Init 2 */
}
/**
* @brief USART2 Initialization Function
* @param None
@ -343,9 +381,6 @@ static void MX_GPIO_Init(void)
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOA, m1_dir_Pin|m2_dir_Pin|GPIO_PIN_8|GPIO_PIN_9, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(LD3_GPIO_Port, LD3_Pin, GPIO_PIN_RESET);
/*Configure GPIO pins : m1_dir_Pin m2_dir_Pin PA8 PA9 */
GPIO_InitStruct.Pin = m1_dir_Pin|m2_dir_Pin|GPIO_PIN_8|GPIO_PIN_9;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
@ -353,13 +388,6 @@ static void MX_GPIO_Init(void)
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/*Configure GPIO pin : LD3_Pin */
GPIO_InitStruct.Pin = LD3_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(LD3_GPIO_Port, &GPIO_InitStruct);
}
/* USER CODE BEGIN 4 */

@ -209,7 +209,42 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
if(huart->Instance==USART2)
if(huart->Instance==USART1)
{
/* USER CODE BEGIN USART1_MspInit 0 */
/* USER CODE END USART1_MspInit 0 */
/** Initializes the peripherals clock
*/
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1;
PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
Error_Handler();
}
/* Peripheral clock enable */
__HAL_RCC_USART1_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/**USART1 GPIO Configuration
PB3 (JTDO-TRACESWO) ------> USART1_DE
PB6 ------> USART1_TX
PB7 ------> USART1_RX
*/
GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_6|GPIO_PIN_7;
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_USART1;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/* USER CODE BEGIN USART1_MspInit 1 */
/* USER CODE END USART1_MspInit 1 */
}
else if(huart->Instance==USART2)
{
/* USER CODE BEGIN USART2_MspInit 0 */
@ -264,7 +299,26 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart)
*/
void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
{
if(huart->Instance==USART2)
if(huart->Instance==USART1)
{
/* USER CODE BEGIN USART1_MspDeInit 0 */
/* USER CODE END USART1_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_USART1_CLK_DISABLE();
/**USART1 GPIO Configuration
PB3 (JTDO-TRACESWO) ------> USART1_DE
PB6 ------> USART1_TX
PB7 ------> USART1_RX
*/
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_3|GPIO_PIN_6|GPIO_PIN_7);
/* USER CODE BEGIN USART1_MspDeInit 1 */
/* USER CODE END USART1_MspDeInit 1 */
}
else if(huart->Instance==USART2)
{
/* USER CODE BEGIN USART2_MspDeInit 0 */

@ -1,5 +1,5 @@
##########################################################################################################################
# File automatically-generated by tool: [projectgenerator] version: [3.16.0] date: [Fri Apr 01 16:19:23 CDT 2022]
# File automatically-generated by tool: [projectgenerator] version: [3.16.0] date: [Wed Apr 06 17:16:57 CDT 2022]
##########################################################################################################################
# ------------------------------------------------

@ -8,8 +8,9 @@ Mcu.IP1=RCC
Mcu.IP2=SYS
Mcu.IP3=TIM2
Mcu.IP4=TIM6
Mcu.IP5=USART2
Mcu.IPNb=6
Mcu.IP5=USART1
Mcu.IP6=USART2
Mcu.IPNb=7
Mcu.Name=STM32L432K(B-C)Ux
Mcu.Package=UFQFPN32
Mcu.Pin0=PC14-OSC32_IN (PC14)
@ -18,8 +19,10 @@ Mcu.Pin10=PA13 (JTMS-SWDIO)
Mcu.Pin11=PA14 (JTCK-SWCLK)
Mcu.Pin12=PA15 (JTDI)
Mcu.Pin13=PB3 (JTDO-TRACESWO)
Mcu.Pin14=VP_SYS_VS_Systick
Mcu.Pin15=VP_TIM6_VS_ClockSourceINT
Mcu.Pin14=PB6
Mcu.Pin15=PB7
Mcu.Pin16=VP_SYS_VS_Systick
Mcu.Pin17=VP_TIM6_VS_ClockSourceINT
Mcu.Pin2=PA0
Mcu.Pin3=PA1
Mcu.Pin4=PA2
@ -28,7 +31,7 @@ Mcu.Pin6=PA4
Mcu.Pin7=PA5
Mcu.Pin8=PA8
Mcu.Pin9=PA9
Mcu.PinsNb=16
Mcu.PinsNb=18
Mcu.ThirdPartyNb=0
Mcu.UserConstants=
Mcu.UserName=STM32L432KCUx
@ -86,10 +89,14 @@ PA8.Locked=true
PA8.Signal=GPIO_Output
PA9.Locked=true
PA9.Signal=GPIO_Output
PB3\ (JTDO-TRACESWO).GPIOParameters=GPIO_Label
PB3\ (JTDO-TRACESWO).GPIO_Label=LD3 [Green]
PB3\ (JTDO-TRACESWO).Locked=true
PB3\ (JTDO-TRACESWO).Signal=GPIO_Output
PB3\ (JTDO-TRACESWO).Mode=Hardware Flow Control (RS485)
PB3\ (JTDO-TRACESWO).Signal=USART1_DE
PB6.Mode=Asynchronous
PB6.Signal=USART1_TX
PB7.Locked=true
PB7.Mode=Asynchronous
PB7.Signal=USART1_RX
PC14-OSC32_IN\ (PC14).Locked=true
PC14-OSC32_IN\ (PC14).Mode=LSE-External-Oscillator
PC14-OSC32_IN\ (PC14).Signal=RCC_OSC32_IN
@ -124,7 +131,7 @@ ProjectManager.StackSize=0x400
ProjectManager.TargetToolchain=Makefile
ProjectManager.ToolChainLocation=
ProjectManager.UnderRoot=false
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_TIM2_Init-TIM2-false-HAL-true,4-MX_USART2_UART_Init-USART2-false-HAL-true,5-MX_TIM1_Init-TIM1-false-HAL-true
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_TIM2_Init-TIM2-false-HAL-true,4-MX_USART2_UART_Init-USART2-false-HAL-true,5-MX_TIM6_Init-TIM6-false-HAL-true
RCC.48CLKFreq_Value=24000000
RCC.AHBFreq_Value=32000000
RCC.APB1Freq_Value=32000000
@ -195,6 +202,9 @@ TIM6.AutoReloadPreload=TIM_AUTORELOAD_PRELOAD_ENABLE
TIM6.IPParameters=Prescaler,AutoReloadPreload,Period
TIM6.Period=249
TIM6.Prescaler=127
USART1.IPParameters=VirtualMode-Asynchronous,VirtualMode-Hardware Flow Control (RS485)
USART1.VirtualMode-Asynchronous=VM_ASYNC
USART1.VirtualMode-Hardware\ Flow\ Control\ (RS485)=VM_ASYNC
USART2.IPParameters=VirtualMode-Asynchronous
USART2.VirtualMode-Asynchronous=VM_ASYNC
VP_SYS_VS_Systick.Mode=SysTick

Loading…
Cancel
Save