• Keil实现Flash升级跳转(STM32/GD32/HC32)


    编写BOOT程序,和APP程序。
    BOOT程序检查OTA参数,执行OTA升级,然后跳转到APP代码。

    记录一下跳转APP需要修改得东西:

    1、BOOT程序 修改跳转地址

    先检查APP地址是否有效
    然后关闭外设 反初始化
    设置MSP指针,进行跳转

    /**
     * @brief  Jump from boot to app function.
     * @param  [in] u32Addr                 APP address
     * @retval LL_ERR                       APP address error
     */
    int32_t IAP_JumpToApp(uint32_t u32Addr)
    {
        uint32_t u32StackTop = *((__IO uint32_t *)u32Addr);
    	uint32_t JumpAddr;
    	func_ptr_t JumpToApp;
    	
        /* Check stack top pointer. */
        if ((u32StackTop > SRAM_BASE) && (u32StackTop <= (SRAM_BASE + 0x010000UL))) {
            IAP_PeriphDeinit();
            /* Jump to user application */
            JumpAddr = *(__IO uint32_t *)(u32Addr + 4U);
            JumpToApp = (func_ptr_t)JumpAddr;
            /* Initialize user application's Stack Pointer */
            __set_MSP(u32StackTop);
            JumpToApp();
        }
    
        return LL_ERR;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24

    2、APP程序修改起始地址

    修改VECT_TAB_OFFSET定义值 与BOOT对应

    /**
     * @brief  Setup the microcontroller system. Initialize the System and update
     *         the SystemCoreClock variable.
     * @param  None
     * @retval None
     */
    void SystemInit(void)
    {
        /* FPU settings */
    #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
        SCB->CPACR |= ((3UL << 20) | (3UL << 22)); /* set CP10 and CP11 Full Access */
    #endif
        SystemCoreClockUpdate();
    #if defined (ROM_EXT_QSPI)
        SystemInit_QspiMem();
    #endif /* ROM_EXT_QSPI */
        /* Configure the Vector Table relocation */
        SCB->VTOR = VECT_TAB_OFFSET;    /* Vector Table Relocation */
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

    3、APP程序修改内存加载文件

    如下图,如果不勾选该项,则要手动修改ACT文件的LR_IROM1区的起始地址和结束地址
    如果勾选,则要在target选项中设置起始地址和结束地址
    KEIL内存加载配置
    在这里插入图片描述

    ACT文件一般格式:

    ; ****************************************************************
    ; Scatter-Loading Description File
    ; ****************************************************************
    LR_IROM1 0x00004000 0x00040000  {    ; load region size_region
        ER_IROM1 0x00004000 0x00040000  {  ; load address = execution address
            *.o (RESET, +First)
            *(InRoot$$Sections)
            .ANY (+RO)
            .ANY (+XO)
        }
        RW_IRAM1 0x1FFF8000 UNINIT 0x00000008  {  ; RW data
            *(.bss.noinit)
        }
        RW_IRAM2 0x1FFF8008 0x0000FFF8  {  ; RW data
            .ANY (+RW +ZI)
            .ANY (RAMCODE)
        }
        RW_IRAMB 0x200F0000 0x00001000  {  ; RW data
            .ANY (+RW +ZI)
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
  • 相关阅读:
    Dubbo和SpringCloud对比
    Hdfs存储策略
    怎么在树莓派上搭建web网站,并发布到外网可访问?
    滴滴9.17笔试题复盘(差分数组和前缀和数组)
    SpringCloud搭建微服务之Config配置中心
    CASIO FX-4800P圆曲线及缓和曲线上任意点切线方位角计算程序
    picoctf_2018_buffer overflow 2
    Triples of Cows
    网络安全:六种常见的网络攻击手段
    ONLYOFFICE8.1版本桌面编辑器测评
  • 原文地址:https://blog.csdn.net/weixin_38743772/article/details/133929364