Go Down

Topic: Making bootloader for Atmega162 (Read 7322 times) previous topic - next topic

evostars


You beat me too it, I was just editing my post above.
Jj
I did just that, but doesn't the name mess
If you rename the file, it will trick the arduino IDE into uploading that file.

Hehehe, nice :P

I did just that.
But i still cant load the firmware on it... No correct device name...
I'll look into it again tomorrow.  I need sleep now...
:smiley-sleep:

evostars

Just to be shure,
how did you hookup the 162?

Tom Carpenter

UNO -> Atmega162
Miso -> Miso
Mosi -> Mosi
SS -> Reset
+5v -> VCC
GND -> GND



What happens when you try and program it?
~Tom~

evostars

OK that's what I did.

I think the problem is in my x0xb0x.

I put a brand new CPU in today, with firmware, and still... no play time.
So I'll first have to fix the x0xb0x...

I think the bootloader worked just fine.

klimenkoandrey

Hi TCWORLD
i just want to know, can you run bootloader on ATMega162 to work with Arduino IDE?

Tom Carpenter

#20
Jul 14, 2012, 02:09 pm Last Edit: Jul 14, 2012, 02:13 pm by TCWORLD Reason: 1
Yes, that is the purpose of it. It is just a modified version of the Arduino Optiboot bootloader to support the Atmega162.

The code supports both serial ports - Serial.begin() and Serial1.begin(). I have checked and they do work. It should also support PWM, but I haven't checked that. See the pins_arduino.h file to find out how the arduino pin numbers (0 to 34 inclusive) relate to the atmega162 chip pins.
Note: The atmega162 has no Analog inputs, but it does have 35 digital outputs, 6 of which work as PWMs. It has 2 serial ports, SPI, and I2C. There is however only 14kB of program space, half what an Uno has.


I found some bugs in the pins_arduino.h file, and there is also a file in the avr folder which doesn't work without a small modification. I have attached a full set of files to this post.

optiboot_atmega162.hex needs to be saved to:
<arduino>\hardware\arduino\bootloaders\optiboot\optiboot_atmega162.hex

iom162.h needs to be saved to:
<arduino>\hardware\tools\avr\avr\include\avr\iom162.h
(This replaces the existing one. There is a bug which prevents code from compiling otherwise. Changing the file won't affect anything other than the Atmega162).

pins_arduino.h needs to be saved to:
<arduino>\hardware\arduino\variants\atmega162\pins_arduino.h

Then in the <arduino>\hardware\arduino\boards.txt file, add these lines to the end:

##############################################################

atmega162.name= ATmega162

atmega162.upload.protocol=arduino
atmega162.upload.maximum_size=14336
atmega162.upload.speed=57600

atmega162.bootloader.low_fuses=0xFF
atmega162.bootloader.high_fuses=0xD8
atmega162.bootloader.extended_fuses=0xFB
atmega162.bootloader.path=optiboot
atmega162.bootloader.file=optiboot_atmega162.hex
atmega162.bootloader.unlock_bits=0x3F
atmega162.bootloader.lock_bits=0x0F

atmega162.build.mcu=atmega162
atmega162.build.f_cpu=16000000L
atmega162.build.core=arduino
atmega162.build.variant=atmega162

##############################################################
~Tom~

y3i12

Hi Tom!

You're doing an awesome Job!

I'm trying to program an ATmega162 using the Arduino IDE and the ArduinoISP, so I dont need the bootloader, but i'm having some problems that you had, for instance the problem of the missing definition of USART0_RX_vect.

Your solution is awesome, but I'd recommend to use another definition inside of Arduino.h or even in pins_arduino.h to avoid changes in iom162.h.

I made the following definitions:

Code: [Select]

#define USART0_RX_vect USART0_RXC_vect
#define USART1_RX_vect USART1_RXC_vect
#define USART0_TX_vect USART0_TXC_vect
#define USART1_TX_vect USART1_TXC_vect


Worked nicely to compile the affected files, like HardwareSerial.cpp.

Now I "just" need to be able to burn the generated code to the MCU. lol

Regards,
Yuri I.

Tom Carpenter


Your solution is awesome, but I'd recommend to use another definition inside of Arduino.h or even in pins_arduino.h to avoid changes in iom162.h.

I made the following definitions:

Code: [Select]

#define USART0_RX_vect USART0_RXC_vect
#define USART1_RX_vect USART1_RXC_vect
#define USART0_TX_vect USART0_TXC_vect
#define USART1_TX_vect USART1_TXC_vect



The reason I changed the iom162.h file directly is because Arduino doesn't actually support the 162 natively, so changing it wont do any harm to any of the other processors and examples. It just makes it easier than having to remember to #define them. But either way works :) Perhaps though you are correct, the pins_arduino.h file for it would be an ideal place to define them as you would only have to change it once...
~Tom~

Go Up