2013-01-26 09:34:33 +00:00
|
|
|
###| CMAKE Kiibohd Controller |###
|
|
|
|
#
|
2014-03-31 08:07:48 +00:00
|
|
|
# Jacob Alexander 2011-2014
|
2013-01-26 09:34:33 +00:00
|
|
|
# Due to this file's usefulness:
|
|
|
|
#
|
|
|
|
# Released into the Public Domain
|
|
|
|
#
|
|
|
|
# avr-gcc CMake Build Configuration
|
|
|
|
#
|
|
|
|
###
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#| Set the Compilers (must be set first)
|
|
|
|
include( CMakeForceCompiler )
|
|
|
|
cmake_force_c_compiler ( avr-gcc AVRCCompiler )
|
|
|
|
cmake_force_cxx_compiler( avr-g++ AVRCxxCompiler )
|
2014-04-19 04:58:14 +00:00
|
|
|
set( _CMAKE_TOOLCHAIN_PREFIX avr- )
|
2013-01-26 09:34:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
###
|
|
|
|
# Atmel Defines and Linker Options
|
|
|
|
#
|
|
|
|
|
|
|
|
#| MCU Name
|
|
|
|
#|
|
|
|
|
#| "at90usb162" # Teensy 1.0
|
|
|
|
#| "atmega32u4" # Teensy 2.0
|
|
|
|
#| "at90usb646" # Teensy++ 1.0
|
|
|
|
#| "at90usb1286" # Teensy++ 2.0
|
2014-04-19 05:57:14 +00:00
|
|
|
|
|
|
|
set( MCU "${CHIP}" )
|
2013-01-26 09:34:33 +00:00
|
|
|
|
2013-01-26 20:43:59 +00:00
|
|
|
message( STATUS "MCU Selected:" )
|
|
|
|
message( "${MCU}" )
|
|
|
|
|
2013-01-26 09:34:33 +00:00
|
|
|
|
2014-08-15 17:42:12 +00:00
|
|
|
#| Indicate to later build step that this is a Teensy
|
|
|
|
set( Teensy )
|
|
|
|
|
|
|
|
|
2014-04-19 07:10:28 +00:00
|
|
|
#| Chip Size Database
|
|
|
|
#| Teensy 1.0
|
|
|
|
if ( "${CHIP}" MATCHES "at90usb162" )
|
|
|
|
set( SIZE_RAM 512 )
|
|
|
|
set( SIZE_FLASH 15872 )
|
|
|
|
|
|
|
|
#| Teensy 2.0
|
|
|
|
elseif ( "${CHIP}" MATCHES "atmega32u4" )
|
|
|
|
set( SIZE_RAM 2560 )
|
|
|
|
set( SIZE_FLASH 32256 )
|
|
|
|
|
|
|
|
#| Teensy++ 1.0
|
|
|
|
elseif ( "${CHIP}" MATCHES "at90usb646" )
|
|
|
|
set( SIZE_RAM 4096 )
|
|
|
|
set( SIZE_FLASH 64512 )
|
|
|
|
|
|
|
|
#| Teensy++ 2.0
|
|
|
|
elseif ( "${CHIP}" MATCHES "at90usb1286" )
|
|
|
|
set( SIZE_RAM 8192 )
|
|
|
|
set( SIZE_FLASH 130048 )
|
|
|
|
|
|
|
|
#| Unknown AVR
|
|
|
|
else ()
|
|
|
|
message( AUTHOR_WARNING "CHIP: ${CHIP} - Unknown AVR microcontroller" )
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
|
2014-09-15 02:27:22 +00:00
|
|
|
#| Only Teensy based AVRs supported
|
|
|
|
set ( TEENSY 1 )
|
|
|
|
|
|
|
|
|
2013-01-26 09:34:33 +00:00
|
|
|
#| Extra Compiler Sources
|
|
|
|
#| Mostly for convenience functions like interrupt handlers
|
|
|
|
set( COMPILER_SRCS
|
|
|
|
# XXX Not needed for avr-gcc
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2014-03-31 08:07:48 +00:00
|
|
|
#| CPU Type
|
|
|
|
#| This is only informational for AVR microcontrollers
|
|
|
|
#| The field can be determined by the microcontroller chip, but currently only one CPU type is used atm
|
|
|
|
set( CPU "megaAVR" )
|
|
|
|
|
|
|
|
message( STATUS "CPU Selected:" )
|
|
|
|
message( "${CPU}" )
|
|
|
|
|
|
|
|
|
2013-02-02 01:02:55 +00:00
|
|
|
#| USB Defines
|
2014-08-15 17:42:12 +00:00
|
|
|
set( VENDOR_ID "0x1C11" )
|
|
|
|
set( PRODUCT_ID "0xB04D" )
|
|
|
|
set( BOOT_VENDOR_ID "0x16C0" ) # TODO Double check, this is likely incorrect
|
|
|
|
set( BOOT_PRODUCT_ID "0x047D" )
|
2013-02-02 01:02:55 +00:00
|
|
|
|
|
|
|
|
2013-01-26 09:34:33 +00:00
|
|
|
#| Compiler flag to set the C Standard level.
|
|
|
|
#| c89 = "ANSI" C
|
|
|
|
#| gnu89 = c89 plus GCC extensions
|
|
|
|
#| c99 = ISO C99 standard (not yet fully implemented)
|
|
|
|
#| gnu99 = c99 plus GCC extensions
|
|
|
|
set( CSTANDARD "-std=gnu99" )
|
|
|
|
|
|
|
|
|
|
|
|
#| Warning Options
|
|
|
|
#| -Wall...: warning level
|
2014-03-31 08:07:48 +00:00
|
|
|
set( WARN "-Wall" )
|
2013-01-26 09:34:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
#| Tuning Options
|
|
|
|
#| -f...: tuning, see GCC manual and avr-libc documentation
|
2013-02-02 01:02:55 +00:00
|
|
|
#| NOTE: -fshort-wchar is specified to allow USB strings be passed conveniently
|
2013-02-02 01:30:14 +00:00
|
|
|
set( TUNING "-funsigned-char -funsigned-bitfields -ffunction-sections -fpack-struct -fshort-enums" )
|
2013-01-26 09:34:33 +00:00
|
|
|
|
|
|
|
|
2014-03-31 08:07:48 +00:00
|
|
|
#| Optimization level, can be [0, 1, 2, 3, s].
|
2013-01-26 09:34:33 +00:00
|
|
|
#| 0 = turn off optimization. s = optimize for size.
|
|
|
|
#| (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
|
|
|
|
set( OPT "s" )
|
|
|
|
|
|
|
|
|
|
|
|
#| Output Format
|
|
|
|
#| srec, ihex, binary
|
|
|
|
set( FORMAT "ihex" )
|
|
|
|
|
|
|
|
|
|
|
|
#| Processor frequency.
|
|
|
|
#| Normally the first thing your program should do is set the clock prescaler,
|
|
|
|
#| so your program will run at the correct speed. You should also set this
|
|
|
|
#| variable to same clock speed. The _delay_ms() macro uses this, and many
|
|
|
|
#| examples use this variable to calculate timings. Do not add a "UL" here.
|
|
|
|
set( F_CPU "16000000" )
|
|
|
|
|
|
|
|
|
|
|
|
#| Dependency Files
|
|
|
|
#| Compiler flags to generate dependency files.
|
|
|
|
set( GENDEPFLAGS "-MMD -MP" )
|
|
|
|
|
|
|
|
|
|
|
|
#| Compiler Flags
|
2013-02-02 01:02:55 +00:00
|
|
|
add_definitions( "-mmcu=${MCU} -DF_CPU=${F_CPU} -D_${MCU}_=1 -O${OPT} ${TUNING} ${WARN} ${CSTANDARD} ${GENDEPFLAGS}" )
|
2013-01-26 09:34:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
#| Linker Flags
|
2014-06-26 07:54:39 +00:00
|
|
|
set( LINKER_FLAGS "-mmcu=${MCU} -Wl,-Map=link.map,--cref -Wl,--relax -Wl,--gc-sections" )
|
2013-01-26 09:34:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
#| Hex Flags (XXX, CMake seems to have issues if you quote the arguments for the custom commands...)
|
|
|
|
set( HEX_FLAGS -O ${FORMAT} -R .eeprom -R .fuse -R .lock -R .signature )
|
|
|
|
|
|
|
|
|
2013-01-26 20:05:28 +00:00
|
|
|
#| Eep Flags (XXX, I've removed this target from the builds, but keeping the set line as a note)
|
2013-01-26 09:34:33 +00:00
|
|
|
set( EEP_FLAGS -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 --no-change-warnings -O ${FORMAT} )
|
|
|
|
|
|
|
|
|
|
|
|
#| Lss Flags
|
|
|
|
set( LSS_FLAGS -h -S -z )
|
|
|
|
|