Migrating Arduino Leonardo Atmega32U4 to Atmega16U4

Hi guys,

I’m trying to migrate the actual Arduino Leonard Bootloader using the Atmega32U4 to Atmega16U4, also I’d like to be able to compile sketches.
I already changed several files like:

  • boards.txt

leonardo.name=Arduino Leonardo
leonardo.upload.maximum_size=16384 <---- changed the size based on the flash available
leonardo.build.mcu=atmega16u4 <----------- changed the mcu to the desired one

I keep the fuse bits because both hardware are pretty the same but I’m not 100% sure if I should keep them.

*) bootloaders/caterina/makefile
Changed the mcu to Atmega16U4
and the flash size FLASH_SIZE_KB = 16

*) cores/arduino
I keep the files.

*) variants/leonardo/pins_arduino.h
As I want to have different mapping I remapped 2 digital pins.

I added a new device description for Atmega16u4 based on the Atmega32U4, just changed the signature, id, desc, some flash and eeprom definitions.

Added a line for Atmega16U4.

*)Created file avr/avr/include/avr/iom16u4.h
Based on the iom32u4.h created the iom16u4.h

I also downloaded LUFA-111009.

After running these changes I was able to run the Makefile for the Leonardo bootloader, it compiled I uploaded the new bootloader to the device using my pololu avr programmer. The only issue I found was that the breathing animation (led fading) run indefinitely but I think it should run for a small period of time (8 seconds if I’m not wrong). I checked the caterina.c file and I suspect the ISR is not 100% compatible.

//uint16_t ctr = 0;
/* Reset counter */
TCNT1H = 0;
TCNT1L = 0;

/* Check whether the TX or RX LED one-shot period has elapsed. if so, turn off the LED */
if (TxLEDPulse && !(–TxLEDPulse))
if (RxLEDPulse && !(–RxLEDPulse))

if (pgm_read_word(0) != 0xFFFF) <<<<<<<<<<<----------- maybe this is not ok.

Well, I tried to compilet the blink example and the IDE gives me:

/Users/devlware/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega16u4 -DF_CPU=16000000L -MMD -DUSB_VID=0x2341 -DUSB_PID=0x8036 -DARDUINO=101 -I/Users/devlware/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino -I/Users/devlware/Arduino.app/Contents/Resources/Java/hardware/arduino/variants/leonardo /var/folders/0n/syx_x3ss64q9jq4fwxkx9p480000gn/T/build7457131111444128833.tmp/Blink.cpp -o /var/folders/0n/syx_x3ss64q9jq4fwxkx9p480000gn/T/build7457131111444128833.tmp/Blink.cpp.o
unknown MCU ‘atmega16u4’ specified
Known MCU names:

{ “” List several mcus’ }

Blink:-1: error: MCU ‘atmega16u4’ supported for assembler only
In file included from /Users/devlware/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/…/lib/gcc/avr/4.3.2/…/…/…/…/avr/include/avr/pgmspace.h:82,
from /Users/devlware/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Arduino.h:8,
from Blink.cpp:10:
/Users/devlware/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/…/lib/gcc/avr/4.3.2/…/…/…/…/avr/include/avr/io.h:332:6: warning: #warning “device type not defined”

I’m out of ideas to how fix this.

Somebody with more experience could suggest something?

Regards, Diego

Unfortunately I don't think its that easy, I tried something similiar just to work with the 328(non p) and I got the same errors, its not an easy fix for me atleast, I neve figured it out : /

Well... I'll keep searching for a solution. Thanks.

Hi Diego,

Did you have luck with bootloading the ATmega16u?

Thanks Eszter

I doubt migration will happen- Leonardo's bootloader size just fits to 32U4; it requires larger memory than 16U4 has.

What if I want to custom design my own circuit? Is this compatible? If I just burn HEX file for Leonardo on atmega16u4-AU without bootloader (by that I mean stock Atmel DFU bootloader)?