Добавлена адресация к бутлоадеру

This commit is contained in:
lulko 2025-03-22 13:56:28 +03:00
parent a1bcbdb33b
commit cf1c6eb05c
4 changed files with 50 additions and 21 deletions

View file

@ -12,6 +12,11 @@ volatile uint32_t fw_crc = 0;
volatile uint32_t jump;
static FLASH_RECORD flash_record = {0};
static uint32_t ptr_flash;
volatile uint32_t msg_id;
volatile uint16_t id_x;
volatile uint8_t msg_ch;
// Прототипы функций
void jump_to_app();
void process_can_message(const CAN_message_t &msg);
@ -32,8 +37,8 @@ void setup() {
// SendTimer->attachInterrupt(process_can_message);
SendTimer->resume();
// Разрешить все ID (маска 0x00000000)
Can.setFilter(0, 0, STD);
Can.setFilter(0, 0, STD);
// Настройка GPIO
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOCEN;
GPIOC->MODER |= GPIO_MODER_MODE10_0 | GPIO_MODER_MODE11_0;
@ -54,12 +59,15 @@ void setup() {
if(*(volatile uint32_t*)(FLAG_BOOT) == UPDATE_FLAG) {
fw_update = true;
GPIOC->ODR |= GPIO_ODR_OD10; // Индикация обновления
for(int i = 0; i < 5;i++){
GPIOC->ODR ^= GPIO_ODR_OD10; // Индикация обновления
HAL_Delay(100);
}
erase_flash_pages();
} else {
jump_to_app();
}
}
void loop() {
@ -75,7 +83,15 @@ void loop() {
void process_can_message(const CAN_message_t &msg) {
switch(msg.id) {
msg_id = msg.id;
/* 0x691
69 - адрес устройства
1 - что делать дальше с данными */
id_x = (msg_id >> 4) & 0xFFFF; //получение адреса устройства страшие 2 бита
msg_ch = msg_id & 0xF; // получения id, чтобы выбрать, что делать
if(id_x == flash_record.value){
switch(msg_ch) {
case BOOT_CAN_ID:
if(msg.buf[0] == 0x01) { // Старт передачи
fw_size = *(uint32_t*)&msg.buf[1]; //размер прошивки тип 4 байта
@ -97,8 +113,8 @@ void process_can_message(const CAN_message_t &msg) {
case BOOT_CAN_END: // Завершение передачи
if(verify_firmware()) {
erase_sector(7); // Сброс флага
send_ack(0xAA);
erase_sector(7); // Сброс флага
NVIC_SystemReset();
} else {
send_ack(0x55);
@ -106,8 +122,7 @@ void process_can_message(const CAN_message_t &msg) {
break;
}
}
}
void jump_to_app() {
__disable_irq();
@ -177,4 +192,3 @@ void send_ack(uint8_t status) {
ack.buf[0] = status;
Can.write(ack);
}