diff --git a/controller/fw/bootloader/src/main.cpp b/controller/fw/bootloader/src/main.cpp index 4782660..f2f277b 100644 --- a/controller/fw/bootloader/src/main.cpp +++ b/controller/fw/bootloader/src/main.cpp @@ -7,6 +7,8 @@ STM32_CAN Can(CAN2, DEF); volatile bool fw_update = false; +volatile bool app_valid = false; + volatile uint32_t fw_size = 0; volatile uint16_t fw_crc = 0; volatile uint32_t jump; @@ -25,9 +27,7 @@ bool verify_firmware(); void send_ack(uint8_t status); void setup() { - // Инициализация периферии - SystemInit(); - SystemClock_Config(); + Serial.setRx(HARDWARE_SERIAL_RX_PIN); Serial.setTx(HARDWARE_SERIAL_TX_PIN); Serial.begin(115200); @@ -46,28 +46,25 @@ void setup() { GPIOC->MODER |= GPIO_MODER_MODE10_0 | GPIO_MODER_MODE11_0; GPIOC->ODR &= ~GPIO_ODR_OD11; GPIOC->ODR |= GPIO_ODR_OD10; - // // Проверка флага обновления - // erase_sector(7); - // flash_program_word(FLAG_BOOT,0xDEADBEEF,BYTE32); - // flash_record = load_params(); - // write_param(firmw,UPDATE_FLAG); + flash_record = load_params(); - // write_param(addr_id,33); - // flash_record = load_params(); + + /* Добавить проверку адреса, т.е во время отправки запроса прошивки по CAN мы сохраняем как флаг, так и аддрес устройства к которому будет обращатлься во время прошивки */ - if(flash_record[firmw].value == UPDATE_FLAG) { fw_update = true; for(int i = 0; i < 5;i++){ GPIOC->ODR ^= GPIO_ODR_OD10; // Индикация обновления delay(100); } + write_param(firmw,0); //reset flasg erase_flash_pages(); - } else { - jump_to_app(); } + else + jump_to_app(); + GPIOC->ODR |= GPIO_ODR_OD10; } @@ -99,15 +96,13 @@ void process_can_message(const CAN_message_t &msg) { send_ack(0x02); } - break; - + break; case BOOT_CAN_END: // Завершение передачи if(verify_firmware()) { send_ack(0xAA); - HAL_Delay(500); - // erase_sector(7); // Сброс флага write_param(firmw,0); //reset flasg + // erase_sector(7); // Сброс флага NVIC_SystemReset(); } else { send_ack(0x55); @@ -156,7 +151,6 @@ void send_ack(uint8_t status) { Can.write(ack); } - void loop() { if(fw_update) { CAN_message_t msg; diff --git a/controller/fw/embed/platformio.ini b/controller/fw/embed/platformio.ini index b2b4e74..a15e7c9 100644 --- a/controller/fw/embed/platformio.ini +++ b/controller/fw/embed/platformio.ini @@ -7,6 +7,7 @@ debug_tool = stlink monitor_speed = 19200 monitor_parity = N +board_upload.offset_address = 0x08008000 board_build.ldscript = ${PROJECT_DIR}/custom_script.ld build_flags = @@ -14,11 +15,10 @@ build_flags = -D HAL_CAN_MODULE_ENABLED -D SIMPLEFOC_PWM_LOWSIDE_ACTIVE_HIGH - lib_deps = askuric/Simple FOC@^2.3.4 pazi88/STM32_CAN@^1.1.2 extra_scripts = pre:gen_compile_commands.py - post:hex_compile.py \ No newline at end of file + post:hex_compile.py diff --git a/controller/fw/embed/src/main.cpp b/controller/fw/embed/src/main.cpp index dd27397..907b94c 100644 --- a/controller/fw/embed/src/main.cpp +++ b/controller/fw/embed/src/main.cpp @@ -63,13 +63,13 @@ volatile uint32_t ipsr_value = 0; void setup(){ // Vector table initialization (commented out) - SCB->VTOR = (uint32_t)0x08008004; + SCB->VTOR = (volatile uint32_t)0x08008004; Serial.setRx(HARDWARE_SERIAL_RX_PIN); Serial.setTx(HARDWARE_SERIAL_TX_PIN); Serial.begin(115200); - // pinMode(PC11, OUTPUT); + pinMode(PC11, OUTPUT); pinMode(PC10,OUTPUT); GPIOC->ODR &= ~GPIO_ODR_OD10; // Can.enableMBInterrupts(); @@ -111,11 +111,12 @@ void loop() { // // Process incoming CAN messages while (Can.read(msg)) { + listen_can(msg); CAN_GET = true; } /* If receive data from CAN */ if(CAN_GET) { - listen_can(msg); + CAN_GET = false; } } diff --git a/controller/fw/embed/src/process_can.cpp b/controller/fw/embed/src/process_can.cpp index 3730926..b9b6217 100644 --- a/controller/fw/embed/src/process_can.cpp +++ b/controller/fw/embed/src/process_can.cpp @@ -6,7 +6,7 @@ static CAN_message_t CAN_inMsg; template -void send_can_with_id_crc(uint8_t id, uint8_t message_type, const T* data) { +void send_can_with_id_crc(uint8_t id, uint8_t message_type, T* data) { // Create CAN message CAN_message_t msg_l; msg_l.id = id; @@ -76,7 +76,6 @@ void send_id() { uint8_t id = flash_rec[addr_id].value; send_can_with_id_crc(id,'I',&id); - __NOP(); } // void send_motor_torque() {