STM_ATEM/User/rs485_driver.c
zhoujie 3c0acaa176 feat(config): 新增运行时配置管理功能
- 新增配置管理器模块,支持从SD卡加载运行时配置
- 将数据输出模式从编译时宏改为运行时配置,提高灵活性
- 新增配置文件 `CONFIG.TXT`,支持串口输出和存储功能的动态开关
- 集成配置管理器到主程序,在系统启动时自动加载配置
- 更新数据存储模块,使用配置管理器管理会话序号

🐛 fix(usart): 修复USART3中断配置并优化波特率

- 添加USART3中断处理函数声明和实现
- 将USART3波特率从921600提升至2000000以提高通信速率
- 调整USART1中断优先级从2改为11,优化中断响应
- 在USART3 MSP初始化和反初始化中添加中断配置

📝 docs(user): 新增功能说明文档

- 新增《配置管理功能说明》文档,详细说明运行时配置的使用方法
- 新增《串口发送监控功能说明》文档,说明新增的串口统计功能
- 文档包含配置项说明、文件格式、使用示例和注意事项

 feat(monitor): 增强系统监控功能

- 在系统监控统计中添加串口发送监控字段(发送次数、字节数、错误数)
- 新增串口发送统计报告函数,集成到RS485驱动中
- 优化监控状态保存格式,采用精简格式减少文件写入阻塞时间
- 监控数据现在包含串口统计信息,便于性能分析和故障排查

♻️ refactor(main): 重构主程序配置处理逻辑

- 移除编译时宏 `DATA_OUTPUT_MODE_UART` 和 `DATA_OUTPUT_MODE_STORAGE`
- 使用 `Config_IsUartOutputEnabled()` 和 `Config_IsStorageEnabled()` 函数替代
- 优化数据存储启动逻辑,仅在存储功能启用时开始记录
- 添加配置加载成功/失败的调试输出信息
2026-02-07 14:28:14 +08:00

62 lines
1.7 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "rs485_driver.h"
#include "system_monitor.h"
#include <string.h>
static UART_HandleTypeDef *g_huart_485 = NULL;
static GPIO_TypeDef* g_de_re_port = NULL;
static uint16_t g_de_re_pin = 0;
volatile uint8_t g_rs485_tx_busy = 0;
void RS485_Init(UART_HandleTypeDef *huart, GPIO_TypeDef* de_re_port, uint16_t de_re_pin)
{
g_huart_485 = huart;
g_de_re_port = de_re_port;
g_de_re_pin = de_re_pin;
g_rs485_tx_busy = 0;
HAL_GPIO_WritePin(g_de_re_port, g_de_re_pin, GPIO_PIN_RESET); // 初始为接收模式
}
HAL_StatusTypeDef RS485_SendData(uint8_t *pData, uint16_t Size)
{
HAL_StatusTypeDef ret;
// 检查上一次传输是否完成
if (g_rs485_tx_busy)
{
return HAL_BUSY; // 上一次传输未完成,返回忙状态
}
g_rs485_tx_busy = 1; // 标记为忙状态
HAL_GPIO_WritePin(g_de_re_port, g_de_re_pin, GPIO_PIN_SET); // 设置为发送模式
// 使用DMA非阻塞发送
ret = HAL_UART_Transmit_DMA(g_huart_485, pData, Size);
if (ret != HAL_OK)
{
// 如果启动DMA失败需要清除忙标志并切换回接收模式
HAL_GPIO_WritePin(g_de_re_port, g_de_re_pin, GPIO_PIN_RESET);
g_rs485_tx_busy = 0;
// 报告串口发送错误
SystemMonitor_ReportUARTTxError();
}
else
{
// 报告串口发送成功(记录字节数)
SystemMonitor_ReportUARTTx(Size);
}
return ret;
}
// UART DMA传输完成回调函数
void RS485_TxCpltCallback(UART_HandleTypeDef *huart)
{
if (huart == g_huart_485)
{
// DMA传输完成后切换回接收模式
HAL_GPIO_WritePin(g_de_re_port, g_de_re_pin, GPIO_PIN_RESET);
g_rs485_tx_busy = 0; // 清除忙标志
}
}