Difference between revisions of "DFU Bootloader"
(9 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | [[Category:STM32]][[Category:USB]][[Category:STM32 | + | [[Category:STM32]][[Category:USB]][[Category:STM32 Development]][[Category:Work in progress]] |
All [[STM32]] MCUs have a built-in bootloader which will allow reflashing. The [[Boot0]] pin is used to toggle between "normal" boot and this bootloader. Unfortunately this process can not be controlled without manipulating the [[Boot0]] pin, so if we want to control this from our application, we will have to implement our own bootloader. | All [[STM32]] MCUs have a built-in bootloader which will allow reflashing. The [[Boot0]] pin is used to toggle between "normal" boot and this bootloader. Unfortunately this process can not be controlled without manipulating the [[Boot0]] pin, so if we want to control this from our application, we will have to implement our own bootloader. | ||
== Overall Architecture == | == Overall Architecture == | ||
− | All [[STM32]] [[MCU]]s (indeed all [[ARM]] processors) follows the [https://en.wikipedia.org/wiki/Von_Neumann_architecture Von Neumann] architecture. | + | All [[STM32]] [[MCU]]s (indeed all [[ARM]] processors) follows the [https://en.wikipedia.org/wiki/Von_Neumann_architecture Von Neumann] architecture. This essentially - in this context - means that the instruction and data memory share the same address space. Since [[STM32]] processors are 32-bit processors and since 32-bit addresses can address 4GB (4,294,967,296 bytes), sharing the address space between instruction and data memory is not a problem. |
+ | |||
+ | On [[STM32]]s, programs are stored in on-chip flash memory. Different [[STM32]]s have different amount of flash memory, but common for all is that it is mapped in the address space starting from 0x08000000. | ||
+ | |||
+ | {| class=wikitable | ||
+ | ! | ||
+ | ! | ||
+ | ! Start Addr (incl.) | ||
+ | ! End Addr (not incl.) | ||
+ | ! Size (hex) | ||
+ | ! Size (kb) | ||
+ | |- | ||
+ | | align=right | End | ||
+ | | --> | ||
+ | | align=right | 0x8078000 | ||
+ | | align=right | 0x8080000 | ||
+ | | align=right | 0x8000 | ||
+ | | align=right | 32 kB | ||
+ | |- | ||
+ | | | ||
+ | | | ||
+ | | align=right | 0x8070000 | ||
+ | | align=right | 0x8078000 | ||
+ | | align=right | 0x8000 | ||
+ | | align=right | 32 kB | ||
+ | |- | ||
+ | | | ||
+ | | | ||
+ | | align=right | 0x8068000 | ||
+ | | align=right | 0x8070000 | ||
+ | | align=right | 0x8000 | ||
+ | | align=right | 32 kB | ||
+ | |- | ||
+ | | | ||
+ | | | ||
+ | | align=right | 0x8060000 | ||
+ | | align=right | 0x8068000 | ||
+ | | align=right | 0x8000 | ||
+ | | align=right | 32 kB | ||
+ | |- | ||
+ | | | ||
+ | | | ||
+ | | align=right | 0x8058000 | ||
+ | | align=right | 0x8060000 | ||
+ | | align=right | 0x8000 | ||
+ | | align=right | 32 kB | ||
+ | |- | ||
+ | | | ||
+ | | | ||
+ | | align=right | 0x8050000 | ||
+ | | align=right | 0x8058000 | ||
+ | | align=right | 0x8000 | ||
+ | | align=right | 32 kB | ||
+ | |- | ||
+ | | | ||
+ | | | ||
+ | | align=right | 0x8048000 | ||
+ | | align=right | 0x8050000 | ||
+ | | align=right | 0x8000 | ||
+ | | align=right | 32 kB | ||
+ | |- | ||
+ | | | ||
+ | | | ||
+ | | align=right | 0x8040000 | ||
+ | | align=right | 0x8048000 | ||
+ | | align=right | 0x8000 | ||
+ | | align=right | 32 kB | ||
+ | |- | ||
+ | | | ||
+ | | | ||
+ | | align=right | 0x8038000 | ||
+ | | align=right | 0x8040000 | ||
+ | | align=right | 0x8000 | ||
+ | | align=right | 32 kB | ||
+ | |- | ||
+ | | | ||
+ | | | ||
+ | | align=right | 0x8030000 | ||
+ | | align=right | 0x8038000 | ||
+ | | align=right | 0x8000 | ||
+ | | align=right | 32 kB | ||
+ | |- | ||
+ | | | ||
+ | | | ||
+ | | align=right | 0x8028000 | ||
+ | | align=right | 0x8030000 | ||
+ | | align=right | 0x8000 | ||
+ | | align=right | 32 kB | ||
+ | |- | ||
+ | | | ||
+ | | | ||
+ | | align=right | 0x8020000 | ||
+ | | align=right | 0x8028000 | ||
+ | | align=right | 0x8000 | ||
+ | | align=right | 32 kB | ||
+ | |- | ||
+ | | | ||
+ | | | ||
+ | | align=right | 0x8018000 | ||
+ | | align=right | 0x8020000 | ||
+ | | align=right | 0x8000 | ||
+ | | align=right | 32 kB | ||
+ | |- | ||
+ | | | ||
+ | | | ||
+ | | align=right | 0x8010000 | ||
+ | | align=right | 0x8018000 | ||
+ | | align=right | 0x8000 | ||
+ | | align=right | 32 kB | ||
+ | |- | ||
+ | | | ||
+ | | | ||
+ | | align=right | 0x8008000 | ||
+ | | align=right | 0x8010000 | ||
+ | | align=right | 0x8000 | ||
+ | | align=right | 32 kB | ||
+ | |- | ||
+ | | align=right | Begin | ||
+ | | --> | ||
+ | | align=right | 0x8000000 | ||
+ | | align=right | 0x8008000 | ||
+ | | align=right | 0x8000 | ||
+ | | align=right | 32 kB | ||
+ | |} | ||
+ | |||
+ | Under normal reset ([[Boot0]] not activated), the [[MCU]] will jump to address 0x8000000 and begin execution from there. | ||
{| class=wikitable | {| class=wikitable | ||
! | ! | ||
! | ! | ||
− | ! Start Addr | + | ! Start Addr (incl.) |
− | ! End Addr | + | ! End Addr (not incl.) |
! Size (hex) | ! Size (hex) | ||
! Size (kb) | ! Size (kb) | ||
+ | ! Usage | ||
|- | |- | ||
| align=right | End | | align=right | End | ||
Line 19: | Line 145: | ||
| align=right | 0x8080000 | | align=right | 0x8080000 | ||
| align=right | 0x8000 | | align=right | 0x8000 | ||
− | | align=right | | + | | align=right | 32 kB |
+ | | rowspan=15 | Application (480 kB) | ||
|- | |- | ||
| | | | ||
Line 26: | Line 153: | ||
| align=right | 0x8078000 | | align=right | 0x8078000 | ||
| align=right | 0x8000 | | align=right | 0x8000 | ||
− | | align=right | | + | | align=right | 32 kB |
|- | |- | ||
| | | | ||
Line 33: | Line 160: | ||
| align=right | 0x8070000 | | align=right | 0x8070000 | ||
| align=right | 0x8000 | | align=right | 0x8000 | ||
− | | align=right | | + | | align=right | 32 kB |
|- | |- | ||
| | | | ||
Line 40: | Line 167: | ||
| align=right | 0x8068000 | | align=right | 0x8068000 | ||
| align=right | 0x8000 | | align=right | 0x8000 | ||
− | | align=right | | + | | align=right | 32 kB |
|- | |- | ||
| | | | ||
Line 47: | Line 174: | ||
| align=right | 0x8060000 | | align=right | 0x8060000 | ||
| align=right | 0x8000 | | align=right | 0x8000 | ||
− | | align=right | | + | | align=right | 32 kB |
|- | |- | ||
| | | | ||
Line 54: | Line 181: | ||
| align=right | 0x8058000 | | align=right | 0x8058000 | ||
| align=right | 0x8000 | | align=right | 0x8000 | ||
− | | align=right | | + | | align=right | 32 kB |
|- | |- | ||
| | | | ||
Line 61: | Line 188: | ||
| align=right | 0x8050000 | | align=right | 0x8050000 | ||
| align=right | 0x8000 | | align=right | 0x8000 | ||
− | | align=right | | + | | align=right | 32 kB |
|- | |- | ||
| | | | ||
Line 68: | Line 195: | ||
| align=right | 0x8048000 | | align=right | 0x8048000 | ||
| align=right | 0x8000 | | align=right | 0x8000 | ||
− | | align=right | | + | | align=right | 32 kB |
|- | |- | ||
| | | | ||
Line 75: | Line 202: | ||
| align=right | 0x8040000 | | align=right | 0x8040000 | ||
| align=right | 0x8000 | | align=right | 0x8000 | ||
− | | align=right | | + | | align=right | 32 kB |
|- | |- | ||
| | | | ||
Line 82: | Line 209: | ||
| align=right | 0x8038000 | | align=right | 0x8038000 | ||
| align=right | 0x8000 | | align=right | 0x8000 | ||
− | | align=right | | + | | align=right | 32 kB |
|- | |- | ||
| | | | ||
Line 89: | Line 216: | ||
| align=right | 0x8030000 | | align=right | 0x8030000 | ||
| align=right | 0x8000 | | align=right | 0x8000 | ||
− | | align=right | | + | | align=right | 32 kB |
|- | |- | ||
| | | | ||
Line 96: | Line 223: | ||
| align=right | 0x8028000 | | align=right | 0x8028000 | ||
| align=right | 0x8000 | | align=right | 0x8000 | ||
− | | align=right | | + | | align=right | 32 kB |
|- | |- | ||
| | | | ||
Line 103: | Line 230: | ||
| align=right | 0x8020000 | | align=right | 0x8020000 | ||
| align=right | 0x8000 | | align=right | 0x8000 | ||
− | | align=right | | + | | align=right | 32 kB |
|- | |- | ||
| | | | ||
Line 110: | Line 237: | ||
| align=right | 0x8018000 | | align=right | 0x8018000 | ||
| align=right | 0x8000 | | align=right | 0x8000 | ||
− | | align=right | | + | | align=right | 32 kB |
|- | |- | ||
| | | | ||
Line 117: | Line 244: | ||
| align=right | 0x8010000 | | align=right | 0x8010000 | ||
| align=right | 0x8000 | | align=right | 0x8000 | ||
− | | align=right | | + | | align=right | 32 kB |
|- | |- | ||
| align=right | Begin | | align=right | Begin | ||
Line 124: | Line 251: | ||
| align=right | 0x8008000 | | align=right | 0x8008000 | ||
| align=right | 0x8000 | | align=right | 0x8000 | ||
− | | align=right | | + | | align=right | 32 kB |
+ | | Bootloader (32 kB) | ||
|} | |} | ||
Latest revision as of 03:52, 10 July 2021
All STM32 MCUs have a built-in bootloader which will allow reflashing. The Boot0 pin is used to toggle between "normal" boot and this bootloader. Unfortunately this process can not be controlled without manipulating the Boot0 pin, so if we want to control this from our application, we will have to implement our own bootloader.
Overall Architecture
All STM32 MCUs (indeed all ARM processors) follows the Von Neumann architecture. This essentially - in this context - means that the instruction and data memory share the same address space. Since STM32 processors are 32-bit processors and since 32-bit addresses can address 4GB (4,294,967,296 bytes), sharing the address space between instruction and data memory is not a problem.
On STM32s, programs are stored in on-chip flash memory. Different STM32s have different amount of flash memory, but common for all is that it is mapped in the address space starting from 0x08000000.
Start Addr (incl.) | End Addr (not incl.) | Size (hex) | Size (kb) | ||
---|---|---|---|---|---|
End | --> | 0x8078000 | 0x8080000 | 0x8000 | 32 kB |
0x8070000 | 0x8078000 | 0x8000 | 32 kB | ||
0x8068000 | 0x8070000 | 0x8000 | 32 kB | ||
0x8060000 | 0x8068000 | 0x8000 | 32 kB | ||
0x8058000 | 0x8060000 | 0x8000 | 32 kB | ||
0x8050000 | 0x8058000 | 0x8000 | 32 kB | ||
0x8048000 | 0x8050000 | 0x8000 | 32 kB | ||
0x8040000 | 0x8048000 | 0x8000 | 32 kB | ||
0x8038000 | 0x8040000 | 0x8000 | 32 kB | ||
0x8030000 | 0x8038000 | 0x8000 | 32 kB | ||
0x8028000 | 0x8030000 | 0x8000 | 32 kB | ||
0x8020000 | 0x8028000 | 0x8000 | 32 kB | ||
0x8018000 | 0x8020000 | 0x8000 | 32 kB | ||
0x8010000 | 0x8018000 | 0x8000 | 32 kB | ||
0x8008000 | 0x8010000 | 0x8000 | 32 kB | ||
Begin | --> | 0x8000000 | 0x8008000 | 0x8000 | 32 kB |
Under normal reset (Boot0 not activated), the MCU will jump to address 0x8000000 and begin execution from there.
Start Addr (incl.) | End Addr (not incl.) | Size (hex) | Size (kb) | Usage | ||
---|---|---|---|---|---|---|
End | --> | 0x8078000 | 0x8080000 | 0x8000 | 32 kB | Application (480 kB) |
0x8070000 | 0x8078000 | 0x8000 | 32 kB | |||
0x8068000 | 0x8070000 | 0x8000 | 32 kB | |||
0x8060000 | 0x8068000 | 0x8000 | 32 kB | |||
0x8058000 | 0x8060000 | 0x8000 | 32 kB | |||
0x8050000 | 0x8058000 | 0x8000 | 32 kB | |||
0x8048000 | 0x8050000 | 0x8000 | 32 kB | |||
0x8040000 | 0x8048000 | 0x8000 | 32 kB | |||
0x8038000 | 0x8040000 | 0x8000 | 32 kB | |||
0x8030000 | 0x8038000 | 0x8000 | 32 kB | |||
0x8028000 | 0x8030000 | 0x8000 | 32 kB | |||
0x8020000 | 0x8028000 | 0x8000 | 32 kB | |||
0x8018000 | 0x8020000 | 0x8000 | 32 kB | |||
0x8010000 | 0x8018000 | 0x8000 | 32 kB | |||
0x8008000 | 0x8010000 | 0x8000 | 32 kB | |||
Begin | --> | 0x8000000 | 0x8008000 | 0x8000 | 32 kB | Bootloader (32 kB) |