Go Down

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

ant.b

Oct 01, 2010, 09:53 pm Last Edit: Oct 01, 2010, 11:50 pm by ant.b Reason: 1
Hi
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.

Source
I use the following sources:
http://arduino.cc/en/Main/ArduinoBoardUno
http://arduino.cc/blog/2010/09/27/arduino-0020-released-for-windows-and-mac-supports-uno-and-mega-2560/
http://www.ladyada.net/library/arduino/unofaq.html
http://arduino.cc/en/uploads/Main/arduino-uno-schematic.pdf

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

Hardware:
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

Test
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!

sxdemon


ant.b

Hi,
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
ant.b
6 oct 2010
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1285962838
*/

void setup()
{
 Serial.begin(9600);
}

void loop()
{
send_byte(0,0,0,0,0,0);
send_byte(1,0,0,0,0,0);
send_byte(0,1,0,0,0,0);
send_byte(0,0,1,0,0,0);
send_byte(0,0,0,1,0,0);
send_byte(0,0,0,0,1,0);
send_byte(0,0,0,0,0,1);
}

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;
 Serial.print(byte_to_send);  
 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
              Joystick_Init();
                   Buttons_Init();

           I add this in  for( ;;; )
           
Code: [Select]
while (Serial_IsCharReceived())
               {
           temp=Serial_RxByte();
           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

Verify
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?

mellis

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).

majolsurf

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.

majolsurf

Update:  In the arduino-0021 version of arduino-usbserial the Descriptor.c file is using VID = 0x03EB (Atmel) and PID = 0x204B (LUFA USBtoSerial demo).    The Arduino UNO.inf is looking for VID=0x2341 and PID=0x0001 which is reflected in arduino-0020...  

I see in the 0021 release notes indicate "Modifying VID / PID combination in 8U2 firmwares" but was this the intent?

mellis

According to the USB folks, we're not really allowed to share our VID / PIDs with other organizations.  So the firmware was modified to use other ones.  Probably we should create a different version of the .inf file that uses the other VID/PID pair.  The intent is that any VID/PID pair should work with the IDE, but that the Arduino ones should only be used with the official Arduino hardware.

tjhowse

Awesome work! I wasn't looking forward to working out all this stuff on my own.

The only problem I've encountered is loading the DFU drivers in windows 7. It seems they aren't signed so win7 refuses to allow access to the device via Flip. I had to install it on an XP machine before I could write my newly compiled .hex to the 8U2.

There are ways of making win7 load unsigned drivers in test mode, but this is cumbersome.

mellis

You can also use an ISP to update the 8U2 firmware, if you have one.

anv

#9
Oct 29, 2010, 04:14 pm Last Edit: Oct 29, 2010, 04:17 pm by anv Reason: 1
It would be great if the software on the ATmega8u2 had various usb "personalities" included, selectable by software on the 328.

You could send some special string to 328 to swithch it from usb-serial mode to usb-keyboard mode or usb-joystick mode.

Then, there will be no need to upload new software to the 8u2.

When power off it could return to the default usb-serial mode.

stimmer

Here's a way to get the Uno into DFU mode without any soldering. Put two wires into GND pins on either side of the board. Then put the other ends of the wires on the board as follows:



The sequence is, hold the first wire on the top left 8u2 ICSP pad, then touch the second wire against the left side of the capacitor below the RX LED. Then remove both wires. It's slightly different to the sequence in the instructions but it seems to work.

Be careful with the second wire as the capacitor is quite near a 5v track. You can try using a low-value resistor instead of a wire if you are worried about blowing up your board.

To get back to normal mode, hold wire 1 in place as above, press the reset button, then remove wire 1. Or just unplug the USB cable and plug it back in.
Due VGA library - http://arduino.cc/forum/index.php/topic,150517.0.html

Ranking

I doesen'T have an Arduino Uno only a nano does someone know how I can use this code on an Arduino nano 3.0

it would be realy great if anyone has an answer for me ;D

PaulS

Quote
does someone know how I can use this code on an Arduino nano 3.0

Can you post a picture of your nano with a ATMega8U2 chip on it?

tjhowse

Found a solution to my problem:

http://www.avrfreaks.net/index.php?module=Freaks%20Files&func=viewFile&id=3842&showinfo=1

These drivers were signed by some generous avrfreak, and work with the Uno under Win7 64b. Happy days!

Australian Robotics


Go Up