Skip to content

Commit

Permalink
Add support for LTO
Browse files Browse the repository at this point in the history
  • Loading branch information
MCUdude committed Oct 6, 2016
1 parent 3c5c11f commit 0d5a359
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 12 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ If you're into "pure" AVR programming, I'm happy to tell you that all relevant k
* [Supported microcontrollers](#supported-microcontrollers)
* [Supported clock frequencies](#supported-clock-frequencies)
* [BOD option](#bod-option)
* [Link time optimization / LTO](#link-time-optimization--lto)
* [Programmers](#programmers)
* [Why add Arduino support for these microcontrollers?](#why-add-arduino-support-for-these-microcontrollers)
* [Write to own flash](#write-to-own-flash)
Expand Down Expand Up @@ -57,6 +58,11 @@ Make sure you connect an ISP programmer, and select the correct one in the "Prog
Brown out detection, or BOD for short lets the microcontroller sense the input voltage and shut down if the voltage goes below the brown out setting. The ATmega8, ATmega48, ATmega88 and ATmega168 haven't dedicated the BOD selection to extended fuse, so there's no way to only change the BOD option in the Arduino IDE. If you need to change this setting you'll have to edit the boards.txt file.


##Link time optimization / LTO
After Arduino IDE 1.6.11 where released, There have been support for link time optimization or LTO for short. The LTO optimizes the code at link time, making the code (often) significantly smaller without making it "slower". In Arduino IDE 1.6.11 and newer LTO is enabled by default. I've chosen to disable this by default to make sure the core keep its backwards compatibility. Enabling LTO in IDE 1.6.10 and older will return an error.
I encourage you to try the new LTO option and see how much smaller your code gets! Note that you don't need to hit "Burn Bootloader" in order to enable LTO. Simply enable it in the "Tools" menu, and your code is ready for compilation. If you want to read more about LTO and GCC flags in general, head over to the [GNU GCC website](https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html)!


##Programmers
Mini does not adds its own copies of all the standard programmers to the "Programmer" menu. Just select one of the stock programmers in the "Programmers" menu, and you're ready to "Burn Bootloader" or "Upload Using Programmer".

Expand Down
110 changes: 99 additions & 11 deletions avr/boards.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
# MiniCore - An Arduino core for the ATmega48/P, ATmega8, ATmega88/P, ATmega168/P, ATmega328/P
# https://github.com/MCUdude/MiniCore
# Run ./makeall to build all bootloaders

##########################################
## This file is created by MCUdude
## for use with MiniCore
## https://github.com/MCUdude/MiniCore
##
## This is the file where fuse settings,
## clock frequencies and compiler flags
## are located.
##
## Run ./makeall to build all bootloaders
##########################################

# Menu options
menu.variant=Variant
menu.clock=Clock
menu.BOD=B.O.D

menu.BOD=BOD
menu.LTO=Compiler LTO

############################################################
##########################
#### ATmega328/A/P/PA ####
##########################

328.name=ATmega328
328.upload.tool=avrdude
Expand All @@ -23,11 +34,13 @@ menu.BOD=B.O.D
328.build.board=AVR_ATmega328
328.build.variant=standard

# Variants
328.menu.variant.modelP=328P / 328PA
328.menu.variant.modelP.build.mcu=atmega328p
328.menu.variant.modelNonP=328 / 328A
328.menu.variant.modelNonP.build.mcu=atmega328

# Brown out detection
328.menu.BOD.2v7=2.7v
328.menu.BOD.2v7.bootloader.extended_fuses=0xfd
328.menu.BOD.4v3=4.3v
Expand All @@ -37,7 +50,20 @@ menu.BOD=B.O.D
328.menu.BOD.disabled=Disabled
328.menu.BOD.disabled.bootloader.extended_fuses=0xff

# Compiler link time optimization
328.menu.LTO.Os=Disabled (default)
328.menu.LTO.Os.compiler.c.extra_flags=
328.menu.LTO.Os.compiler.c.elf.extra_flags=
328.menu.LTO.Os.compiler.cpp.extra_flags=
328.menu.LTO.Os.ltoarcmd=avr-ar

328.menu.LTO.Os_flto=Enabled
328.menu.LTO.Os_flto.compiler.c.extra_flags=-Wextra -flto
328.menu.LTO.Os_flto.compiler.c.elf.extra_flags=-w -flto
328.menu.LTO.Os_flto.compiler.cpp.extra_flags=-Wextra -flto
328.menu.LTO.Os_flto.ltoarcmd=avr-gcc-ar

# Clock frequencies
#make atmega328p AVR_FREQ=16000000L BAUD_RATE=115200 LED=B5 LED_START_FLASHES=2
#make atmega328 AVR_FREQ=16000000L BAUD_RATE=115200 LED=B5 LED_START_FLASHES=2
328.menu.clock.16MHz_external=16 MHz external
Expand Down Expand Up @@ -97,7 +123,9 @@ menu.BOD=B.O.D
328.menu.clock.1MHz_internal.build.f_cpu=1000000L


############################################################
##########################
#### ATmega168/A/P/PA ####
##########################

168.name=ATmega168
168.upload.tool=avrdude
Expand All @@ -113,12 +141,26 @@ menu.BOD=B.O.D
168.build.board=AVR_ATmega168
168.build.variant=standard

# Variants
168.menu.variant.modelP=168P / 168PA
168.menu.variant.modelP.build.mcu=atmega168p
168.menu.variant.modelNonP=168 / 168A
168.menu.variant.modelNonP.build.mcu=atmega168

# Compiler link time optimization
168.menu.LTO.Os=Disabled (default)
168.menu.LTO.Os.compiler.c.extra_flags=
168.menu.LTO.Os.compiler.c.elf.extra_flags=
168.menu.LTO.Os.compiler.cpp.extra_flags=
168.menu.LTO.Os.ltoarcmd=avr-ar

168.menu.LTO.Os_flto=Enabled
168.menu.LTO.Os_flto.compiler.c.extra_flags=-Wextra -flto
168.menu.LTO.Os_flto.compiler.c.elf.extra_flags=-w -flto
168.menu.LTO.Os_flto.compiler.cpp.extra_flags=-Wextra -flto
168.menu.LTO.Os_flto.ltoarcmd=avr-gcc-ar

# Clock frequencies
#make atmega168p AVR_FREQ=16000000L BAUD_RATE=115200 LED=B5 LED_START_FLASHES=2
#make atmega168 AVR_FREQ=16000000L BAUD_RATE=115200 LED=B5 LED_START_FLASHES=2
168.menu.clock.16MHz_external=16 MHz external (BOD 2.7v)
Expand Down Expand Up @@ -184,7 +226,9 @@ menu.BOD=B.O.D
168.menu.clock.1MHz_internal.build.f_cpu=1000000L


############################################################
#########################
#### ATmega88/A/P/PA ####
#########################

88.name=ATmega88
88.upload.tool=avrdude
Expand All @@ -200,12 +244,26 @@ menu.BOD=B.O.D
88.build.board=AVR_ATmega88
88.build.variant=standard

# Variants
88.menu.variant.modelP=88P / 88PA
88.menu.variant.modelP.build.mcu=atmega88p
88.menu.variant.modelNonP=88 / 88A
88.menu.variant.modelNonP.build.mcu=atmega88

# Compiler link time optimization
88.menu.LTO.Os=Disabled (default)
88.menu.LTO.Os.compiler.c.extra_flags=
88.menu.LTO.Os.compiler.c.elf.extra_flags=
88.menu.LTO.Os.compiler.cpp.extra_flags=
88.menu.LTO.Os.ltoarcmd=avr-ar

88.menu.LTO.Os_flto=Enabled
88.menu.LTO.Os_flto.compiler.c.extra_flags=-Wextra -flto
88.menu.LTO.Os_flto.compiler.c.elf.extra_flags=-w -flto
88.menu.LTO.Os_flto.compiler.cpp.extra_flags=-Wextra -flto
88.menu.LTO.Os_flto.ltoarcmd=avr-gcc-ar

# Clock frequencies
#make atmega88p AVR_FREQ=16000000L BAUD_RATE=115200 LED=B5 LED_START_FLASHES=2
#make atmega88 AVR_FREQ=16000000L BAUD_RATE=115200 LED=B5 LED_START_FLASHES=2
88.menu.clock.16MHz_external=16 MHz external (BOD 2.7v)
Expand Down Expand Up @@ -271,7 +329,9 @@ menu.BOD=B.O.D
88.menu.clock.1MHz_internal.build.f_cpu=1000000L


############################################################
##########################
#### ATmega48/A/P/PA ####
##########################

48.name=ATmega48 (no bootloader)
48.upload.tool= avrdude
Expand All @@ -287,12 +347,26 @@ menu.BOD=B.O.D
48.build.board=AVR_ATmega48
48.build.variant=standard

# Variants
48.menu.variant.modelP=48P / 48PA
48.menu.variant.modelP.build.mcu=atmega48p
48.menu.variant.modelNonP=48 / 48A
48.menu.variant.modelNonP.build.mcu=atmega48

# Compiler link time optimization
48.menu.LTO.Os=Disabled (default)
48.menu.LTO.Os.compiler.c.extra_flags=
48.menu.LTO.Os.compiler.c.elf.extra_flags=
48.menu.LTO.Os.compiler.cpp.extra_flags=
48.menu.LTO.Os.ltoarcmd=avr-ar

48.menu.LTO.Os_flto=Enabled
48.menu.LTO.Os_flto.compiler.c.extra_flags=-Wextra -flto
48.menu.LTO.Os_flto.compiler.c.elf.extra_flags=-w -flto
48.menu.LTO.Os_flto.compiler.cpp.extra_flags=-Wextra -flto
48.menu.LTO.Os_flto.ltoarcmd=avr-gcc-ar

# Clock frequencies
#make atmega48p AVR_FREQ=16000000L BAUD_RATE=115200 LED=B5 LED_START_FLASHES=2
#make atmega48 AVR_FREQ=16000000L BAUD_RATE=115200 LED=B5 LED_START_FLASHES=2
48.menu.clock.16MHz_external=16 MHz external (BOD 2.7v)
Expand Down Expand Up @@ -357,8 +431,10 @@ menu.BOD=B.O.D
48.menu.clock.1MHz_internal.bootloader.file=empty/empty.hex
48.menu.clock.1MHz_internal.build.f_cpu=1000000L

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

###################
#### ATmega8/A ####
###################

8.name=ATmega8
8.upload.tool=avrdude
Expand All @@ -375,8 +451,20 @@ menu.BOD=B.O.D
8.build.variant=standard
8.build.mcu=atmega8

# Compiler link time optimization
8.menu.LTO.Os=Disabled (default)
8.menu.LTO.Os.compiler.c.extra_flags=
8.menu.LTO.Os.compiler.c.elf.extra_flags=
8.menu.LTO.Os.compiler.cpp.extra_flags=
8.menu.LTO.Os.ltoarcmd=avr-ar

8.menu.LTO.Os_flto=Enabled
8.menu.LTO.Os_flto.compiler.c.extra_flags=-Wextra -flto
8.menu.LTO.Os_flto.compiler.c.elf.extra_flags=-w -flto
8.menu.LTO.Os_flto.compiler.cpp.extra_flags=-Wextra -flto
8.menu.LTO.Os_flto.ltoarcmd=avr-gcc-ar

# Clock frequencies
#make atmega8 AVR_FREQ=16000000L BAUD_RATE=115200 LED=B5 LED_START_FLASHES=2
8.menu.clock.16MHz_external=16 MHz external (BOD 2.7v)
8.menu.clock.16MHz_external.upload.speed=115200
Expand Down
2 changes: 1 addition & 1 deletion avr/platform.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ compiler.c.elf.cmd=avr-gcc
compiler.S.flags=-c -g -x assembler-with-cpp
compiler.cpp.cmd=avr-g++
compiler.cpp.flags=-c -g -Os {compiler.warning_flags} -std=gnu++11 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD
compiler.ar.cmd=avr-ar
compiler.ar.cmd={ltoarcmd}
compiler.ar.flags=rcs
compiler.objcopy.cmd=avr-objcopy
compiler.objcopy.eep.flags=-O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0
Expand Down

0 comments on commit 0d5a359

Please sign in to comment.