You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+22-16Lines changed: 22 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,21 +19,25 @@ Customizable Bootloader for STM32 microcontrollers. This example demonstrates ho
19
19
- Easy to customize and port to other microcontrollers
20
20
21
21
## Description
22
-
This demo is implemented on a custom hardware [see FIGURE]equipped with a STM32L476VG microcontroller [[1, 2]](#references). The microSD card is connected to the MCU over SDIO interface. The example software uses the official HAL library of ST [[3]](#references) and is compiled with IAR EWARM. Programming and debugging is performed over SWD with a SEGGER J-Link debug probe.
22
+
This demo is implemented on a custom hardware (see Figure 1) equipped with a STM32L476VG microcontroller [[1, 2]](#references). The microSD card is connected to the MCU over SDIO interface. The implementation uses the official HAL library of ST [[3]](#references) and is compiled with IAR EWARM. Programming and debugging is performed over SWD with a SEGGER J-Link debug probe.
23
23
24
-
[FIGURE: system]
24
+

25
+
26
+
*Figure 1: System overview*
25
27
26
28
The microcontroller flash is organized as follows: by default the first 32kBytes (16 pages) of the flash is reserved for the bootloader and the rest of the flash is the application space.
27
29
28
-
[FIGURE: flash organization]
30
+

31
+
32
+
*Figure 2: Flash organization*
29
33
30
34
After power-up, the bootloader starts. All three LEDs are flashed for a second, then the bootloader checks for user-interaction:
31
35
32
-
- If the button is not pressed, then the bootloader tries to launch the application: First it checks the application space. If there is an application, the bootloader calculates the checksum over the application space and compares with the application checksum (if the checksum feature is enabled). Finally, the bootloader prepares for the jump by resetting the peripherals, disabling the SysTick, setting the vector table and stack pointer, then the bootloader performs a jump to the application.
36
+
- If the button is not pressed, then the bootloader tries to launch the application: First it checks the application space. If there is a firmware located in the application space, the bootloader calculates the checksum over the application space and compares with the application checksum (if the checksum feature is enabled). Finally, the bootloader prepares for the jump by resetting the peripherals, disabling the SysTick, setting the vector table and stack pointer, then the bootloader performs a jump to the application.
33
37
34
-
- If the button is pressed and released within 4 seconds: the bootloader tries to update the application by performing the following sequence:
38
+
- If the button is pressed and released within 4 seconds: the bootloader tries to update the application firmware by performing the following sequence:
35
39
36
-
1. Checks for write-protection. If the application space is write-protected, then the red LED is switched on and the yellow LED is flashed for five seconds. If the button is pressed within this interval, the bootloader disables the write protection and performs a system reset (required after flash option bytes programming). Please note that after disabling the write protection, the user has to invoke the application update procedure again by pressing the button in order to continue the update.
40
+
1. Checks for writeprotection. If the application space is write-protected, then the red LED is switched on and the yellow LED is flashed for five seconds. If the button is pressed within this interval, the bootloader disables the write protection by re-programming the flash option bytes and performs a system reset (required after flash option bytes programming). Please note that after disabling the write protection, the user has to invoke the application update procedure again by pressing the button in order to continue the firmware update.
37
41
2. Initializes SD card, looks for application binary and opens the file.
38
42
3. Checks the file size whether it fits the application space in the microcontroller flash.
39
43
4. Initializes microcontroller flash.
@@ -42,28 +46,30 @@ After power-up, the bootloader starts. All three LEDs are flashed for a second,
42
46
7. Enables write protection of application space if this feature is enabled in the configuration.
43
47
8. After successful in-application-programming, the bootloader launches the application.
44
48
45
-
- If the button is pressed for more than 4 seconds: the bootloader launches ST's built-in bootloader located in the internal boot ROM (system memory) of the chip. For more information, please refer to [[4]](#references). With this method, the bootloader can be updated or even a full chip re-programming can be performed easily, for instance by connecting the hardware to the computer via USB and using the DFU mode [[5, 6]](#references).
49
+
- If the button is pressed for more than 4 seconds: the bootloader launches ST's built-in bootloader located in the internal boot ROM (system memory) of the chip. For more information, please refer to [[4]](#references). With this method, the bootloader can be updated or even a full chip re-programming can be performed easily, for instance by connecting the hardware to the computer via USB and using DFU mode [[5, 6]](#references).
50
+
51
+

46
52
47
-
[FIGURE: sequence]
53
+
*Figure 3: Bootloader sequence*
48
54
49
55
## Source code organization
50
56
```
51
-
stm32-dma-uart/
57
+
stm32-bootloader/
52
58
|—— Drivers/
53
59
|—— EWARM/
54
60
|—— Inc/
55
61
|—— Middlewares/
56
62
`—— Src/
57
63
```
58
-
`Drivers` and `Middlewares` folders contain the CMSIS, HAL and FatFs libraries for the microcontroller. The source code and corresponding header files can be found in `Src` and `Inc` folders respectively.
64
+
`Drivers` and `Middlewares` folders contain the CMSIS, HAL and FatFs libraries for the microcontroller. The bootloader source code and corresponding header files can be found in `Src` and `Inc` folders respectively.
59
65
60
66
## How to use
61
-
The bootloader can be easily customized and tailored to the required hardware and environment, i.e. to perform application updates over various interfaces and even to implement over-the-air (OTA) updates. In order to perform successful in-application-programming, the following sequence has to be kept:
62
-
1. Check for write protection and disable it if necessary.
67
+
The bootloader can be easily customized and tailored to the required hardware and environment, i.e. to perform firmware updates over various interfaces or even to implement over-the-air (OTA) updates if the hardware incorporates wireless communication modules. In order to perform successful in-application-programming, the following sequence has to be kept:
68
+
1. Check for flash write protection and disable it if necessary.
63
69
2. Initialize flash with `Bootloader_Init()`.
64
70
3. Erase application space with `Bootloader_Erase()` (optional, but recommended).
65
-
4. Prepare for programming with`Bootloader_FlashBegin()`.
66
-
5. Perform programming by repeatedly calling the `Bootloader_FlashNext(uint64_t data)` function. The flashing procedure requires 8 bytes of data (double word) to be programmed at once into the flash. This function automatically increases the address where the data is being written.
71
+
4. Prepare for programming by calling`Bootloader_FlashBegin()`.
72
+
5. Perform programming by repeatedly calling the `Bootloader_FlashNext(uint64_t data)` function. The programming procedure requires 8 bytes of data (double word) to be programmed at once into the flash. This function automatically increases the address where the data is being written.
67
73
6. Finalize programming by calling `Bootloader_FlashEnd()`.
68
74
69
75
The application image has to be in binary format. If the checksum verification is enabled, the binary must include the checksum value at the end of the image. When creating the application image, the checksum has to be calculated over the entire image (except the checksum area) with the following parameters:
@@ -72,10 +78,10 @@ The application image has to be in binary format. If the checksum verification i
72
78
- Initial value: 0xFFFFFFFF
73
79
- Bit order: MSB first
74
80
75
-
__Important notice__: in order to perform a successful application jump from the bootloader, the vector table of the application should be relocated. By default, the startup code of the microcontroller sets the vector table location to 0x00000000 in the `system_stm32xxxx.c` file. This has to be either disabled (the bootloader can be configured to perform the vector table relocation before the jump) or manually set to the appropriate value which is the start address of the application space.
81
+
__Important notice__: in order to perform a successful application jump from the bootloader, the vector table of the application firmware should be relocated. When creating an application, the microcontroller startup code sets the vector table location to 0x00000000 in the `system_stm32xxxx.c` file by default. This has to be either disabled (the bootloader can be configured to perform the vector table relocation before the jump) or manually set to the appropriate value which is the start address of the application space.
76
82
77
83
## Configuration
78
-
The bootloader can be widely configured in the `bootloader.h` file. The file includes detailed descriptions and comments for the configurable parameters and definitions.
84
+
The bootloader can be widely configured in the `bootloader.h` file. The file includes detailed comments and descriptions related to the configurable parameters and definitions.
0 commit comments