当前位置:网站首页>Write bootloader from 0
Write bootloader from 0
2022-07-27 20:45:00 【Work hard and you can go to heaven!】
So-called bootloader Boot loader , Be similar to windows Inside BIOS, It is used for loading some environments and necessary initialization before the program runs .
And the single chip microcomputer bootloader Mainly for OTA Upgraded , The function is to initialize the necessary running environment , Determine whether to upgrade , If you want to upgrade , Then copy the downloaded upgrade program to the operation of the MCU flash in , Then jump to APP Program running address , If you don't upgrade, jump directly to APP Program running address .
bootloader Implementation function diagram 
Is to achieve a jump .
Realization bootloaer And running the program requires two documents :
1.bootloader Program engineering 
1. Set up bootloader Program start position of , Such as 1 Shown , Generally not changed .
2. Set up bootloader The size of the program , As shown in Figure 2 , Generally, it is more practical to use bootloaer The program needs a little more space .
2.APP Program settings 
Same as bootloader The same meaning , however APP The running address needs to be set by you cheaply bootloader The address size of , stay 2 You also need to reduce your settings bootlader Program size of 
You can also change the starting position of the program here , But it is not recommended to change here , Just use the default here .
notes :SP The stack pointer does not need to be changed , Because bootloader and APP Only one program is running at the same time , So only one program is using the stack .
APP Program
1. No exception vector table is required 
You don't need the exception vector table to jump to APP The program start address can be executed .
2. Need exception vector table 
When the program jumps , If you directly use the address as a pointer , Pay attention to ,Thumb Instruction sets and ARM The difference between instruction sets .
typedef void(*IapAppFun)(void); // Define a function pointer , Used to jump to APP Program
#define FLASH_APP_ADDR 0x08010000 // Definition APP Program start address
void main
{
IapAppFun JumpApp;
// bootloader Some column initialization to be done
if (((*(__IO uint32_t *)FLASH_APP_ADDR) & 0xFF000000) == 0x08000000)
{
__disable_irq();// Turn off interrupt
JumpApp = (IapAppFun)*(__IO uint32_t *)(FLASH_APP_ADDR +4);
SCB->VTOR = FLASH_BASE|0x10000; // Inside the chip FLASH The starting address plus the offset address will be equal to APP The starting address of the program
JumpApp();
}
printf("APP is invalid!\r\n");// If the execution reaches here, it means that the jump fails
}
if (((*(__IO uint32_t )FLASH_APP_ADDR) & 0xFF000000) == 0x08000000)
The purpose of this sentence is to judge FLASH_APP_ADDR The value stored in this address is used to jump to flash OK operation SRAM Or other places , If M3 As an example , So if it is SRAM The operation should be changed to
if ((((__IO uint32_t *)FLASH_APP_ADDR) & 0x2FF80000) == 0x20000000) From SRAM Began to run
This depends on where the upgrade program you write wants to start .
JumpApp = (IapAppFun)*(__IO uint32_t *)(FLASH_APP_ADDR +4);
The purpose of this sentence is because ,FLASH_APP_ADDR The address of the exception vector table is stored on , Add 4 The following address means that the program start address is stored inside , So we need to use dereference plus its value to get it and give it to the function pointer , Used to jump execution APP Program .
SCB->VTOR = FLASH_BASE|0x10000;
The purpose of this sentence is to change APP Program exception vector table , because APP The program is relative to 0x08000000 Has shifted 0x10000, So the first address after the offset stores the exception vector table .
The above is purely personal opinion , I hope you can correct the mistakes .
边栏推荐
- Software test interview question: if a string is known as "hello_world_yoyo", how to get a queue ["hello", "world", "yoyo"]
- 【程序人生】“阶段总结“-不甘平凡
- One week activity express | in simple terms, issue 8; Meetup Chengdu station registration in progress
- A new UI testing method: visual perception test
- OA项目之我的审批(查询&会议签字)
- Clickhouse implements materializedpostgresql
- IE11 下载doc pdf等文件的方法
- 2022-07-19 网工进阶(二十)BGP-路由优选、路由优选逐条分析
- access control
- Innovative cases | the growth strategy of digitalization of local life services and upgrading of Gaode brand
猜你喜欢

My approval of OA project (Query & meeting signature)

2022.07.11
![[design tutorial] yolov7 target detection network interpretation](/img/dc/a795dcbd1163df6d8f33704a129d30.png)
[design tutorial] yolov7 target detection network interpretation

Graphic leetcode - Sword finger offer II 115. reconstruction sequence (difficulty: medium)
![(manual) [sqli labs38, 39] stack injection, error echo, character / number type](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
(manual) [sqli labs38, 39] stack injection, error echo, character / number type

A new UI testing method: visual perception test

Nailing development document

Pyqt5 rapid development and practice 4.3 qlabel and 4.4 text box controls

Some contents related to cmsis-rtos

I'm also drunk. Eureka delayed registration and this pit
随机推荐
Konka semiconductor's first storage master chip was mass produced and shipped, with the first batch of 100000 chips
It is said that Intel will stop the nervana chip manufactured by TSMC at 16nm
【程序人生】“阶段总结“-不甘平凡
Redis hash structure command
One week activity express | in simple terms, issue 8; Meetup Chengdu station registration in progress
Standing on the shoulders of giants to learn, jd.com's popular architect growth manual was launched
Pytorch multiplication and broadcasting mechanism
做测试, 就得去大厂,内部披露BAT大厂招聘“潜规则”
MySQL log query log
My approval of OA project (Query & meeting signature)
CONDA common commands
Conversion of Oracle date
Oracle Xe installation and user operation
十年测试老鸟聊聊移动端兼容性测试
Software test interview question: given a queue, such as: [1, 3, 5, 7], how to put the first number into the third position to get: [3, 5, 1, 7]
Linked list~~~
Some contents related to cmsis-rtos
MySQL 日志错误日志
Illustration leetcode - 592. Fraction addition and subtraction (difficulty: medium)
[Alibaba security × ICDM 2022] 200000 bonus pool! The risk commodity inspection competition on the large-scale e-commerce map is in hot registration