Tags

    Building Arduino Atmega8u2 firmware on Linux

    I've had a few questions about how to build the HID firmware for the atmega8u2 under linux. Here's a guide for getting the avr tools installed to be able to build the firmware. I've tested this on Ubuntu 10.04.

    Build and install binutils for the AVR

    Build and install libgmp (needed for gcc-4.5.3)

    Install libmpfr and libmpc (needed for gcc-4.5.3)

    • sudo apt-get install libmpfr-dev
    • sudo apt-get install libmpc-dev

    Build and install gcc-4.5.3 for AVR

    Build and install avr-libc

    Do a test build of Arduino-usbserial

    The Arduino-usbserial firmware is the default firmware that the UNO comes installed with on its atmega8u2. It implements a serial interface over USB. Build this firmware to check that your avr-gcc toolchain and avr-libc are working.
    • cd Arduino/hardware/arduino/firmwares/arduino-usbserial
    • edit the makefile and make sure that MCU = atmega8u2 and ARDUINO_PID = 0x0001
    • make
    • You should have an newly built Arduino-usbserial.hex file.

    Comments

    renato gallo (unauthenticated)
    Oct 18, 2011

    In file included from ../../LUFA/Drivers/USB/../../Common/Common.h:68:0,
    from ../../LUFA/Drivers/USB/USB.h:362,
    from Descriptors.h:42,
    from Arduino-usbserial.h:45,
    from Arduino-usbserial.c:37:
    ../../LUFA/Drivers/USB/../../Common/ArchitectureSpecific.h:66:9: warning: "ARCH" is not defined
    ../../LUFA/Drivers/USB/../../Common/ArchitectureSpecific.h:66:17: warning: "ARCH_AVR8" is not defined
    In file included from ../../LUFA/Drivers/USB/Core/USBController.h:118:0,
    from ../../LUFA/Drivers/USB/Core/USBTask.h:47,
    from ../../LUFA/Drivers/USB/USB.h:366,
    from Descriptors.h:42,
    from Arduino-usbserial.h:45,
    from Arduino-usbserial.c:37:
    ../../LUFA/Drivers/USB/Core/AVR8/USBController_AVR8.h:84:5: error: #error F_USB is not defined. You must define F_USB to the frequency of the unprescaled USB controller clock in your project makefile.
    ../../LUFA/Drivers/USB/Core/AVR8/USBController_AVR8.h:87:8: warning: "F_USB" is not defined
    ../../LUFA/Drivers/USB/Core/AVR8/USBController_AVR8.h:99:10: warning: "F_USB" is not defined
    ../../LUFA/Drivers/USB/Core/AVR8/USBController_AVR8.h:114:5: error: #error No PLL prescale value available for chosen F_USB value and AVR model.
    In file included from ../../LUFA/Drivers/USB/Core/USBController.h:118:0,
    from ../../LUFA/Drivers/USB/Core/USBTask.h:47,
    from ../../LUFA/Drivers/USB/USB.h:366,
    from Descriptors.h:42,
    from Arduino-usbserial.h:45,
    from Arduino-usbserial.c:37:
    ../../LUFA/Drivers/USB/Core/AVR8/USBController_AVR8.h: In function 'USB_PLL_On':
    ../../LUFA/Drivers/USB/Core/AVR8/USBController_AVR8.h:335:14: error: 'USB_PLL_PSC' undeclared (first use in this function)
    ../../LUFA/Drivers/USB/Core/AVR8/USBController_AVR8.h:335:14: note: each undeclared identifier is reported only once for each function it appears in
    In file included from Arduino-usbserial.h:45:0,
    from Arduino-usbserial.c:37:
    Descriptors.h: At top level:
    Descriptors.h:84:12: error: conflicting types for 'CALLBACK_USB_GetDescriptor'
    ../../LUFA/Drivers/USB/Core/AVR8/../Device.h:133:13: note: previous declaration of 'CALLBACK_USB_GetDescriptor' was here
    In file included from ../../LUFA/Drivers/Board/LEDs.h:175:0,
    from Arduino-usbserial.h:50,
    from Arduino-usbserial.c:37:
    ./Board/LEDs.h:48:5: error: #error Do not include this file directly. Include LUFA/Drivers/Board/LEDS.h instead.
    Arduino-usbserial.c: In function 'main':
    Arduino-usbserial.c:127:5: warning: implicit declaration of function 'Serial_TxByte'
    make: *** [Arduino-usbserial.o] Error 1

    Wergio (unauthenticated)
    Oct 19, 2011

    Hi, I followed your instruction, I'm using Ubuntu 10.10 and i make the hex file without error but when i try to upload the HEX with FLIP I get "Address Out of Range", seems that the file is too big... how is it possibile? I built the official arduino source...

    coopermaa (unauthenticated)
    Nov 15, 2011

    Hi, I get "Address is out range" problem too when loading hex file with FLIP. Can you tell me how to fix it?

    Cory (unauthenticated)
    Jan 14, 2012

    But how do you finally compile the file then? You skipped that part.

    darran
    Jan 16, 2012

    Hi Cory,

    its in the last steps: you run the "make" command in the Arduino/hardware/arduino/firmwares/arduino-usbserial directory. This builds the arduino-usbserial.hex file.

    Leonard (unauthenticated)
    Jun 25, 2012

    Hello darran,
    I am a young developer from germany and I am working on a Project which involves the LUFA Framework and flashing built Firmwares to the UNOs ATMega8u2. However I encountered some problems when trying to build Firmwares myself. It seems that I just can not set up the compiler on my Mac OS X Lion Machine.. Thats why I wanted to ask you, whether you would build a Firmware for me? You can contact me via Twitter (twitter.com/SpoonHarpoon)

    Thank you very much
    Leonard

    darran
    Jul 9, 2012

    Hi Leonard,

    for OS X Lion, you can stiil use the macports set of packages (http://www.macports.org) to install avr-gcc and everything else you need to build the firmware. I'll send you a tweet. Haven't tried this my self yet but will give it a go this weekend.

    mike (unauthenticated)
    Aug 20, 2012

    Hey Darran,

    I was able to follow your instructions to d/l and install the appropriate packages to build a firmware file (Arduino-usbserial.hex). I wanted to make my own firmware to simulate a device (a pedometer). I was wondering what APIs you looked at to create firmwares for other HID devices? Where could I get more information on this? Other than your examples, I wouldn't know where to begin. as you can probably tell, i'm a newbie to firmware, but it is something i really am interested in.

    Aloha,
    Mike

    Waiser (unauthenticated)
    Dec 21, 2012

    Hello Everyone.

    I am on first step, and getting problem at library installation.

    Following steps are completed successfully.

    1. binutils for the AVR
    2. install libgmp (needed for gcc-4.5.3)
    3.Install libmpfr and libmpc
    4. Build and install gcc-4.5.3 for AVR

    I am getting problem on step "Build and install avr-libc".

    After this statement I got the following errors.
    CFLAGS=-Os ../configure --build=`../config.guess` --host=avr

    checking build system type... Invalid configuration `../config.guess': machine `../config.guess' not recognized
    configure: error: /bin/bash ../config.sub ../config.guess failed

    After going through different forum, I found that config.guess and config.sub have to be updated.

    I updated these files.

    but after executing this statement again

    CFLAGS=-Os ../configure --build=`../config.guess` --host=avr

    and also executing this

    sudo ln -s /usr/share/automake-1.11 /usr/share/automake-1.10

    I got the following error.

    configure: error: cannot run /bin/bash ../config.sub

    Now I am stuck.

    i dnt know where is the issue. Looking forward to for prompt response.

    Reagrds,
    AES

    Waiser (unauthenticated)
    Dec 26, 2012

    Hello Every one

    I have solve this problem by myself.

    Follow the steps to resolve this issue

    1.Get your pc name by uname command for linux. or simply run config.guess on shell. For me it was
    i686-pc-gnu-linux
    2.CFLAGS=-Os ../configure --build=i686 --host=avr

    avr-library will start configuring, it will take 1-2 minute and will configure successfully.

    Jason (unauthenticated)
    Nov 23, 2013

    Hi Darran,

    Nice tutorial, but at my last step, make the Hex, something wrong , could you pls help to look?

    *****************************************************

    jason@ubuntu:~/FGS/SourceCode$ make
    makefile:141: ../../LUFA/makefile: No such file or directory
    makefile:507: *** missing separator (did you mean TAB instead of 8 spaces?). Stop.

    *****************************************************

    Thank you

    darran
    Dec 13, 2013

    Hi Jason,

    it looks like the LUFA directory is missing.

    Download a copy of LUFA 100807, unzip it and copy the LUFA subdirectory to the Arduino source tree:
    ftp http://www.fourwalledcubicle.com/files/LUFA/LUFA-100807.zip
    unzip LUFA-100807.zip
    cp -pr LUFA\ 100807/LUFA Arduino/hardware/arduino

    Btw, I've put the code up on github also: https://github.com/harlequin-tech/arduino-usb

    nick (unauthenticated)
    Mar 13, 2014

    Sorry to be a pain, has anyone done this with M$ windows Amtel Studio? The last word I understood in this page was ubuntu.
    I'm trying to figure building from a makefile for myself, but it's like trying to teach a dog thermodynamics.