Stm32 bootloader and app authoring considerations
1, how to allocate bootloader and app space
2. How to get data and write Flash
3. How to jump from bootloader to app
4, how to set the app interrupt vector
5. How to generate Bin file in app
6. Process of program execution
1, how to allocate bootloader and app space
Because I'm using STM32F103C8T6, it's flash size is 64k, so divide it up as shown above
0x08000000---0x0800 33FF is assigned to bootloader, the size is 13k
0x0800 3400----0X080097FF assigned to the first app, size 25k
0x08009800----0x0800 FBFF assigned to the second app, size 25k
0X0800FC00----0x0800 FFFF assigned to User_flag and other flags, size 1k
Setting the size of the ROM in Keil
A, the setting of ROM size in bootloader
B. setting of ROM size in APP1
C, APP2 setting of ROM size
The ROM is set up so you can see the change of address in the map, taking bootloader and App1.
Map of Bootloader
Map of App1
Here we can see that reset's address has changed.
But if we change the ROM in map also change Keil inside must be set like,
This must be checked, the default new project is not selected
2. How to get data and write Flash
In my program is to receive data through the serial port, and then call App_bin_handler (&timer), function to complete the Write Flash (function Iap_write_appbin (flash_current_write_addr (), g_ Rxbuf1,length), and verify that the data written is correct (function flag =READ_FLASH_ECC (FLASH_CURRENT_WRITE_ADDR (), length), The verification pass can jump to the app (function Jumptoapp (FLASH_CURRENT_WRITE_ADDR (), 1);)
3. How to jump from bootloader to app
Voidjumptoapp (u32 applicationaddress,u8 flag)
{
U32 temp;
if (((* (vu32*) applicationaddress) &0x2ffe0000) = = 0x20000000)
{
if (flag = = 1)
{
User_write_flash_falg ();
}
temp = (* (vu32*) (applicationaddress + 4));
Jumptoapplication = (funvoidtype) temp;
Msr_msp (* (vu32*) applicationaddress);
Jumptoapplication ();
}
}
The program is to use the above function to implement the jump, the middle of a user_write_flash_falg () function is used to set the logo of the app, if the current is using APP1, then set the flag bit is 2, fortunately, the next time you start to jump to App2, If you are currently using APP2, then set the flag bit to 1, the next time you start to jump to App1
As for the above function of the detailed can Baidu.
4 , How to set the app interrupt vector
Stm32 interrupt redirection is simpler because it has a dedicated register
Nvic_setvectortable (nvic_vecttab_flash,0x9800);
This function is to redirect the interrupt vector of the APP2, which is simple to implement.
6. How to generate Bin file in app
Because my program is to download the app through the serial port, it is necessary to generate a bin file, to facilitate the download,
You can create a bin file with the following settings in the project
The main is the path to the right, or can not find the. axf file, you won't be able to generate a bin file
Summarize:
Bootloader inside is mainly
1. Set bootloader and app space
2, receive the compiled app bin file, write Flash
3. Achieve jump
The main areas of change in the app are
1. Rom start address and allocated space size
2. REDIRECT Interrupt vector
3. Generate Bin File
This is the process of executing the entire program.
How to use Stm32 to write IAP bootloader and apps