当前位置:网站首页>Code implementation of jump between IAP bootload and app
Code implementation of jump between IAP bootload and app
2022-07-18 05:16:00 【Summer night breeze_】
IAP The contents of the remote update series are as follows :
1. IAP Description of remote update mechanism
2. Bootload and App Code implementation of inter jump
3. STM32 Inside Flash Operation function of
List of articles
1. Bootload Jump to App
jump_to_app.c
#include "stm32f10x.h"
#include "jump_to_app.h"
/* work can : Turn off global interrupt */
void BoardDisableIrq(void)
{
__disable_interrupt();
}
/* work can : Enable global interrupt */
void BoardEnableIrq(void)
{
__enable_interrupt();
}
/* Initialize stack pointer */
void MSR_MSP(uint32_t addr)
{
__ASM("msr msp, r0"); // set Main Stack value Save the main stack address to MSP register (R13) in
__ASM("bx lr"); // Jump to lr At the address stored in .bx Is a forced jump instruction lr Is the connection register , yes STM32 Single chip microcomputer R14
}
typedef void (*IapFun)(void); // Declare a function pointer , Used to jump to the absolute address to execute the program
IapFun JumpToApp;
/*! * work can : Jump to application * param1: User code start address * retval: No return value */
void IapLoadApp(uint32_t AppAddr)
{
/* Applications APP Middle set handle Interrupt vector table Put in 0x08003000 Starting position ; The first place in the interrupt vector table is the value of the stack top address in other words , This sentence is to judge whether the address value at the top of the stack is correct ( Whether in 0x2000 0000 - 0x 2000 2000 Between ) To determine whether the application It has been downloaded , Because the startup file of the application just begins to initialize the stack space , If the stack top value is right , Say that the application has downloaded the startup file , Initialization is also performed ; */
if( ((*(uint32_t*)AppAddr) & 0x2FFE0000) == 0x20000000 )// Check if the top of stack address is legal , Check the memory section of the reference manual SRAM Section
{
BoardDisableIrq(); // No interruptions
JumpToApp = (IapFun)*(uint32_t*)(AppAddr+4); // The second word in the user code area is the program start address ( New program reset address )
MSR_MSP(*(uint32_t*)AppAddr); // initialization APP Stack pointer ( The first word in the user code area is used to store the top address of the stack )
JumpToApp(); // Set up PC Pointer for bootload Reset the address of the interrupt function , To perform the
}
}
2. App Jump to Bootload
jumo_to_bootload.c
#include "stm32f10x.h"
#include "jump_to_boot.h"
#define INFLASH_ADDR_BOOTLOAD ((uint32_t)0x08000000) // bootload From
/* Initialize stack pointer */
void MSR_MSP(uint32_t addr)
{
__ASM("msr msp, r0"); // set Main Stack value Save the main stack address to MSP register (R13) in
__ASM("bx lr"); // Jump to lr At the address stored in .bx Is a forced jump instruction lr Is the connection register , yes STM32 Single chip microcomputer R14
}
typedef void (*IapFun)(void); // Declare a function pointer , Used to jump to the absolute address to execute the program
IapFun JumpToBootload;
/*! * work can : Jump to application * param1: User code start address * retval: No return value */
void IapLoadBootload(void)
{
/* Applications APP Middle set handle Interrupt vector table Put in 0x08003000 Starting position ; The first place in the interrupt vector table is the value of the stack top address in other words , This sentence is to judge whether the address value at the top of the stack is correct ( Whether in 0x2000 0000 - 0x 2000 2000 Between ) To determine whether the application It has been downloaded , Because the startup file of the application just begins to initialize the stack space , If the stack top value is right , Say that the application has downloaded the startup file , Initialization is also performed ; */
if( ((*(uint32_t*)INFLASH_ADDR_BOOTLOAD) & 0x2FFE0000) == 0x20000000 )// Check if the top of stack address is legal , Check the memory section of the reference manual SRAM Section
{
BoardDisableIrq(); // No interruptions
JumpToBootload = (IapFun)*(uint32_t*)(INFLASH_ADDR_BOOTLOAD+4); // The second word in the user code area is the program start address ( New program reset address )
MSR_MSP(*(uint32_t*)INFLASH_ADDR_BOOTLOAD); // initialization APP Stack pointer ( The first word in the user code area is used to store the top address of the stack )
JumpToBootload(); // Set up PC Pointer for bootload Reset the address of the interrupt function , To perform the
}
}
3. App Set the offset of interrupt vector table in
stay APP In the program ,main The function should first modify the starting address of the interrupt vector table , It can be modified by VTOR Vector table offset register to relocate vector table . Reference resources 《Cortex-M3 Authoritative guide 》7.3 Section “ The starting address of the vector table is required : We must first find out how many vectors there are in the system , Then put this number up “ Roundness ” To 2 The whole power of , The starting address must be aligned to the boundary of the latter . for example , If there is 32 A break , Then there is 32+16( System exception )=48 Vector , Round up to 2 The value after the entire power of is 64, Therefore, the address of vector table relocation must be able to be 64*4=256 to be divisible by , Thus, the legal starting address can be :0x0, 0x100, 0x200 etc. ”
STM32F103 Series have 59 A break +16 A system exception , altogether 65 Vector , Round up to 2 The value after the entire power of is 128, The legal address is 0x0, 0x400, 0x800 … stay main Function can set the value of the register to reposition the vector table , The specific implementation is as follows , among FLASH_VTOR_OFFSET Need to be based on your own APP Modify the starting address of .
#define INFLASH_START_ADDR ((uint32_t)0x08000000) // STM32 Inside FLASH From
#define INFLASH_VTOR_OFFSET ((uint32_t)0x00004000) // APP Offset address of vector table , And APP The starting address of is consistent
int main()
{
SCB->VTOR = INFLASH_START_ADDR | INFLASH_VTOR_OFFSET; // Set the starting address of the vector table
/* Other code */
}
边栏推荐
- 动态规划 | 最长公共子序列
- Redis04: three special data types of redis
- STM32 IAP远程更新
- Salesforce email sent to spam mailbox or SF email processing method not received (dkim - New CNAME version)
- Redis03:Redis的5大常用数据类型
- Matlab_ Figure is displayed on the top during debugging
- 由四种颜色组成的环,填到五个段组成的一个环上,使得各个环与相邻的颜色并不相同的组合能有多少种(全量)。
- 象棋一本通
- Salesforce中實施Campaign Influence模型注意事項
- Information system project managers must recite the core examination sites (10) information system planning
猜你喜欢

Super Ping tool

Niuke 2021 summer training 3-e-math

Uni app request to get data

Niuke 2021 summer training 4-j-average

Core examination sites for information system project managers (VI) layering of OSI protocol, mapping + real questions

hbuilder提交代码

12306 ticket grabbing tools shock and attack

电商平台后台管理系统--->操作方法说明

uni-app 表单提交按钮发送请求

Cool dog music interface is amazingly open
随机推荐
由四种颜色组成的环,填到五个段组成的一个环上,使得各个环与相邻的颜色并不相同的组合能有多少种(全量)。
How to create threads
点灯
What every Salesforce developer should know about Dates and Times in Apex
C leetcode brush notes 1- maximum number of words in sentences
volatile低配版syn,实现可见性和有序性
Information system project manager core examination site (IX) organizational structure type
Redis01: introduction to NoSQL and redis
零基础学lua第十五天---最后归纳下
蚂蚁隐私计算创新TEE技术获学术认可
Considérations relatives à la mise en œuvre du modèle d'influence de la campagne dans Salesforce
STM32 IO口模式介绍
Redis05: redis transactions
Virtual box mount shared folders
STM32 IAP远程更新
Niuke 2021 summer training 8-f-robots
理财平台哪个最安全收益怎么样
超强ping工具
[kekeguo information management] writing requirements of information management paper - abstract
@tap是什么