From 249409457fcd556b5fbcecffa6330ab7a495d32b Mon Sep 17 00:00:00 2001 From: iorebuild Date: Wed, 3 Jun 2026 19:53:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=9E=B6=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bsp/Inc/VoiletPort.h | 13 +++++-------- Bsp/Src/Bsp.c | 29 ++++++++++++++++++++++------- Bsp/Src/Uart.c | 4 ++++ 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/Bsp/Inc/VoiletPort.h b/Bsp/Inc/VoiletPort.h index 6ec5408..1350d22 100644 --- a/Bsp/Inc/VoiletPort.h +++ b/Bsp/Inc/VoiletPort.h @@ -209,31 +209,28 @@ typedef struct { void (*ClockCmd)(uint32_t RccPeriph, FunctionalState State); unsigned int ClockTree; COM_PERIPH_T Periph; - GPIO_MAP_T TxRxEn; //收发使能 } COM_MAP_T; typedef struct { COM_MAP_T *ComX; //串口外设 GPIO_MAP_T TxPort; //发送端口 GPIO_MAP_T RxPort; //接收端口 - unsigned char Rs485; //是否是Rs485 GPIO_MAP_T TxRxEn; //收发使能 - GPIOSpeed_TypeDef Speed; //IO口速度 }COM_CONFIG; #define COM_NUM 5 #ifdef USART1 -#define COM0 (&(COM_MAP_T){RCC_APB2PeriphClockCmd, RCC_APB2Periph_USART1, {USART1,USART1_IRQn},GPIO_NULL}) +#define COM0 (&(COM_MAP_T){RCC_APB2PeriphClockCmd, RCC_APB2Periph_USART1, {USART1,USART1_IRQn}}) #endif #ifdef USART2 -#define COM1 (&(COM_MAP_T){RCC_APB1PeriphClockCmd, RCC_APB1Periph_USART2, {USART2,USART2_IRQn},GPIO_NULL}) +#define COM1 (&(COM_MAP_T){RCC_APB1PeriphClockCmd, RCC_APB1Periph_USART2, {USART2,USART2_IRQn}}) #endif #ifdef USART3 -#define COM2 (&(COM_MAP_T){RCC_APB1PeriphClockCmd, RCC_APB1Periph_USART3,{USART3,USART3_IRQn},GPIO_NULL}) +#define COM2 (&(COM_MAP_T){RCC_APB1PeriphClockCmd, RCC_APB1Periph_USART3,{USART3,USART3_IRQn}}) #endif #ifdef UART4 -#define COM3 (&(COM_MAP_T){RCC_APB1PeriphClockCmd, RCC_APB1Periph_UART4,{UART4,UART4_IRQn},GPIO_NULL}) +#define COM3 (&(COM_MAP_T){RCC_APB1PeriphClockCmd, RCC_APB1Periph_UART4,{UART4,UART4_IRQn}}) #endif -#define COM4 (&(COM_MAP_T){RCC_APB1PeriphClockCmd, RCC_APB1Periph_UART5,{UART5,UART5_IRQn},GPIO_NULL}) +#define COM4 (&(COM_MAP_T){RCC_APB1PeriphClockCmd, RCC_APB1Periph_UART5,{UART5,UART5_IRQn}}) #endif //_VOILET_PORT_H diff --git a/Bsp/Src/Bsp.c b/Bsp/Src/Bsp.c index a07c6e6..53bb5fe 100644 --- a/Bsp/Src/Bsp.c +++ b/Bsp/Src/Bsp.c @@ -25,8 +25,8 @@ const GPIO_CONFIG DO_PERIPH[] = { #endif //串口配置表 const COM_CONFIG COM_PERIPH[] = { - {COM0,.TxPort = GPIO9, .RxPort =GPIO10, .Speed = GPIO_Speed_50MHz,.Rs485 = false}, - {COM1,.TxPort = GPIO2, .RxPort = GPIO3, .Speed = GPIO_Speed_50MHz,.Rs485 = true,.TxRxEn = GPIO55}, + {COM0,.TxPort = GPIO9, .RxPort =GPIO10}, + {COM1,.TxPort = GPIO2, .RxPort = GPIO3,.TxRxEn = GPIO55}, }; void BspExtraInit(void); @@ -78,11 +78,8 @@ void BspInit(void) { //串口配置 for (i = 0;i < ARRAY_LEN(COM_PERIPH);i++) { - GpioConfig(&COM_PERIPH[i].TxPort, GPIO_Mode_AF_PP, COM_PERIPH[i].Speed); - GpioConfig(&COM_PERIPH[i].RxPort, GPIO_Mode_IPU, COM_PERIPH[i].Speed); - if (COM_PERIPH[i].Rs485 == true) { - GpioConfig(&COM_PERIPH[i].TxRxEn, GPIO_Mode_AF_PP, COM_PERIPH[i].Speed); - } + GpioConfig(&COM_PERIPH[i].TxPort, GPIO_Mode_AF_PP, GPIO_Speed_2MHz); + GpioConfig(&COM_PERIPH[i].RxPort, GPIO_Mode_IPU, GPIO_Speed_2MHz); } INTERRUPT_ENABLE @@ -160,6 +157,24 @@ void LedToggle(uint8_t Chnl) GpioSet(&LED_PERIPH[Chnl].GpioX,LED_ON); } } + +void Rs485StdConfig(const COM_MAP_T *ComX,unsigned int Baud) +{ + for (unsigned char i = 0;i < ARRAY_LEN(COM_PERIPH);i++) { + if (ComX == COM_PERIPH[i].ComX) { + if (COM_PERIPH[i].TxRxEn.ClockTree) { + GpioSet(&COM_PERIPH[i].TxRxEn,Baud); + } + ComStdConfig(COM_PERIPH[i].ComX,Baud); + } + } +} + +void Rs485AdvConfig(const COM_MAP_T *ComX, uint32_t Baud, uint8_t DataBits, uint8_t StopBits, uint8_t Parity) +{ + +} + /** * @brief 重写Printf函数 * @note void diff --git a/Bsp/Src/Uart.c b/Bsp/Src/Uart.c index 2796a41..4f29495 100644 --- a/Bsp/Src/Uart.c +++ b/Bsp/Src/Uart.c @@ -93,4 +93,8 @@ void ComStdConfig(const COM_MAP_T *ComX, uint32_t Baud) void ComAdvConfig(const COM_MAP_T *ComX, uint32_t Baud, uint8_t DataBits, uint8_t StopBits, uint8_t Parity) { ComInit(ComX, Baud, DataBits, StopBits, Parity); +} + +unsigned int CalcBaudTransIoSpeed(unsigned int Baud) { + } \ No newline at end of file