feat(ota): 修复备份APP区域恢复功能和OTA流程优化、启用BRS、减小延时

- 添加sendBackup方法用于在备份APP激活时发送确认消息
- 优化OTA跳转逻辑,在jumpToApplication中清除复位标志
- 修复move_app_data函数中数据源地址错误,从备份区域正确读取数据
- 在OTA流程中正确设置APP状态标志,确保应用验证状态管理

refactor(can): 清理调试代码和函数签名优化

- 移除调试用的printf语句和未使用的cstdio头文件
- 统一函数参数类型为u8和u32,提高代码一致性
- 优化CAN通信检查逻辑,移除冗余的调试输出

perf(ota): 优化OTA处理中的延时函数

- 将delay_1ms(1)改为delay_1us(100),提高延时精度
- 添加微秒级延时函数delay_1us实现
- 增加OTA超时时间从10秒到100秒

fix(ota): 修复OTA状态管理和错误处理

- 在各种错误情况下正确设置ota_state为OTA_STATE_IDLE
- 在eraseApplicationArea中正确初始化APP状态标志
- 添加CRC校验失败时的调试输出选项
- 修复数据包大小验证逻辑
This commit is contained in:
cbb
2026-01-07 23:14:15 +08:00
parent c7c4451d57
commit aefb7d4ee4
18 changed files with 1384 additions and 1328 deletions
+11 -11
View File
@@ -10,20 +10,20 @@
class OTAHandler {
public:
u32 ota_stateota_time;
uint32_t received_size;
uint32_t expected_size;
u32 received_size;
u32 expected_size;
void init();
void process();
bool isActive() const { return ota_state; }
void handleOTAMessage(uint32_t id, uint8_t *data, uint8_t len);
void handleOTAMessage(u32 id, u8 *data, u8 len);
void jumpToApplication();
private:
u16 ota_time;
u32 ota_time;
void eraseApplicationArea();
void writeApplicationData(uint32_t offset, uint8_t *data, uint32_t size);
void writeApplicationData(u32 offset, u8 *data, u32 size);
bool verifyApplicationData(u32 offset, u8 *data, u32 size);
typedef enum {
OTA_STATE_IDLE = 0,
@@ -44,18 +44,18 @@ class OTAHandler {
OTA_ERROR_INVALID_SIZE
} ota_error_t;
uint8_t device_uid[12]; // 从GD32 UID寄存器读取
uint8_t current_K_session[16];
uint8_t nonce_server[16];
u8 device_uid[12]; // 从GD32 UID寄存器读取
u8 current_K_session[16];
u8 nonce_server[16];
aes128_context aes_ctx; // AES上下文
ota_state_t ota_state = OTA_STATE_IDLE;
ota_error_t ota_error = OTA_ERROR_NONE;
};
void getDeviceSerialNumber(uint8_t *buffer);
void calculate_crc32_with_key(const uint8_t *key, const uint8_t *data,
void getDeviceSerialNumber(u8 *buffer);
void calculate_crc32_with_key(const u8 *key, const u8 *data,
u8 *output);
void send_error_frame(uint8_t error);
void send_error_frame(u8 error);
bool validateApplication();
fmc_state_enum move_app_data();