Go Down

Topic: Tutorial - How to change firmware on 8u2 (Read 116 times) previous topic - next topic


Oct 01, 2010, 09:53 pm Last Edit: Oct 01, 2010, 11:50 pm by ant.b Reason: 1
I've just received my arduino uno.
I try to upload a new firmware on the 8u2
I share here the steps I follow.
I use Windows.

I use the following sources:

I need those software:
After install, copy folder arduino-0020\hardware\arduino\firmwares\arduino-usbserial on LUFA_100807\Projects\

There are two modifications to do:
Solder 2 jumpers: one on the HWB line and one between pin 5 & 6 on ISP1 for RESET

How to put the Uno on DFU mode:
     4. put the 8U2 into USB DFU mode:
     4.a. assert and hold the 8U2's RESET line
     4.b. assert and hold the 8U2's HWB line
     4.c. release the 8U2's RESET line
     4.d. release the 8U2's HWB line
     The device became USB DFU

Hardware, drivers installation:
  • Arduino Uno: drivers are on arduino-0020\drivers
  • Arduino Uno DFU: drivers are on Atmel\Flip 3.4.2\usb

Verify the board
Upload blink program on your uno to check that the board is working fine.

Compile firmware
  • To be sure that's working i change a line in Descriptors.c:
    UnicodeString          = L"Arduino Uno"  by UnicodeString          = L"ArduINo UNO"
  • Open WinAvr/Programmer Notepad
  • Load makefile
  • I modify LUFA_PATH => LUFA_PATH = ../../
  • You should have to modify ARDUINO_MODEL_PID if you use MEGA
  • Do Tools[ch8594]Make clean
  • Do Tools[ch8594]Make all

Upload Arduino-usbserial.hex on the board
  • make sure the board is in DFU mode
  • Start Flip
  • Select the device AT90USB82  (not the ATmega8u2!!)
  • Open usb communication
  • Select Load Hex file
  • Program target device memory

Unplug the board and re-plug
The Name of the board should have changed : it becomes "ArduINo UNO"

Verify the board
Upload blink program on your uno to check that the board is still working fine.

That's all!



This is the next step : how to make a joytick emulator with the arduino-uno.

First step
Be sure to be able to upload the initial firwmare arduino-serial: we need this firmware to upload the Atmega328.

How it works
The Atmega328 sends to 8u2 a byte on serial communication that represents the state of the joystick.

Point of attention
It's important to load first the atmega328 program and then the 8u2 firmware.
Once the firmware of 8u2 is upload with joystick program, atmega328 can't be loaded.
In order to modify atmega328 program, the original firmware of 8u2 need to be re-loaded.

Atmega328 program
Code: [Select]
Program test for arduino uno
8u2 firmware-> Usb Joystick
6 oct 2010

void setup()

void loop()

void send_byte(boolean JOY_UP, boolean JOY_DOWN,
               boolean JOY_LEFT, boolean JOY_RIGHT,
               boolean JOY_PRESS, boolean BUTTONS_BUTTON1)
 byte byte_to_send;// use a 'byte' not a 'int'-> a int will send 3 bytes via serial
 byte_to_send= JOY_UP*32 + JOY_DOWN *16  +
               JOY_LEFT*8 + JOY_RIGHT*4 +
               JOY_PRESS*2 +  BUTTONS_BUTTON1*1;
 delay(1000);//delay 1s before send another byte

8u2 program
  • copy  the folder LUFA_100807\Demos\Device\ClassDriver\Joystick to LUFA_100807\Projects\Arduino-Joystick
  • copy the following files from arduino-0021\hardware\arduino\firmwares\arduino-usbserial\ to LUFA_100807\Projects\Arduino-Joystick
    • folder 'Lib'
    • folder 'Board'
    • file makefile

Changes to make
     In makefile
            Set TARGET = Joystick
     In Joystick.h
            Delete #include <LUFA/Drivers/Board/Joystick.h>
            Delete #include <LUFA/Drivers/Board/Buttons.h>
    In Joystick.c
            Add this on the begining:
Code: [Select]
#include <LUFA/Drivers/Peripheral/Serial.c>
uint8_t temp;
const uint8_t JOY_UP= 0b100000;
const uint8_t JOY_DOWN = 0b010000;
const uint8_t JOY_LEFT= 0b001000;
const uint8_t JOY_RIGHT= 0b000100;
const uint8_t JOY_PRESS= 0b000010;
const uint8_t BUTTONS_BUTTON1= 0b000001;

            Add this in void SetupHardware(void)
Code: [Select]
 Serial_Init(9600, false);

            I delete clock_prescale_set(clock_div_1); because this line can't compile. I don't know if it is usefull ??
            I also delete

           I add this in  for( ;;; )
Code: [Select]
while (Serial_IsCharReceived())
           Serial_TxByte(temp);// Sendback the same byte juste for information

                And finally replace the content of CALLBACK_HID_Device_CreateHIDReport by that
Code: [Select]
USB_JoystickReport_Data_t* JoystickReport = (USB_JoystickReport_Data_t*)ReportData;

uint8_t JoyStatus_LCL    =temp; //Joystick_GetStatus();

     if (JoyStatus_LCL & JOY_UP)
            JoystickReport->Y = -100;
       else if (JoyStatus_LCL & JOY_DOWN)
             JoystickReport->Y =  100;

      if (JoyStatus_LCL & JOY_LEFT)
             JoystickReport->X = -100;
      else if (JoyStatus_LCL & JOY_RIGHT)
             JoystickReport->X =  100;

      if (JoyStatus_LCL & JOY_PRESS)
             JoystickReport->Button  = (1 << 1);

      if (JoyStatus_LCL & BUTTONS_BUTTON1)
              JoystickReport->Button |= (1 << 0);

     *ReportSize = sizeof(USB_JoystickReport_Data_t);
       return false;

Then compile and upload this program on 8u2

You can verify that it is working by unplug and replug the usb connection.

The joystick is visible in configuration pannel / gamepad.

Comment : I have had some difficulties with Flip : I often had the error 'Address is out of range'. I don't really now why?? Does someone have an idea?


Thanks ant.b.  I was supposed to write a tutorial like this one but didn't get to it yet.  I linked here from the Arduino Uno page (under the programming section).


I had trouble with the arduino-0021 version of arduino-usbserial.  After building and programming it onto the 8U2 the Windows would ask to install drivers for the new device.  After pointing the installation to the arduino drivers directory windows would report a failure in driver installation.  The Arduino IDE would not recognize the UNO after that...  :-/  I compiled the 0020 version and my UNO is back in action...   8-)

I noticed in the 0021 release mentioned tweaks to PID/VID values... wondering if that has something to do with it.  I don't have time to look at it tonight it's 12:50am   :P

Great tutorial ant.b!  Can't wait to try the joystick version tomorrow.

Go Up