Made My Own Arduino Board - ATMEGA32U4 - Bootloader Questions

Hey Guys,

I am an Arduino Newb, but been in electronics for quite some time. I am by experience a HW designer (ASICS, FPGA, etc.). I made my own board ..based off using the ATMEGA32U4(Leonardo was my reference). My board is up and working, but I need to get a bootloader into it. I have quite rusty on programmerMCU's, so I need some guidance.

I also have the ATMEGA2560 (own it), but I only know of Leonardo by schematic, and it seems to be different that the other mainstream boards.

With the ATMEGA2560, it has another ATMEGA CPU for the USB-programming of arduino sketches. But with the leonardo, it uses a direct USB connection. S

I got my board on the jtag (AVR JTAGICE MKII), and Ican read and write to it...and I erased the original AVR bootloader on it and put on a bootloader what I thought was a leonardo bootloader that I found online.

WHERE IS THE LEONARDO/ATMEGA32U4 BOOTLOADER FOR ARDUINO? I found a file in thje arduino directory called Caterina-Leonardo, but this hex file is 76L in size, and the flash space for the ATMEGA32U4 is only 28K, so that can't be right...is it? if so, please explain.

So if someone can please explain the bootloader stuff for this MCU..thanks in advance...

Also, so once I get the bootloader in using JTAG on AVE JTAGICE MKII, what should the arduino SW see when I plug in the USB?

please give me some guidance...

Thanks! :slight_smile:
-Peter

a .hex file is in Intel Hex format, it's ASCII, human readable, not binary. You need two ASCII characters to represent every actual byte, plus there's some overhead in the Intel Hex format to indicate address and checksums. So it's file size does not indicate the true size of memory you need.

also keep in mind, your microcontroller has 32K total, the bootloader can occupy up to 4K, thus you have 28K remaining for application. So your reasoning is wrong in your original post.

I'm not an expert on programming the ATMEGA32U4 with a bootloader, but I do know it uses the PDI programming interface, for which you need a PDI programmer. I doubt the ATMEGA2560 will do that, although possibly with a suitable programmer installed. You would need connections to PDI, PDO and SCK as described on page 361 of the datasheet. Then you need a suitable programming sequence.

I don't know where the bootloader file is. I presume it is on the Arduino code site somewhere.

http://code.google.com/p/arduino/

or, here maybe:

If that isn't it, someone else might know.

This file:

https://github.com/arduino/Arduino/blob/master/hardware/arduino/bootloaders/caterina/Caterina-Leonardo.hex

seems to have a lot of 0xFF in it. It looks a bit like it also contains some default sketch.

Once you get past all that it seems to have code at 0x7000 to 0x8000 which would be 4096 bytes (4K) which sounds right for a bootloader.

I am looking for someone who REALLY knows the answer. Please do not reply if you don't know or may have an idea. There has to be somebody who has put the bootloader on the Leonardo Board.

Is the 'Catarina-Leonoard.hex' in the Arduino folder the legit arduino bootloader?

Why is this file 78KB if a bootloader is only ~4KB?

Thanks for the support,
-Peter

Why is this file 78KB if a bootloader is only ~4KB?

I explained that. What part of the explanation did you not understand?

To repeat part of my explanation ...

Most of that file is just putting 0xFF into memory (filler in other words):

:20602000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF80
:20604000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF60
:20606000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF40
:20608000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF20
:2060A000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00

Plus since this is "readable" hex it will take 2 bytes in the file to put one byte into memory. Plus there is the address, the length, the sumcheck, etc. per line.

@MrBeef

great attitude, I'm sure you'll make a lot of friends around here :slight_smile:

I would appreciate if you had a nicer way to deal with the people who are here to help you AND gave you a perfectly good answer.

Nick , as usual, is right. re-read his answers.

m

Hey Nick,

Sorry didn't mean to be rude if it came off that way. As long as you're sure great..thanks for the help. The reason why I said that is because sometimes people on forums just babble(as the old saying goes "everything on the internet is true"). I guess I should have looked at your title and recognized you probably knew what you're saying.

So thanks on that..

So my next question is:

I made a board, which I want to use arduino SW on. It uses an ATMEGA32U4 and has basic features, but is not a copy of the Leonardo Schematic. I wish to load a bootloader for arduino, and then build support for it in Arduino using the 3rd-party as as I am supposed to.

I am a HW engineer, so I am pretty inexperienced for SW(I know C/C++, but haven't used it in 8 years), and the arduino structure.

How can I learn all of this?

So my next question is about the bootloaders...if I make a board using the ATMEGA32U4, and want to put on an Arduino bootloader, can I just use the leonardo(arduino & ATMEGA32U4)?

Here is what I did earlier just to see if I could get it working in Arduino... I found a company called MattairTech, and they have their own ATMEGA32U4. So I used a jtag programmer to load it. It seemed to work...then I installed their files into my arduino...and it can find my COM port, and the device board target. But when I go to load the board...it fails. Perhaps I am totally missing a detail or I have no idea what I am doing lol.

Let me know what you think and thank you for the help,
-Peter

This group here was one of the first to make pre-release Leonardo's.

Do some reading, see what you can figure out.
Come back with what you find.

My expectation would be that one would load a bootloader the normal way, with an AVR ISP Programmer (such as Atmel AVR ISP MKii) connected to the pins that make up the ICSP header: SCK, MOSI, MISO, Reset, Gnd, Power (Note: MKii only senses the voltage, board must be powered otherwise). (There is a mod I've seen to MKii to connect power to the Vcc header pin so it will supply power - I've not hacked mine, I just supply external power - sometimes just using a 3 AA battery pack).

Here's some discussion of the MKii mod

MrBEEF:
I made a board, which I want to use arduino SW on. It uses an ATMEGA32U4 and has basic features, but is not a copy of the Leonardo Schematic. I wish to load a bootloader for arduino, and then build support for it in Arduino using the 3rd-party as as I am supposed to.

OK, well you've taken me out of my area of expertise with this bit. I have experience uploading bootloaders using things like the AVRISP and also my own software, eg.

and:

However, all those use SPI programming, whereas your chip uses PDI. Now I don't have a hardware PDI programmer, and although I have an AVR Dragon this model doesn't (seem to) support the PDI interface.

I attempted to make a PDI programmer using a Uno, but the documentation for the protocol is somewhat sparse, and I haven't succeeded yet.

If I had one, I could download the firmware from my Leonardo, and confirm whether or not it agrees with the hex file we were discussing.

But when I go to load the board...it fails. Perhaps I am totally missing a detail or I have no idea what I am doing lol.

This part is unclear. What did you load onto what, and what connections did you make?

I've asked fm to jump in here with some of his vinciduino experience.

Hi folks, I am off to work but it sounds like the JTAG fuse is set. As soon as I get back this afternoon I will good through the thread and see if I can contribute a bit to get that bootloader going. Do you have a schematic of the wiring.

Hey fm,

Yeah I was messing with the fuses, and when I loaded a bootloader (MAttairtech CDC), the jtag shut off and didn't come back.

I think I am going to try to use my MEGA 2560 arduino to load a bootloader.

But I did attach the CPU page of the schematic, so you could see how different it is compared to a leonardo.

Cna I put the leonardo bootloader on this board and it will work the same? Is there anything inside the bootloader that would prevent me from using it? I don't know anything about booloaders.

Thanks,
-Peter

Fm, can you advise of a suitable programmer for the ATMEGA32U4 chip (assuming no bootloader)?

Sorry to answer so later, its been a looong day. For that board and layout you should be more than fine downloading the Leonardo bootloader. If you use the Arduino IDE it will write the fuses for you.
Let me know if it worked.
@Nick - I recomend the AVR ISP MkII from Atmel and any old Arduino should do the trick too. The moded AVR ISP mkIi is the one I use to flash the Leonardo bootloader to all the vinciDuinos. If you order from Digikey as part of something else you save on shipping costs.

Thanks, fm, for the encouraging remarks. I actually have an AVR ISP MkII to hand, but hadn't got it to work as a PDI programmer before. After downloading the (fairly hefty) Atmel Studio 6, I got it to work on my Leonardo.

@MrBEEF: Below is the firmware from my Leonardo. Unfortunately Atmel Studio writes out 16-byte lines (they start with hex 10) and the firmware on the page below is in 32-byte lines (they start with hex 20):

However a few spot checks at addresses above 0x7000 appear to indicate the code is the same (I only checked a few bytes but you could do a more rigorous check).

Caterina-Leonardo:

https://github.com/arduino/Arduino/blob/master/hardware/arduino/bootloaders/caterina/Caterina-Leonardo.hex

My firmware:

http://gammon.com.au/Arduino/Leonardo_firmware.hex

The first part will definitely be different as I have one of my sketches loaded on it, but the part past 0x7000 should be the bootloader.

Hey Everyone,

So here is the scenario for everyone's benefit:

*** IF YOU MADE YOUR OWN ARDUINO COMPATIBLE BOARD USING AN ATMEGA32U4, AND WISH TO GET IT TO BOOT IN ARDUINO:

  1. download winavr

  2. edit and compile the caterina bootloder files in the arduino directory, using the makefile, and editing the .h and .cpp to your own custom needs, use winavr to compile and generate the .hex for your bootloader.

  3. using an isp such as JTAGICE MKII or a different ISP, use Atmel studio to program your .hex file into your device, using jtag or the SPI

  4. Use fuse and circuit reference :

fuse references:
http://www.codingwithcody.com/2011/04/arduino-default-fuse-settings/

http://cal-eng.com/?page_id=535

circuit for isp:

Device programming can be found under the tools menu in AVR studio. Interface is pretty self explanatory. Change fuses, remove lock bits, go to the memories section browse for .hex that one generates using the caterina files and WinAVR. Edit the .cpp and .h, and the USB driver .inf for leonardo(if you have ATMEGA32U4), so it doesnt say leonardo and so on.

DOne...

-MrBEEF

BTW TO EVERYONE...

THANKS FOR THE HELP...YOUR DIRECTION CERTAINLY HELPED.

-MRBEEF