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.protocol=avr109
leonardo.upload.maximum_size=16384 <---- changed the size based on the flash available
leonardo.upload.speed=57600
leonardo.upload.disable_flushing=true
leonardo.bootloader.low_fuses=0xff
leonardo.bootloader.high_fuses=0xd8
leonardo.bootloader.extended_fuses=0xcb
leonardo.bootloader.path=caterina
leonardo.bootloader.file=Caterina-Leonardo.hex
leonardo.bootloader.unlock_bits=0x3F
leonardo.bootloader.lock_bits=0x2F
leonardo.build.mcu=atmega16u4 <----------- changed the mcu to the desired one
leonardo.build.f_cpu=16000000L
leonardo.build.vid=0x2341
leonardo.build.pid=0x8036
leonardo.build.core=arduino
leonardo.build.variant=leonardo
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.
*)tools/avr/etc/avrdude.conf
I added a new device description for Atmega16u4 based on the Atmega32U4, just changed the signature, id, desc, some flash and eeprom definitions.
*)avr/avr/include/avr/io.h
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;
ISR(TIMER1_COMPA_vect, ISR_BLOCK)
{
/* 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))
TX_LED_OFF();
if (RxLEDPulse && !(--RxLEDPulse))
RX_LED_OFF();
if (pgm_read_word(0) != 0xFFFF) <<<<<<<<<<<----------- maybe this is not ok.
Timeout++;
}
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