Skip to content

alfreedom/ABOS

Repository files navigation

ABOS (AVR Bootloader Open Source)

Simple bootloader to avoid ISP hardware to program AVR Microcontrollers

Supported Devices

  • 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.


Installation

  1. Download the repository:

     git clone https://github.com/alfreedom/abos
    
  2. Edit the include device configuration in the Makefile to choose the microcontroller:

     include devices/myDevice.mk
    
  3. Change the AVRDUDE_PROG to specify your programmer in the Makefile:

     AVRDUDE_PROG = -c usbtiny
    
  4. Enter to the bootloader folder and run:

     make all
     make install
    
     or
    
     make
     make flash
     make fuse
     make lockbits
    

Add support to other microcontrollers

  1. Add the a new makefile definitions in "devices" folder, eg, myDevice.mk
  2. Edit the device name, frequency, fuses, lock bits, flash and bootloader parameters.

Bootloader Logic

Enter Bootloader Mode

  1. The bootloader waits for Sync Command (SYN [0x16]). If sync command not received for a while, jump to user program.
  2. 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).
  3. 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.
  4. If the bootloader receives the Cancel Bootloader command, jump to user program, else if receives the Enter Bootloader command enter in bootloader mode
  5. The bootloader response with Acknowledge Command (ACK [0x06]) to the Enter Bootloader command or the Cancel Bootloader command.
  6. Once entered in Bootloader mode, the bootloader can receive 2 command types: Page Write Command (STX [0x02]) or End of Transmission Program (EOT [0x04]).
Figure 1
     ACK      VERSION    CPU MODEL   PAGE SIZE   FLASH SIZE
┌──────────┬───────────┬───────────┬───────────┬────────────┐
│ 1 (0x06) │     3     │    20     │      2    │      2     | = 28 bytes
└──────────┴───────────┴───────────┴───────────┴────────────┘

Send a program to bootloader

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])].

  1. Send Page Write Command (STX [0x02])
  2. Once the Page Write Command is received, bootloader responds with Acknowledge Command (ACK [0x06])
  3. Send data in chunks of size PAGE_SIZE
  4. 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.
  5. Repeat steps 1 to 4 while there is still data to be sent.
  6. Send the End of Transmission Program (EOT [0x04]) command to finish loading.
  7. 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.