further explanation and description for the customized bootloader
- REMAP
principle for remap mode interrupt vectors |
- for detail information about the standard customized bootloader, go to read AN2659
- the first 128 bytes (
0x8000-0x8080
) contains 32 fix interrupt vectors - the first interrupt vector (
0x8000-0x8003
) is for the hardware reset interrupt and it should be kept unchanged - the last 31 interrupt vectors (
0x8004-0x8080
) should be redirected to0x8284-0x82ff
, the value for0x8004-0x8080
is calculated by0x8200 << 16 & (0x8280 + n*4), n=1,2,...,31
- in file
lnkstm8l103k3.icf
, changedefine region NearFunCode = [from 0x8280 to 0x9FFF]
, compile and get the app bin - memcyp the app bin including the interrupt vector table and the code to the flash from the address
0x8280
, the code actually starts from0x8300
- when bootloader finished, the program will jump to the app
JP $8280
- OVERLAP
principle for overlap mode interrupt vectors |
- the first 128 bytes (
0x8000-0x8080
) contains 32 fix interrupt vectors - the first interrupt vector (
0x8000-0x8003
) is for the hardware reset interrupt and it should be kept unchanged - the last 31 interrupt vectors (
0x8004-0x8080
) should be changed according to the app's 1-31th interrupt vectors - store the reset interrupt vector for app at the end of the user-bootloader
0x827c-0x827f
- in file
lnkstm8l103k3.icf
, changedefine region NearFunCode = [from 0x8200 to 0x9FFF]
, compile and get the app bin - just memcyp the app bin code except the interrupt vector table to the flash from the address
0x8280
- when bootloader finished, the program will jump to the app
JP $827c
- comparison between
REMAP
&OVERLAP
REMAP
mode is the standard mode provide by the official manual reference AN2659, so it is easy to understand and realize- in
REMAP
mode, the content for the bootloader including both theinterrupt vectors
anduser-bootloader code
is constant, so you can define this area asUBC
and design protection mechanism to prevent write operation duringIAP
; while inOVERLAP
mode, as the last 31 interrupt vectors vary as the app code, it can not easily be protected - compared to
OVERLAP
mode, you will waste124
bytes storing the redirecting addresses, which is fatal when theflash resource
is very limited - compared to
OVERLAP
mode, you will waste at least aCPU cycle
when handling the interrupt service. When an interrupt happens, the PC first jump to the fix interrupt vector, then jump to the redirected address, and then jump to the entry of the ISR, which is fatal when the interrupt service is verytime limited
.
-
when flashing the program, you can use
byte programming
,fast byte programming
,word programming
,fast word programming
,block programming
andfast block programming
.
thetime consumption
forbyte programming
andblock programming
scales greatly. For a binary file whose size is about 6K bytes, you may need minutes to finish programming usingbyte programming
, at the meantime, 2-3 seconds usingblock programming
When usingblock programming
, you should map the code into the RAM, for example:IN_RAM(void FLASH_ProgBlock(uint16_t StartAddress, uint8_t *Buffer));
for further information about the programming guide, refer to AN2659, PM0047, UM0560 and SWIM
-
you should pay attention to the size of the bootloader.bin, in this example, we reserve 640bytes for bootloader. If you use more complicated algorithms such as
transfer verification
,flash verification
orCRC verification
, the size of the bootloader.bin will increase.
When the space revered for the bootloader is not enough, fatal error will happen.
-
In the
OVERLAP
mode, the space address storing the app reset interrupt can be changed?Absolutely yes!
Actually, when the bootloader ends, it will jump to the space address storing the app reset interrupt vector which stores the entry for main function. You can even just fetch the entry for main function, and put it into thejump space address
, this will save a jump cycle.
In this example, we just choose thejump space address
at the end of theuser-bootloader
0x807c
. You can choose wherever you want just to avoid the occupation. -
Can the interrupt enabled during the bootloader?
Generally not!
But if you change the bootloader a little, it can!
The reason why we should not enable interrupt during the bootloader is that we have damaged the interrupt vector, both inREMAP
orOVERLAP
mode after we rewrite the interrupt vector table.
InREMAP
mode, if you enable specified interrupt during bootloader, you can make a branch like this:if(booting){ "excute the ISR for booting" }else{ "jump to the specified redirected address for app" }
booting
is a global boolen variable indicating that whether the process now is inboot
orapp