====================================================================================================
Caterina Bootloader for Arduino and AVR
====================================================================================================

https://github.com/arduino/ArduinoCore-avr/tree/master/bootloaders/caterina

----------------------------------------------------------------------------------------------------
Caterina and all its files are not part of the eCxx library and are not covered by eCxx licenses.

To build Caterina from source, LUFA 111009 is needed. The LUFA library is released under a modified
MIT license, see:

    https://github.com/abcminiuser/lufa/blob/master/LUFA/License.txt

for the license details.

A minimum LUFA source code is included with eCxx so Caterina can be built. The complete version of
LUFA 111009 can be downloaded from:

    https://github.com/abcminiuser/lufa/releases/tag/LUFA-111009
----------------------------------------------------------------------------------------------------

This Caterina bootloader source code has been modified to meet eCxx's need.

Several prebuilt bootloader HEX files are included:

    Caterina-Leonardo.hex          - official Arduino Leonardo bootloader from Arduino distribution
                                     (copied from an unmodified Caterina source code tree)

    Caterina-AT90USB1286-16MHz.hex - eCxx bootloader for AT90USB1286 (16 MHz)
    Caterina-AT90USB1286-8MHz.hex  - eCxx bootloader for AT90USB1286 ( 8 MHz)

    Caterina-AT90USB646-16MHz.hex  - eCxx bootloader for AT90USB646  (16 MHz)
    Caterina-AT90USB646-8MHz.hex   - eCxx bootloader for AT90USB646  ( 8 MHz)

    Caterina-ATmega32U4-16MHz.hex  - eCxx bootloader for ATmega32U4  (16 MHz)
    Caterina-ATmega32U4-8MHz.hex   - eCxx bootloader for ATmega32U4  ( 8 MHz)

    Caterina-ATmega16U4-16MHz.hex  - eCxx bootloader for ATmega16U4  (16 MHz)
    Caterina-ATmega16U4-8MHz.hex   - eCxx bootloader for ATmega16U4  ( 8 MHz)


====================================================================================================
Usage Examples
====================================================================================================

-----------------------------------------------
Fuse setting for ATmega16U4 16 Mhz for Caterina
-----------------------------------------------

Low      fuse : <none>         (0xFF)
High     fuse : SPIEN, BOOTRST (0xD8)
Extended fuse : BODLEVEL1      (0xCB)
Unlock   bits :                 0x3F   =>   use 0x2F to protect the bootloader section

External crystal oscillator; frequency 8.0+ MHz; start-up time 16K CK / 14 CK + 65 mS
Boot reset vector enabled (size 2048 words, boot start address $1800)
Serial program downloading (SPI) enabled

Brown-out detection level at 2.6 V


-----------------------------------------------
Fuse setting for ATmega32U4 16 Mhz for Caterina
-----------------------------------------------

Low      fuse : <none>         (0xFF)
High     fuse : SPIEN, BOOTRST (0xD8)
Extended fuse : BODLEVEL1      (0xCB)
Unlock   bits :                 0x3F   =>   use 0x2F to protect the bootloader section

External crystal oscillator; frequency 8.0+ MHz; start-up time 16K CK / 14 CK + 65 mS
Boot reset vector enabled (size 2048 words, boot start address $3800)
Serial program downloading (SPI) enabled

Brown-out detection level at 2.6 V


-----------------------------------------------
Fuse setting for AT90USB646 16 Mhz for Caterina
-----------------------------------------------
Low      fuse : <none>         (0xFF)
High     fuse : SPIEN, BOOTRST (0xDA)
Extended fuse : BODLEVEL1      (0xFB)
Unlock   bits :                 0x3F   =>   use 0x2F to protect the bootloader section

External crystal oscillator; frequency 8.0+ MHz; start-up time 16K CK / 14 CK + 65 mS
Boot reset vector enabled (size 2048 words, boot start address $7C00)
Serial program downloading (SPI) enabled

Brown-out detection level at 2.6 V


------------------------------------------------
Fuse setting for AT90USB1286 16 Mhz for Caterina
------------------------------------------------
Low      fuse : <none>         (0xFF)
High     fuse : SPIEN, BOOTRST (0xDA)
Extended fuse : BODLEVEL1      (0xFB)
Unlock   bits :                 0x3F   =>   use 0x2F to protect the bootloader section

External crystal oscillator; frequency 8.0+ MHz; start-up time 16K CK / 14 CK + 65 mS
Boot reset vector enabled (size 2048 words, boot start address $F800)
Serial program downloading (SPI) enabled

Brown-out detection level at 2.6 V


----------------------------------------------
Burn Caterina for ATmega16U4 (eCxx bootloader)
----------------------------------------------

avrdude -c usbasp -B 1 -p atmega16u4 -e -U lfuse:w:0xFF:m -U hfuse:w:0xD8:m -U efuse:w:0xCB:m -U lock:w:0x3F:m

avrdude -c usbasp -B 1 -p atmega16u4 -D -V -U flash:w:Caterina-ATmega16U4-16MHz.hex

avrdude -c usbasp -B 1 -p atmega16u4 -U lock:w:0x2F:m


----------------------------------------------
Burn Caterina for ATmega32U4 (eCxx bootloader)
----------------------------------------------

avrdude -c usbasp -B 1 -p atmega32u4 -e -U lfuse:w:0xFF:m -U hfuse:w:0xD8:m -U efuse:w:0xCB:m -U lock:w:0x3F:m

avrdude -c usbasp -B 1 -p atmega32u4 -D -V -U flash:w:Caterina-ATmega32U4-16MHz.hex

avrdude -c usbasp -B 1 -p atmega32u4 -U lock:w:0x2F:m


-------------------------------------------------------------------
Burn Caterina for ATmega32U4 (official Arduino Leonardo bootloader)
-------------------------------------------------------------------

avrdude -c usbasp -B 1 -p atmega32u4 -e -U lfuse:w:0xFF:m -U hfuse:w:0xD8:m -U efuse:w:0xCB:m -U lock:w:0x3F:m

avrdude -c usbasp -B 1 -p atmega32u4 -D -V -U flash:w:Caterina-Leonardo.hex

avrdude -c usbasp -B 1 -p atmega32u4 -U lock:w:0x2F:m


----------------------------------------------
Burn Caterina for AT90USB646 (eCxx bootloader)
----------------------------------------------
avrdude -c usbasp -B 1 -p at90usb646 -e -U lfuse:w:0xFF:m -U hfuse:w:0xDA:m -U efuse:w:0xFB:m -U lock:w:0x3F:m

avrdude -c usbasp -B 1 -p at90usb646 -D -V -U flash:w:Caterina-AT90USB646-16MHz.hex

avrdude -c usbasp -B 1 -p at90usb646 -U lock:w:0x2F:m


-----------------------------------------------
Burn Caterina for AT90USB1286 (eCxx bootloader)
-----------------------------------------------
avrdude -c usbasp -B 1 -p at90usb1286 -e -U lfuse:w:0xFF:m -U hfuse:w:0xDA:m -U efuse:w:0xFB:m -U lock:w:0x3F:m

avrdude -c usbasp -B 1 -p at90usb1286 -D -V -U flash:w:Caterina-AT90USB1286-16MHz.hex

avrdude -c usbasp -B 1 -p at90usb1286 -U lock:w:0x2F:m


-------------------
Upload user program
-------------------

avrdude -c avr109 -P /dev/ttyACM0 -b 115200 -p atmega32u4 -D -U flash:w:my_program.hex:i

# In order for the bootloader to run, the MCU must be reset before uploading. This can be done
  manually by pressing the reset button or by running the Python script
  "tools/ResetToBootloader.py". After resetting, a standard AVRDUDE command can be executed.

# Resetting via USB (using the Python script) is only possible if the currently running firmware
  supports this feature (for Arduino IDE, please ensure that Arduino Leonardo board is selected).
  Also, if the MCU is stuck/crashed, resetting via USB would not be possible.


====================================================================================================
