2013-01-26 09:34:33 +00:00
|
|
|
###| CMAKE Kiibohd Controller |###
|
|
|
|
#
|
2014-02-03 01:33:23 +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
|
|
|
|
#
|
|
|
|
# Freescale ARM CMake Build Configuration
|
|
|
|
#
|
|
|
|
###
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#| Set the Compilers (must be set first)
|
|
|
|
include( CMakeForceCompiler )
|
2014-04-19 04:58:14 +00:00
|
|
|
cmake_force_c_compiler ( arm-none-eabi-gcc ARMCCompiler )
|
|
|
|
cmake_force_cxx_compiler( arm-none-eabi-g++ ARMCxxCompiler )
|
|
|
|
set( _CMAKE_TOOLCHAIN_PREFIX arm-none-eabi- )
|
2013-01-26 09:34:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
###
|
|
|
|
# ARM Defines and Linker Options
|
|
|
|
#
|
|
|
|
|
|
|
|
#| Chip Name (Linker)
|
|
|
|
#|
|
2014-06-15 18:09:08 +00:00
|
|
|
#| "mk20dx128" # Teensy 3.0 and McHCK mk20dx128
|
2014-02-03 01:33:23 +00:00
|
|
|
#| "mk20dx256" # Teensy 3.1
|
2013-01-26 09:34:33 +00:00
|
|
|
|
2013-01-26 20:43:59 +00:00
|
|
|
message( STATUS "Chip Selected:" )
|
|
|
|
message( "${CHIP}" )
|
2014-01-19 23:00:48 +00:00
|
|
|
set( MCU "${CHIP}" ) # For loading script compatibility
|
2013-01-26 20:43:59 +00:00
|
|
|
|
2013-01-26 09:34:33 +00:00
|
|
|
|
2014-04-19 07:10:28 +00:00
|
|
|
#| Chip Size Database
|
2014-08-15 17:42:12 +00:00
|
|
|
#| MCHCK Based
|
|
|
|
if ( "${CHIP}" MATCHES "mk20dx128vlf5" )
|
|
|
|
set( SIZE_RAM 16384 )
|
|
|
|
set( SIZE_FLASH 126976 )
|
|
|
|
|
2014-04-19 07:10:28 +00:00
|
|
|
#| Teensy 3.0
|
2014-08-15 17:42:12 +00:00
|
|
|
elseif ( "${CHIP}" MATCHES "mk20dx128" )
|
2014-04-19 07:10:28 +00:00
|
|
|
set( SIZE_RAM 16384 )
|
|
|
|
set( SIZE_FLASH 131072 )
|
|
|
|
|
|
|
|
#| Teensy 3.1
|
|
|
|
elseif ( "${CHIP}" MATCHES "mk20dx256" )
|
|
|
|
set( SIZE_RAM 65536 )
|
|
|
|
set( SIZE_FLASH 262144 )
|
|
|
|
|
|
|
|
#| Unknown ARM
|
|
|
|
else ()
|
|
|
|
message( AUTHOR_WARNING "CHIP: ${CHIP} - Unknown ARM microcontroller" )
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
|
2014-02-03 01:33:23 +00:00
|
|
|
#| Chip Base Type
|
|
|
|
#| Automatically chosed based on the chip name.
|
|
|
|
if ( "${CHIP}" MATCHES "^mk20dx.*$" )
|
|
|
|
set( CHIP_FAMILY "mk20dx" )
|
|
|
|
message( STATUS "Chip Family:" )
|
|
|
|
message( "${CHIP_FAMILY}" )
|
|
|
|
else ()
|
|
|
|
message( FATAL_ERROR "Unknown chip family: ${CHIP}" )
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
|
2013-01-26 09:34:33 +00:00
|
|
|
#| CPU Type
|
|
|
|
#| You _MUST_ set this to match the board you are using
|
|
|
|
#| type "make clean" after changing this, so all files will be rebuilt
|
|
|
|
#|
|
2014-06-15 18:09:08 +00:00
|
|
|
#| "cortex-m4" # Teensy 3.0, 3.1, McHCK
|
2013-01-26 09:34:33 +00:00
|
|
|
set( CPU "cortex-m4" )
|
|
|
|
|
2013-01-26 20:43:59 +00:00
|
|
|
message( STATUS "CPU Selected:" )
|
|
|
|
message( "${CPU}" )
|
|
|
|
|
2013-01-26 09:34:33 +00:00
|
|
|
|
|
|
|
#| Extra Compiler Sources
|
|
|
|
#| Mostly for convenience functions like interrupt handlers
|
|
|
|
set( COMPILER_SRCS
|
2014-02-03 01:33:23 +00:00
|
|
|
Lib/${CHIP_FAMILY}.c
|
2013-01-27 03:30:36 +00:00
|
|
|
Lib/delay.c
|
2013-01-26 09:34:33 +00:00
|
|
|
)
|
|
|
|
|
2013-01-27 06:47:52 +00:00
|
|
|
message( STATUS "Compiler Source Files:" )
|
|
|
|
message( "${COMPILER_SRCS}" )
|
|
|
|
|
2013-01-26 09:34:33 +00:00
|
|
|
|
2014-06-15 18:09:08 +00:00
|
|
|
#| USB Defines, this is how the loader programs detect which type of chip base is used
|
2014-12-31 21:42:00 +00:00
|
|
|
message( STATUS "Bootloader Type:" )
|
2014-08-15 17:42:12 +00:00
|
|
|
if ( "${CHIP}" MATCHES "mk20dx128vlf5" )
|
|
|
|
set( VENDOR_ID "0x1C11" )
|
|
|
|
set( PRODUCT_ID "0xB04D" )
|
|
|
|
set( BOOT_VENDOR_ID "0x1C11" )
|
|
|
|
set( BOOT_PRODUCT_ID "0xB007" )
|
|
|
|
set( DFU 1 )
|
2014-12-31 21:42:00 +00:00
|
|
|
message( "dfu" )
|
2014-08-15 17:42:12 +00:00
|
|
|
elseif ( "${CHIP}" MATCHES "mk20dx128" OR "${CHIP}" MATCHES "mk20dx256" )
|
|
|
|
set( VENDOR_ID "0x1C11" )
|
|
|
|
set( PRODUCT_ID "0xB04D" )
|
|
|
|
set( BOOT_VENDOR_ID "0x16c0" ) # TODO Double check, this is likely incorrect
|
|
|
|
set( BOOT_PRODUCT_ID "0x0487" )
|
|
|
|
set( TEENSY 1 )
|
2014-12-31 21:42:00 +00:00
|
|
|
message( "Teensy" )
|
2014-06-15 18:09:08 +00:00
|
|
|
endif ()
|
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
|
2014-08-15 17:42:12 +00:00
|
|
|
#| gnu11 = c11 plus GCC extensions
|
|
|
|
set( CSTANDARD "-std=gnu11" )
|
2013-01-26 09:34:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
#| Warning Options
|
|
|
|
#| -Wall...: warning level
|
2014-08-15 17:42:12 +00:00
|
|
|
set( WARN "-Wall -ggdb3" )
|
2013-01-26 09:34:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
#| Tuning Options
|
|
|
|
#| -f...: tuning, see GCC manual
|
2013-02-02 01:02:55 +00:00
|
|
|
#| NOTE: -fshort-wchar is specified to allow USB strings be passed conveniently
|
2014-08-15 17:42:12 +00:00
|
|
|
if( BOOTLOADER )
|
2014-09-15 03:07:40 +00:00
|
|
|
set( TUNING "-D_bootloader_ -Wno-main -msoft-float -mthumb -fplan9-extensions -ffunction-sections -fdata-sections -fno-builtin -fstrict-volatile-bitfields -flto -fno-use-linker-plugin -nostdlib" )
|
2014-08-15 17:42:12 +00:00
|
|
|
#set( TUNING "-mthumb -fdata-sections -ffunction-sections -fno-builtin -msoft-float -fstrict-volatile-bitfields -flto -fno-use-linker-plugin -fwhole-program -Wno-main -nostartfiles -fplan9-extensions -D_bootloader_" )
|
|
|
|
else()
|
|
|
|
set( TUNING "-mthumb -nostdlib -fdata-sections -ffunction-sections -fshort-wchar -fno-builtin -nostartfiles" )
|
|
|
|
endif()
|
2013-01-26 09:34:33 +00:00
|
|
|
|
|
|
|
|
2014-02-03 01:33:23 +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.)
|
|
|
|
set( OPT "s" )
|
|
|
|
|
|
|
|
|
|
|
|
#| 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 "48000000" )
|
|
|
|
|
|
|
|
|
|
|
|
#| Dependency Files
|
|
|
|
#| Compiler flags to generate dependency files.
|
|
|
|
set( GENDEPFLAGS "-MMD" )
|
|
|
|
|
|
|
|
|
|
|
|
#| Compiler Flags
|
2013-02-02 01:02:55 +00:00
|
|
|
add_definitions( "-mcpu=${CPU} -DF_CPU=${F_CPU} -D_${CHIP}_=1 -O${OPT} ${TUNING} ${WARN} ${CSTANDARD} ${GENDEPFLAGS}" )
|
2013-01-26 09:34:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
#| Linker Flags
|
2014-08-15 17:42:12 +00:00
|
|
|
if( BOOTLOADER )
|
|
|
|
# Bootloader linker flags
|
|
|
|
set( LINKER_FLAGS "${TUNING} -Wl,--gc-sections -fwhole-program -T${CMAKE_CURRENT_SOURCE_DIR}/../Lib/${CHIP}.bootloader.ld -nostartfiles -Wl,-Map=link.map" )
|
|
|
|
else()
|
|
|
|
# Normal linker flags
|
2014-09-15 03:07:40 +00:00
|
|
|
set( LINKER_FLAGS "${TUNING} -Wl,-Map=link.map,--cref -Wl,--gc-sections -Wl,--no-wchar-size-warning -T${CMAKE_CURRENT_SOURCE_DIR}/Lib/${CHIP}.ld" )
|
2014-08-15 17:42:12 +00:00
|
|
|
endif()
|
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...)
|
2014-06-15 18:09:08 +00:00
|
|
|
set( HEX_FLAGS -O ihex -R .eeprom )
|
|
|
|
|
|
|
|
|
|
|
|
#| Binary Flags
|
|
|
|
set( BIN_FLAGS -O binary )
|
2013-01-26 09:34:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
#| Lss Flags
|
|
|
|
set( LSS_FLAGS -h -S -z )
|
|
|
|
|