feat(device): 添加早期诊断功能并优化SPI通信实现
- 在startup_gd32e50x_cl.s中添加USART0早期诊断代码,在Reset_Handler中 发送'R'字符以确认启动过程 - 修改system_gd32e50x.c中的时钟初始化逻辑,支持动态检测当前时钟源 (PLL或IRC8M)并相应调整串口波特率设置 - 在系统时钟配置函数中添加HXTAL故障诊断输出,当外部晶振启动失败时 通过USART0输出"HXTAL FAIL"错误信息 - 在AppSpiCommand类中实现DMA传输机制,使用DMA0_CH2进行SPI0数据发送, 提升传输效率并与BOOT端保持一致 - 重构SPI命令处理逻辑,优化PING命令响应格式,包含APP和BOOT版本信息 以及运行时间统计 - 添加事务过滤机制,忽略全0xFF或全0x00的数据包以及短帧 - 更新配置文件定义APP固件版本号和OTA配置页面地址 - 修复region配置文件中的ROM大小数值精度问题 - 调整NVIC中断优先级设置,优化SPI中断处理
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
#ifndef DEVICE_APP_SPI_COMMAND_H
|
||||
#define DEVICE_APP_SPI_COMMAND_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* @brief APP 运行期 SPI 命令从机模块。
|
||||
*
|
||||
* 复用 BOOT 的 SpiOta 协议帧格式(SOF+TYPE+LEN+PAYLOAD+CRC):
|
||||
* - TYPE=0xB0 → 请求进入 Bootloader,回复 ACK 帧
|
||||
* - TYPE=0x01/0x02/0x03(OTA 命令)→ 回复 WAIT 帧(不在 BOOT 模式)
|
||||
* - 旧式单字节 0xB0 命令仍兼容
|
||||
*
|
||||
* 调试日志采用延迟输出:processCommand() 只写缓冲+置标志,
|
||||
* poll() 中再 printf,避免在帧处理路径上耗时。
|
||||
*/
|
||||
class AppSpiCommand {
|
||||
public:
|
||||
/** @brief 初始化 SPI0 从机命令通道。 */
|
||||
static void init();
|
||||
|
||||
/** @brief 主循环轮询:打印延迟日志。 */
|
||||
static void poll();
|
||||
|
||||
/** @brief SPI0 中断处理入口。 */
|
||||
static void onInterrupt();
|
||||
|
||||
/** @brief CS 边沿中断处理入口。 */
|
||||
static void onCsExtiInterrupt();
|
||||
|
||||
private:
|
||||
static constexpr uint16_t kRxBufSize = 128U;
|
||||
static constexpr uint16_t kTxBufSize = 64U;
|
||||
static constexpr uint16_t kLogBufSize = 128U;
|
||||
|
||||
static volatile bool s_csActive;
|
||||
static volatile uint8_t s_rxLen;
|
||||
static volatile uint8_t s_txLen;
|
||||
static volatile uint8_t s_txPos;
|
||||
static volatile bool s_logPending;
|
||||
static uint8_t s_rxBuf[kRxBufSize];
|
||||
static uint8_t s_txBuf[kTxBufSize];
|
||||
static char s_logBuf[kLogBufSize];
|
||||
|
||||
static void configureGpio();
|
||||
static void configureSpi0();
|
||||
static void configureExti();
|
||||
static void onCsAssert();
|
||||
static void onCsRelease();
|
||||
static void processCommand();
|
||||
static void logDeferred(const char *msg);
|
||||
static void logDeferredFmt(const char *fmt, uint8_t val);
|
||||
};
|
||||
|
||||
#endif /* DEVICE_APP_SPI_COMMAND_H */
|
||||
Reference in New Issue
Block a user