diff --git a/controller/fw/embed/include/flash.h b/controller/fw/embed/include/flash.h index 0b7f427..01ec21b 100644 --- a/controller/fw/embed/include/flash.h +++ b/controller/fw/embed/include/flash.h @@ -19,6 +19,7 @@ enum { pid_p = 1, pid_i, pid_d, + firmw, foc_id, angl, vel @@ -31,8 +32,8 @@ union{ }conv_float_to_int; #define FLASH_RECORD_SIZE sizeof(FLASH_RECORD) //size flash struct -#define PARAM_COUNT 4 // count data in flash - +#define PARAM_COUNT 5 // count data in flash +#define FIRMWARE_FLAG (uint32_t)0xDEADBEEF // Flash sectors for STM32F407 #define SECTOR_2 0x08008000 // 16KB diff --git a/controller/fw/embed/include/process_can.h b/controller/fw/embed/include/process_can.h index 316e07e..377414d 100644 --- a/controller/fw/embed/include/process_can.h +++ b/controller/fw/embed/include/process_can.h @@ -17,6 +17,7 @@ void send_angle(); void send_motor_enabled(); void send_motor_enabled(); void send_id(); +void firmware_update(); // void send_motor_torque(); void send_pid(uint8_t param_pid); void setup_id(uint8_t my_id); diff --git a/controller/fw/embed/include/reg_cah.h b/controller/fw/embed/include/reg_cah.h index 2760dcf..68f2405 100644 --- a/controller/fw/embed/include/reg_cah.h +++ b/controller/fw/embed/include/reg_cah.h @@ -37,6 +37,7 @@ #define MOTOR_ANGLE 0x72 #define MOTOR_TORQUE 0x73 +#define FIRMWARE_UPDATE 0x55 //For send #define CAN_MSG_MAX_LEN 7 diff --git a/controller/fw/embed/src/main.cpp b/controller/fw/embed/src/main.cpp index 9e616e2..b086b59 100644 --- a/controller/fw/embed/src/main.cpp +++ b/controller/fw/embed/src/main.cpp @@ -78,6 +78,7 @@ volatile uint32_t ipsr_value = 0; // Настройка прерываний CAN CAN2->IER |= CAN_IER_FMPIE0; flash_rec = load_params(); //for update write_ptr + if(flash_rec[firmw].value == FIRMWARE_FLAG) NVIC_SystemReset(); //if in flash go to the bootloader // write_param(addr_id,39); // flash_rec = load_params(); diff --git a/controller/fw/embed/src/process_can.cpp b/controller/fw/embed/src/process_can.cpp index aa469be..89c8b60 100644 --- a/controller/fw/embed/src/process_can.cpp +++ b/controller/fw/embed/src/process_can.cpp @@ -118,6 +118,11 @@ void setup_id(uint8_t my_id) { write_param(addr_id,my_id); } +void firmware_update(){ + write_param(firmw,FIRMWARE_FLAG); + NVIC_SystemReset(); +} + void setup_angle(float target_angle) { motor.enable(); // Enable motor if disabled motor.controller = MotionControlType::angle; @@ -142,6 +147,8 @@ void setup_pid_angle(uint8_t param_pid, float data){ write_param(param_pid,data); } + + void listen_can(const CAN_message_t &msg) { msg_id = msg.id; msg_ch = msg_id & 0xF; // Extract message channel @@ -203,6 +210,10 @@ void listen_can(const CAN_message_t &msg) { conv_float_to_int.f = motor.P_angle.D; write_param(pid_d,conv_float_to_int.i); break; + + case FIRMWARE_UPDATE: + firmware_update(); + break; case MOTOR_ENABLED: if (msg.buf[1] == 1) {