樊春春 5 ヶ月 前
コミット
00e67c6d6d

+ 1 - 0
app/app_task.c

@@ -184,6 +184,7 @@ void SysTick_Handler(void)
     dev_systick_decrement();
     dev_systick_increase();
     systick_handler();
+    jump_boot_time_ctrl();
 }
 
 void app_task_schdule(void)

+ 29 - 3
dev/dev_iap.c

@@ -99,7 +99,7 @@ void iap_flag_release(void)
         {
             send_buff[i] = fmc_read_byte(UPGRADE_FLAG_START_ADDR + (UPGRADE_FLAG_DATA_SIZE * 2) + i);
         }
-        hal_can_msg_tx(0x180000001, CAN_Id_Extended, send_buff, 8);
+        hal_can_msg_tx(0x18000001, CAN_Id_Extended, send_buff, 8);
         CAN_ITConfig(CAN1, CAN_IT_TME, ENABLE);
     }
 }
@@ -109,10 +109,36 @@ uint8_t erase_app_flash(uint32_t start_address, uint32_t end_addr)
     uint8_t  status   = 0;
     uint16_t page_len = 0;
     // page_len          = (end_addr - start_address) / FMC_PAGE_SIZE;
-    status = fmc_erase_pages(start_address, page_len);
+    if ((start_address == ADDR_FLASH_SECTOR_2))
+    {
+        status = fmc_erase_pages(start_address, 5);
+    }
+    else if ((start_address == ADDR_FLASH_SECTOR_8))
+    {
+        status = fmc_erase_pages(start_address, 3);
+    }
+    else
+    {
+        status = 1;
+    }
+
     return status;
 }
 
+void jump_boot_time_ctrl(void)
+{
+    if (jump_boot_time > 0)
+    {
+        jump_boot_time--;
+        if (jump_boot_time == 0)
+        {
+            // jump_flag = 1;
+            __set_FAULTMASK(1); //  关闭所有中断
+            NVIC_SystemReset(); //  复位
+        }
+    }
+}
+
 void write_app_flash(uint16_t *buf, uint16_t pack_len, uint16_t pack_num)
 {
     static uint32_t w_start_addr = 0;
@@ -224,7 +250,7 @@ void iap_rec_handler(pdu_tag rec_msg)
             {
                 // 喂狗
                 fmc_clear_flag_star();
-                erase_flag = erase_app_flash(DOWNLOAD_START_ADDR, DOWNLOAD_MIDDLE_ADDR);
+                erase_flag = erase_app_flash(DOWNLOAD_START_ADDR, DOWNLOAD_END_ADDR);
                 fmc_clear_flag_end();
                 // 喂狗
                 g_iap.count_bytes    = 0;

+ 5 - 4
dev/dev_iap.h

@@ -38,14 +38,14 @@ extern 'C'
 #define UPGRADE_APP_DATA_SIZE  4                                                // 升级参数数组元素个数
 #define UPGRADE_BUFF_DATA_SIZE (UPGRADE_FLAG_DATA_SIZE + UPGRADE_APP_DATA_SIZE) // 升级参数数组元素个数
 
-#define APP_START_ADDR ((uint32_t)0x08010000)
-#define APP_END_ADDR   ((uint32_t)0x08060000)
+#define APP_START_ADDR ((uint32_t)0x08008000)
+#define APP_END_ADDR   ((uint32_t)0x0805FFFF)
 
 #define UPGRADE_FLAG_START_ADDR ((uint32_t)0x08060000)
-#define UPGRADE_FLAG_END_ADDR   ((uint32_t)0x08061000)
+#define UPGRADE_FLAG_END_ADDR   ((uint32_t)0x0807FFFF)
 
 #define DOWNLOAD_START_ADDR  ((uint32_t)0x08080000)
-#define DOWNLOAD_END_ADDR    ((uint32_t)0x080C0000)
+#define DOWNLOAD_END_ADDR    ((uint32_t)0x080DFFFF)
 #define DOWNLOAD_MIDDLE_ADDR ((uint32_t)0x080A0000)
 
 // 升级命令
@@ -103,6 +103,7 @@ extern 'C'
     void set_firmver(void);
     void iap_flag_release(void);
     void iap_param_init(void);
+    void jump_boot_time_ctrl(void);
     void iap_rec_handler(pdu_tag rec_msg);
 /************************************************************************************************
  *                                          Defines                                              *

BIN
docs/BOOT升级协议/CAN升级协议.xlsx


+ 23 - 3
hal/hal_flash.c

@@ -109,10 +109,30 @@ uint8_t fmc_read_one_page(uint32_t read_addr, uint16_t *buff)
 uint8_t fmc_erase_pages(uint32_t erase_addr, uint16_t len)
 {
     uint8_t status = 0;
-    status         = FLASH_EraseSector(fmc_get_flash_sector(erase_addr), VoltageRange_3);
-    if (status != FLASH_COMPLETE)
+    uint8_t i = 0, j = 0;
+    for (i = 0; i < len; i++)
     {
-        return 1;
+        status = FLASH_EraseSector(fmc_get_flash_sector(erase_addr), VoltageRange_3);
+        if (status != FLASH_COMPLETE)
+        {
+            return 1;
+        }
+        if ((erase_addr >= ADDR_FLASH_SECTOR_0) && (erase_addr < ADDR_FLASH_SECTOR_4))
+        {
+            erase_addr += (i * FMC_PAGE_SIZE_16K);
+        }
+        else if ((erase_addr >= ADDR_FLASH_SECTOR_4) && (erase_addr < ADDR_FLASH_SECTOR_5))
+        {
+            erase_addr += (i * FMC_PAGE_SIZE_64K);
+        }
+        else if ((erase_addr >= ADDR_FLASH_SECTOR_4) && (erase_addr < ADDR_FLASH_SECTOR_END))
+        {
+            erase_addr += (i * FMC_PAGE_SIZE_128K);
+        }
+        else
+        {
+            return 0;
+        }
     }
     return 0;
     // uint16_t i = 0, j = 0;

+ 5 - 0
hal/hal_flash.h

@@ -34,6 +34,11 @@ extern 'C'
 #define FMC_PAGE_SIZE_U16 ((uint16_t)0x400)
 #define FMC_FLASH_BASE    ((uint32_t)0x08000000)
 
+#define FMC_PAGE_SIZE_16K  ((uint32_t)0x4000)
+#define FMC_PAGE_SIZE_32K  ((uint32_t)0x8000)
+#define FMC_PAGE_SIZE_64K  ((uint32_t)0x10000)
+#define FMC_PAGE_SIZE_128K ((uint32_t)0x20000)
+
 // FLASH 扇区的起始地址
 #define ADDR_FLASH_SECTOR_0   ((u32)0x08000000) // 扇区0起始地址, 16 Kbytes
 #define ADDR_FLASH_SECTOR_1   ((u32)0x08004000) // 扇区1起始地址, 16 Kbytes

+ 1 - 1
project/gcc/STM32F417IG_FLASH.ld

@@ -40,7 +40,7 @@ _Min_Stack_Size = 0x400; /* required amount of stack */
 /* Specify the memory areas */
 MEMORY
 {
-  FLASH (rx)      : ORIGIN = 0x08010000, LENGTH = 960K
+  FLASH (rx)      : ORIGIN = 0x08008000, LENGTH = 992K
   RAM (xrw)       : ORIGIN = 0x20000000, LENGTH = 128K
   MEMORY_B1 (rx)  : ORIGIN = 0x60000000, LENGTH = 0K
   CCMRAM (rw)     : ORIGIN = 0x10000000, LENGTH = 64K

+ 1 - 1
user/main.c

@@ -6,7 +6,7 @@
 #include "hal_conf.h"
 #include "misc.h"
 
-#define APP_FLASH_OFFSET 0x10000
+#define APP_FLASH_OFFSET 0x8000
 #define BOOT_EN          1
 
 int main(void)