Arduino AVR Boards Core
repository·master·Indexed 23 days ago
https://github.com/arduino/arduinocore-avrCore 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.
What's inside arduino-arduinocore-avr
- 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.
How to enter the bootloader on Arduino Robot boards
masterUnlike 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).
Use EERef and EEPtr for advanced EEPROM manipulation
masterThe library provides two background classes for a more pointer-like or RAM-like experience:
EERef
An
EERefobject references a specific EEPROM cell and mimics a byte of RAM. It has a 2-byte overhead.EEPtr
An
EEPtris a bidirectional pointer toEERefobjects. It supports standard pointer operations like dereferencing (*ptr) and increment/decrement (ptr++).Iteration with begin() and end()
EEPROM.begin(): Returns anEEPtrpointing to the first cell (address 0).EEPROM.end(): Returns anEEPtrpointing 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.
Understand ATmega8U2 firmware structure and dependencies
masterThe ATmega8U2 firmware on Arduino Uno and Mega 2560 consists of two parts:
- DFU Bootloader: Located in the
arduino-usbdfudirectory. - USB-to-Serial Firmware: Located in the
arduino-usbserialdirectory.
Requirements & Compilation:
- Both components must be compiled against LUFA 100807.
- The two
.hexfiles are combined into a single file for burning.
USB VID/PID Usage:
- The
arduino-usbdfuproject uses Atmel's VID and MCU-specific PIDs for FLIP software compatibility. - The
arduino-usbserialproject 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-usbserialuses the official Arduino VID and is intended strictly for official Arduino hardware.
- DFU Bootloader: Located in the
Important legal notice regarding Arduino USB VID/PID usage
masterThe USB VID/PID used in the Arduino Gemma Bootloader is specific to Gemma products. You are prohibited from using the Arduino USB VID/PID for your own non-Gemma products or projects. To use your own identifiers, you must purchase a USB VID from http://www.usb.org/developers/vendor/.Download ArduinoISP firmware source files
masterThe source files for the ArduinoISP firmware can be downloaded from the official GitHub repository. This firmware allows an Arduino board to be used as an In-System Programmer (ISP) to program other AVR microcontrollers.
https://github.com/arduino/ArduinoISPRecompile the Arduino Gemma Bootloader with custom USB parameters
masterThe 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.hfile with the version provided in this repository or apply the providedusbconfig.patchfile to the original source.Burn ATmega8U2 firmware to Arduino Uno
masterUse
avrdudeto burn the combined DFU and USB-to-serial firmware onto the ATmega8U2 chip of an Arduino Uno. This command flashes the.hexfile 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:mProgram chips using ISP targets
masterEach CPU target has a corresponding ISP target (e.g.,
atmega328_ispfor 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, andISPSPEEDvariables during themakeinvocation.Setup and upload Arduino usbserial firmware to ATMEGA8U2
masterTo build and upload the
arduino-usbserialapplication firmware to an ATMEGA8U2 using the Arduino USB DFU bootloader, follow these steps:1. Preparation
- Unpack the source code into the LUFA
Projectsdirectory. - Open the
makefileand set theARDUINO_MODEL_PIDvariable to the appropriate value for your target board.
2. Build
Run the following command in your terminal:
make clean; make3. Enter USB DFU Mode
To put the ATMEGA8U2 into DFU mode, perform the following sequence:
- Assert and hold the 8U2's
RESETline. - Assert and hold the 8U2's
HWBline. - Release the 8U2's
RESETline. - Release the 8U2's
HWBline.
Verify that the board enumerates on your computer as either
Arduino Uno DFUorArduino Mega 2560 DFU.4. Upload
Depending on your operating system, use the corresponding command:
- OS X or Linux: Run
make dfu(requiresdfu-programmerto be installed). - Windows: Run
make flip(requiresFlipto be installed).
5. Verification
After a successful upload, ensure the board enumerates as
Arduino UnoorArduino 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- Unpack the source code into the LUFA
Setup and program an ATMEG8U2 with the Arduino USB DFU bootloader
masterTo set up the project and program an ATMEG8U2 using the Arduino USB DFU bootloader, follow these steps:
- Unpack the source files into the LUFA bootloader directory.
- Open the
makefileand set theARDUINO_MODEL_PIDvariable to the appropriate value for your hardware. - Execute the build and programming sequence using
make.
After programming, verify the installation by checking if the board enumerates as either
Arduino Uno DFUorArduino Mega 2560 DFU. You can test the functionality by uploading theArduino-usbserialapplication firmware (refer to the instructions in theArduino-usbserialdirectory).make clean; make; make programBuild the Caterina bootloader for Arduino Robot boards
masterThe 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:
- Download
LUFA-111009from fourwalledcubicle.com. - Extract the contents directly into the
Caterina-Arduino_Robotbootloader directory.
Build Steps
- Open a command prompt in the
Caterina-Arduino_Robotdirectory. - Run the
makecommand.
make- Arduino Robot Control board: Uses USB identifier