- ATmega16
- ATmega32
- ATmega128/ATmega128A
The default baudrate is 38400, is defined in the firs code line of the "abos.c" file. If you need other baudrate, change these value.
-
Download the repository:
git clone https://github.com/alfreedom/abos
-
Edit the include device configuration in the Makefile to choose the microcontroller:
include devices/myDevice.mk
-
Change the AVRDUDE_PROG to specify your programmer in the Makefile:
AVRDUDE_PROG = -c usbtiny
-
Enter to the bootloader folder and run:
make all make install or make make flash make fuse make lockbits
- Add the a new makefile definitions in "devices" folder, eg, myDevice.mk
- Edit the device name, frequency, fuses, lock bits, flash and bootloader parameters.
- The bootloader waits for Sync Command (SYN [0x16]). If sync command not received for a while, jump to user program.
- When receive sync, the bootloader respose with Acknowledge Command (ACK [0x06]) (1 byte), the BOOTLOADER VERSION (3 bytes), the CPU MODEL (20 bytes), the PAGE_SIZE (2 bytes) and the available MEMORY_SIZE for program (2 bytes), 28 bytes in total (see figure 1).
- The bootloader wait for the Enter Bootloader command (SI [0x0F]) or the Cancel Bootloader command (ESC [0x1B]). If some command is not received for a while, jump to user program.
- If the bootloader receives the Cancel Bootloader command, jump to user program, else if receives the Enter Bootloader command enter in bootloader mode
- The bootloader response with Acknowledge Command (ACK [0x06]) to the Enter Bootloader command or the Cancel Bootloader command.
- Once entered in Bootloader mode, the bootloader can receive 2 command types: Page Write Command (STX [0x02]) or End of Transmission Program (EOT [0x04]).
ACK VERSION CPU MODEL PAGE SIZE FLASH SIZE
┌──────────┬───────────┬───────────┬───────────┬────────────┐
│ 1 (0x06) │ 3 │ 20 │ 2 │ 2 | = 28 bytes
└──────────┴───────────┴───────────┴───────────┴────────────┘
The loading of a program is done after entering the bootloader mode, sending the Page Write Command (STX [0x02]) followed by the page data chunks of size PAGE_SIZE. At the end of each packet (STX + DATA_PAGE) the booloader responds with Acknowledge Command (ACK [0x06]).
The program to be loaded must be fragmented into N pages of size PAGE_SIZE data. If the size of the program is not a multiple of PAGE_SIZE, the remaining data of the program must be added to the last page and filled with 0xFF until the size of PAGE_SIZE is completed.
The bootloader response with No Acknowledge Command (NACK [0x15]) if PAGE_SIZE bytes not received in a while after a Page Wirte Command (STX [0x02]).
Once the loading of the program has been completed, the End of Transmission Program (EOT [0x04]) must be sent to tell the bootloader that the loading has finished. The bootloader responds with Acknowledge Command (ACK [0x06]) to indicate that it has left the bootloader mode and will execute the program.
If the bootloader receives an invalid command, it will respond with the Cancelation Command (CAN [0x18])].
- Send Page Write Command (STX [0x02])
- Once the Page Write Command is received, bootloader responds with Acknowledge Command (ACK [0x06])
- Send data in chunks of size PAGE_SIZE
- Once the PAGE_SIZE data is received, bootloader responds with Acknowledge Command (ACK [0x06]). If the bootloader not receive PAGE_SIZE chunk in a while, it will respose with No Acknowledge Command (NACK [0x15]) and exit from bootloader mode.
- Repeat steps 1 to 4 while there is still data to be sent.
- Send the End of Transmission Program (EOT [0x04]) command to finish loading.
- The bootloader responds with Acknowledge Command (ACK [0x06]) to indicate that it has left the bootloader mode, and it will jump to the user program.