Arduino AVR Boards Core

repository·master·Indexed 23 days ago

https://github.com/arduino/arduinocore-avr

Core implementation and configuration for the Arduino AVR Boards platform. Provides hardware abstraction layers, libraries, and build configurations for AVR-based microcontrollers used by the Arduino IDE and Arduino CLI. Includes documentation for the EEPROM library, network Client and Server abstract classes, and instructions for building and programming bootloaders such as Caterina (for Arduino Robot and LilyPadUSB), Optiboot, and the Arduino Gemma bootloader.

Tokens
3.8K
Snippets
14
Records
29
Agent score
81%

What's inside arduino-arduinocore-avr

  1. Overview of Arduino AVR Boards platform

    master
    This repository provides the source code and configuration files required to support Arduino AVR Boards as an Arduino platform. It enables the compilation and uploading of sketches to AVR-based hardware (such as the Arduino Uno, Nano, and Mega) by providing the necessary core libraries, board definitions, and toolchain configurations.
  2. How to enter the bootloader on Arduino Robot boards

    master

    Unlike standard Leonardo boards, the Arduino Robot bootloader (based on the LilypadUSB design) requires a specific reset sequence to enter bootloader mode:

    • Action: Double-click the reset button.
    • Timing: You must click the button twice in less than 3/4 of a second.

    This mechanism is designed for environments where the board may be subject to direct physical manipulation (e.g., robotics competitions).

  3. Use EERef and EEPtr for advanced EEPROM manipulation

    master

    The library provides two background classes for a more pointer-like or RAM-like experience:

    EERef

    An EERef object references a specific EEPROM cell and mimics a byte of RAM. It has a 2-byte overhead.

    EEPtr

    An EEPtr is a bidirectional pointer to EERef objects. It supports standard pointer operations like dereferencing (*ptr) and increment/decrement (ptr++).

    Iteration with begin() and end()

    • EEPROM.begin(): Returns an EEPtr pointing to the first cell (address 0).
    • EEPROM.end(): Returns an EEPtr pointing to the location after the last cell. Note: This pointer is technically out of range and hardware wrapping may cause it to reference the first cell.
  4. Understand ATmega8U2 firmware structure and dependencies

    master

    The ATmega8U2 firmware on Arduino Uno and Mega 2560 consists of two parts:

    1. DFU Bootloader: Located in the arduino-usbdfu directory.
    2. USB-to-Serial Firmware: Located in the arduino-usbserial directory.

    Requirements & Compilation:

    • Both components must be compiled against LUFA 100807.
    • The two .hex files are combined into a single file for burning.

    USB VID/PID Usage:

    • The arduino-usbdfu project uses Atmel's VID and MCU-specific PIDs for FLIP software compatibility.
    • The arduino-usbserial project uses Atmel's VID and a PID donated to LUFA for development/testing.
    • Warning: The LUFA-donated VID/PID combination is intended for non-commercial testing only and should not be used in products released to the general public.
    • The production version of arduino-usbserial uses the official Arduino VID and is intended strictly for official Arduino hardware.
  5. Recompile the Arduino Gemma Bootloader with custom USB parameters

    master

    The Arduino Gemma Bootloader is a derivative of the Adafruit Trinket/Gemma Bootloader, modified with specific USB VID/PID, Manufacturer name, and Device name parameters.

    If you need to recompile the bootloader, you must replace the original usbconfig.h file with the version provided in this repository or apply the provided usbconfig.patch file to the original source.

  6. Burn ATmega8U2 firmware to Arduino Uno

    master

    Use avrdude to burn the combined DFU and USB-to-serial firmware onto the ATmega8U2 chip of an Arduino Uno. This command flashes the .hex file and sets the appropriate lock, low, high, and extended fuses.

    avrdude -p at90usb82 -F -P usb -c avrispmkii -U flash:w:UNO-dfu_and_usbserial_combined.hex -U lfuse:w:0xFF:m -U hfuse:w:0xD9:m -U efuse:w:0xF4:m -U lock:w:0x0F:m
  7. Program chips using ISP targets

    master

    Each CPU target has a corresponding ISP target (e.g., atmega328_isp for the ATmega328) that programs the bootloader into the chip. These targets automatically set the appropriate fuses and lock bits and upload the bootloader code.

    By default, the makefile uses a USB programmer. To use a serial programmer like ArduinoISP, you must override the ISPTOOL, ISPPORT, and ISPSPEED variables during the make invocation.

  8. Setup and upload Arduino usbserial firmware to ATMEGA8U2

    master

    To build and upload the arduino-usbserial application firmware to an ATMEGA8U2 using the Arduino USB DFU bootloader, follow these steps:

    1. Preparation

    • Unpack the source code into the LUFA Projects directory.
    • Open the makefile and set the ARDUINO_MODEL_PID variable to the appropriate value for your target board.

    2. Build

    Run the following command in your terminal:

    make clean; make

    3. Enter USB DFU Mode

    To put the ATMEGA8U2 into DFU mode, perform the following sequence:

    1. Assert and hold the 8U2's RESET line.
    2. Assert and hold the 8U2's HWB line.
    3. Release the 8U2's RESET line.
    4. Release the 8U2's HWB line.

    Verify that the board enumerates on your computer as either Arduino Uno DFU or Arduino Mega 2560 DFU.

    4. Upload

    Depending on your operating system, use the corresponding command:

    • OS X or Linux: Run make dfu (requires dfu-programmer to be installed).
    • Windows: Run make flip (requires Flip to be installed).

    5. Verification

    After a successful upload, ensure the board enumerates as Arduino Uno or Arduino Mega 2560. You can verify functionality by uploading a new Arduino sketch from the Arduino IDE.

    make clean; make
    # Then either:
    make dfu
    # or
    make flip
  9. Setup and program an ATMEG8U2 with the Arduino USB DFU bootloader

    master

    To set up the project and program an ATMEG8U2 using the Arduino USB DFU bootloader, follow these steps:

    1. Unpack the source files into the LUFA bootloader directory.
    2. Open the makefile and set the ARDUINO_MODEL_PID variable to the appropriate value for your hardware.
    3. Execute the build and programming sequence using make.

    After programming, verify the installation by checking if the board enumerates as either Arduino Uno DFU or Arduino Mega 2560 DFU. You can test the functionality by uploading the Arduino-usbserial application firmware (refer to the instructions in the Arduino-usbserial directory).

    make clean; make; make program
  10. Build the Caterina bootloader for Arduino Robot boards

    master

    The Arduino Robot consists of two boards using the ATmega32U4 processor. Each requires a specific USB identifier configured in the Makefile:

    • Arduino Robot Control board: Uses USB identifier 0x0038 (default).
    • Arduino Robot Motor board: Uses USB identifier 0x0039. To build this version, you must edit the Makefile to comment out the line dedicated to the Control board's PID and uncomment the line configuring the Motor board's PID.

    Prerequisites

    You must use a specific version of LUFA:

    1. Download LUFA-111009 from fourwalledcubicle.com.
    2. Extract the contents directly into the Caterina-Arduino_Robot bootloader directory.

    Build Steps

    1. Open a command prompt in the Caterina-Arduino_Robot directory.
    2. Run the make command.
    make