#include "board.h" #include "bootloader.h" #include "core_cmFunc.h" #include "dev_iap.h" #include "global.h" #include "hal_flash.h" #include "iap.h" #include "queue.h" #include "stm32f4xx_gpio.h" #include "system_stm32f4xx.h" #include #include extern SqQueue CanQueueImportant; // CAN��Ҫ���ݶ��� uint16_t cache_buf[1024] = {0}; int main(void) { rt_hw_board_init(); uint32_t w_size = 0; u16 cnt = 0; CanData_TypeDef element; rt_pin_mode(RED_LED_PIN, PIN_MODE_OUTPUT); rt_pin_mode(GREEN_LED_PIN, PIN_MODE_OUTPUT); InitQueue(&CanQueueImportant); can_init(); iap_param_init(); fmc_read_n_half_word(UPGRADE_FLAG_START_ADDR, upgrade.infor_buf, 4); if (upgrade.param.sign == UPGRADE_SIGN) { if (check_addr_sp(DOWNLOAD_START_ADDR)) { fmc_clear_flag_star(); erase_app_flash(APP_START_ADDR, APP_END_ADDR); while (w_size < upgrade.param.moving_size) { if ((upgrade.param.moving_size - w_size) > FMC_PAGE_SIZE) { fmc_read_n_half_word(DOWNLOAD_START_ADDR + w_size, cache_buf, FMC_PAGE_SIZE_U16); fmc_write_n_half_word(APP_START_ADDR + w_size, cache_buf, FMC_PAGE_SIZE_U16); w_size += FMC_PAGE_SIZE; } else { if (((upgrade.param.moving_size - w_size) % 2) != 0) w_size--; fmc_read_n_half_word(DOWNLOAD_START_ADDR + w_size, cache_buf, (upgrade.param.moving_size - w_size) / 2); fmc_write_n_half_word(APP_START_ADDR + w_size, cache_buf, (upgrade.param.moving_size - w_size) / 2); w_size = upgrade.param.moving_size; } } fmc_clear_flag_end(); if (check_addr_sp(APP_START_ADDR) && check_addr_pc(APP_START_ADDR + 4)) { CAN_DeInit(CAN1); __set_PRIMASK(1); boot_goto_app(); } else { iap_flag_release(); } } else { iap_flag_release(); CAN_DeInit(CAN1); __set_PRIMASK(1); boot_goto_app(); } } if (INVALID == check_addr_sp(APP_START_ADDR)) { if (check_addr_sp(DOWNLOAD_START_ADDR)) { fmc_clear_flag_star(); erase_app_flash(APP_START_ADDR, APP_END_ADDR); while (w_size < upgrade.param.moving_size) { if ((upgrade.param.moving_size - w_size) > FMC_PAGE_SIZE) { fmc_read_n_half_word(DOWNLOAD_START_ADDR + w_size, cache_buf, FMC_PAGE_SIZE_U16); fmc_write_n_half_word(APP_START_ADDR + w_size, cache_buf, FMC_PAGE_SIZE_U16); w_size += FMC_PAGE_SIZE; } else { if (((upgrade.param.moving_size - w_size) % 2) != 0) w_size--; fmc_read_n_half_word(DOWNLOAD_START_ADDR + w_size, cache_buf, (upgrade.param.moving_size - w_size) / 2); fmc_write_n_half_word(APP_START_ADDR + w_size, cache_buf, (upgrade.param.moving_size - w_size) / 2); w_size = upgrade.param.moving_size; } } fmc_clear_flag_end(); if (check_addr_sp(APP_START_ADDR) && check_addr_pc(APP_START_ADDR)) { CAN_DeInit(CAN1); __set_PRIMASK(1); boot_goto_app(); } } } else { CAN_DeInit(CAN1); __set_PRIMASK(1); boot_goto_app(); } while (1) { // if (GetHead(&CanQueueImportant, &element) != ERROR) // { // cnt = 0; // // delay_ms(1000); // GPIO_ToggleBits(GPIOF, GPIO_Pin_9); // iap_process(&element); // } // else if (flash_up_is_ok() == TRUE) // { // iap_from_flash(); // boot_goto_app(); // } // else // { // cnt++; // delay_ms(10); // if (cnt > 100) // { // boot_goto_app(); // } // } } }