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
+15-15Lines changed: 15 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ To prepare your build environment first read this tutorial:
8
8
9
9
**A "bootloader" is a small program that is written to a dedicated section of the non-volatile memory of a computer. In microcontrollers it is mostly used to facilitate the updating of the main program by utilizing a communication peripheral, thereby eliminating the requirement for an external programmer. In more sophisticated computer systems, a bootloader is mostly employed to pre-configure the system clock and input/output interfaces.**
10
10
11
-
**With this definition in mind, what follows is not a practical bootloader. Instead, it is a tutorial designed to step-by-step illustrate the process of program compilation and configuration to show how a bootloader can self-program the microcontroller. This bootloader is literally hardcoding the binary data of the program you want to upload (**[**`blinky_test`**](blinky_test)**) in the bootloader itself. With some small changes in code you can modify it to receive binary of the program you want to upload through UART, I2C or SPI. To learn how to write a more sophisticated and secure bootloader study the**[**resources**](#resources).
11
+
**With this definition in mind, what follows is not a practical bootloader. Instead, it is a tutorial designed to step-by-step illustrate the process of program compilation and configuration to show how a bootloader can self-program the microcontroller. This bootloader is literally hardcoding the binary data of the program you want to upload (**[**`blinky`**](blinky)**) in the bootloader itself. With some small changes in code you can modify it to receive binary of the program you want to upload through UART, I2C or SPI. To learn how to write a more sophisticated and secure bootloader study the**[**resources**](#resources).
12
12
13
13
*DONE:*
14
14
- Configure fuse bits settings for bootloader section size and reset vector
@@ -134,14 +134,14 @@ This means that the total size of the `blink_test` program is 162 bytes.
134
134
135
135
## Self Programming the Microcontroller Inside the Bootloader Program
136
136
137
-
In the [`bootloader`](bootloader) program we put the binary code of the [`blinky_test`](blinky_test) program in an array called `blinky_test_program_bin`.
137
+
In the [`bootloader`](bootloader) program we put the binary code of the [`blinky`](blinky) program in an array called `blinky_test_program_bin`.
138
138
139
139
At the begining of the program LED blinks 2 times slowly to show that the bootloader program is starting.
140
140
141
141
The function `write_program()` writes the contents of the `blinky_test_program_bin` to the address `0x0000`
142
142
of the flash memory of the microcontroller.
143
143
144
-
Finally the program jumps to the address `0x0000` of the flash memory and runs the `blinky_test` program. Then LED blinks faster as long as microcontroller is not reset or powered off.
144
+
Finally the program jumps to the address `0x0000` of the flash memory and runs the `blinky` program. Then LED blinks faster as long as microcontroller is not reset or powered off.
145
145
146
146
```c
147
147
#define F_CPU 16000000UL
@@ -152,7 +152,7 @@ Finally the program jumps to the address `0x0000` of the flash memory and runs t
152
152
#include <avr/interrupt.h>
153
153
#include <avr/pgmspace.h>
154
154
155
-
// This array contains the binary code for the `blinky_test` program
155
+
// This array contains the binary code for the `blinky` program
156
156
// that blinks LED (on PB5) fast (with 5Hz frequency)
// Jump to the start address of the user program (0x0000)
267
-
asm("jmp 0");
267
+
__asm__ __volatile__("jmp 0");
268
268
269
269
// Bootloader ends here
270
270
}
@@ -298,7 +298,7 @@ Data: 162 bytes (7.9% Full)
298
298
(.data + .bss + .noinit)
299
299
```
300
300
301
-
This means that the total size of the `bootloader` program is 664 bytes. As you may noted that 162 bytes is exactly the size of `blinky_test` program stored in an array inside the `bootloader` program.
301
+
This means that the total size of the `bootloader` program is 664 bytes. As you may noted that 162 bytes is exactly the size of `blinky` program stored in an array inside the `bootloader` program.
302
302
303
303
By setting the boot section size of flash memory to 512 words (1024 bytes) we can fit our bootloader program (664 bytes) in it. With this configuration the start address of the boot section becomes `0x3E00` (in words). By knowing that each word is equal to 2 bytes, the start address becomes `0x3E00 * 2 = 0x7C00`.
Adding `-Wl,-section-start=.text=0x7C00` flags to linker options of AVR-GCC makes start address of the bootloader program to be set on the start address of boot section.
With this settings every time the microcontroller resets, it first executes the `bootloader`, the `bootloader` writes the `blinky_test` to address `0` of the flash memory and it executes `blinky_test` until next reset.
326
+
With this settings every time the microcontroller resets, it first executes the `bootloader`, the `bootloader` writes the `blinky` to address `0` of the flash memory and it executes `blinky` until next reset.
0 commit comments