feat(can): 增加EEPROM状态码和系统配置保存功能

- 在CAN通信中增加EEPROM状态码字段,并通过CAN FD发送
- 实现Flash EEPROM对系统配置参数的CRC校验与保存
- 改进目标角度、速度等关键参数的读写逻辑,支持掉电保存
- 调整EEPROM地址映射,优化错误处理和状态反馈机制
- 修复CRC计算相关问题,增强数据可靠性
This commit is contained in:
cbb
2025-12-18 18:23:34 +08:00
parent d6cf143e87
commit 7c2860f302
11 changed files with 546 additions and 225 deletions
+6 -4
View File
@@ -437,16 +437,17 @@ u8 CAN_transmiter::init() {
\brief CAN 数据更新
*/
void CAN_transmiter::update(void) {
target_angle_union.f = FOC.target_angle;
target_velocity_union.f = FOC.target_velocity;
limit_velocity_union.f = FOC.limit_velocity;
limit_voltage = FOC.limit_voltage * 1000;
mcu_temp = sampler.get_mcu_temp() * 100;
motor_temp = sampler.get_drv_temp() * 100;
Power_Voltage = sampler.get_vbus_voltage() * 1000;
rt_angle_union.f = FOC.rt_angle;
// rt_velocity_union.f = KTH7823.getVelocity();
rt_velocity_union.f = FOC.rt_velocity;
MotorStatus = gpio_input_bit_get(GPIOB, GPIO_PIN_2) == RESET;
EEPROMStatus = flashEEP.EEPROMStatus;
Target_Control_Mode = FOC.control_mode;
controller_Mode = FOC.control_mode;
@@ -634,8 +635,7 @@ u8 CAN_transmiter::CANFD_all_Send() {
transmit_data[10] =
(transmit_data[10] & ~0x07) |
((MotorStatus & 0x01) | ((MagStatus & 0x01) << 1) |
((ThermalStatus & 0x01) << 2) | ((EEPROMStatus & 0x01) << 3));
((ThermalStatus & 0x01) << 2) | ((EEPROMStatus & 0x07) << 3));
pack_u16_to_bytes(transmit_data, 11, Power_Voltage);
pack_float_to_bytes(transmit_data, 13, rt_angle_union);
pack_float_to_bytes(transmit_data, 17, rt_velocity_union);
@@ -697,6 +697,8 @@ void CAN_transmiter::communication_check() {
} else if (receive_message.rx_efid == 0x00010301) {
motor_reset();
flashEEP.save_angle(FOC.rt_angle, false);
flashEEP.save_system_config(false);
} else {
printf("Unknown CAN ID: %X\n", receive_message.rx_efid);
}
+1 -1
View File
@@ -82,6 +82,7 @@ class CAN_transmiter {
bool MotorStatus = 0; // 电机状态码
float_union_t target_angle_union = {0}; // 目标角度
u8 Target_Control_Mode = 0; // 目标控制模式
u8 EEPROMStatus = 0; // EEPROM状态码
float_union_t target_velocity_union = {0}; // 目标速度
float_union_t u_current_union = {0}; // U相电流
float_union_t w_current_union = {0}; // W相电流
@@ -110,7 +111,6 @@ class CAN_transmiter {
bool MagStatus = 0; // 磁状态码
bool ThermalStatus = 0; // 热能状态码
bool EEPROMStatus = 0; // EEPROM状态码
void communication_check(); // 通信检查
};