]> git.donarmstrong.com Git - kiibohd-controller.git/blob - Lib/CMake/arm.cmake
Preparing for mk20dx256vlh7
[kiibohd-controller.git] / Lib / CMake / arm.cmake
1 ###| CMAKE Kiibohd Controller |###
2 #
3 # Jacob Alexander 2011-2014
4 # Due to this file's usefulness:
5 #
6 # Released into the Public Domain
7 #
8 # Freescale ARM CMake Build Configuration
9 #
10 ###
11
12
13
14 #| Set the Compilers (must be set first)
15 include( CMakeForceCompiler )
16 cmake_force_c_compiler  ( arm-none-eabi-gcc ARMCCompiler )
17 cmake_force_cxx_compiler( arm-none-eabi-g++ ARMCxxCompiler )
18 set( _CMAKE_TOOLCHAIN_PREFIX arm-none-eabi- )
19
20
21
22 ###
23 # ARM Defines and Linker Options
24 #
25
26 #| Chip Name (Linker)
27 #|
28 #| "mk20dx128vlf5"    # McHCK / Kiibohd-dfu
29 #| "mk20dx256vlh7"    # Kiibohd-dfu
30 #| "mk20dx128"        # Teensy   3.0
31 #| "mk20dx256"        # Teensy   3.1
32
33 message( STATUS "Chip Selected:" )
34 message( "${CHIP}" )
35 set( MCU "${CHIP}" ) # For loading script compatibility
36
37
38 #| Chip Size Database
39 #| MCHCK Based / Kiibohd-dfu
40 if ( "${CHIP}" MATCHES "mk20dx128vlf5" )
41         set( SIZE_RAM    16384 )
42         set( SIZE_FLASH 126976 )
43
44 #| Kiibohd-dfu
45 elseif ( "${CHIP}" MATCHES "mk20dx256vlh7" )
46         set( SIZE_RAM    65536 )
47         set( SIZE_FLASH 253952 )
48
49 #| Teensy 3.0
50 elseif ( "${CHIP}" MATCHES "mk20dx128" )
51         set( SIZE_RAM    16384 )
52         set( SIZE_FLASH 131072 )
53
54 #| Teensy 3.1
55 elseif ( "${CHIP}" MATCHES "mk20dx256" )
56         set( SIZE_RAM    65536 )
57         set( SIZE_FLASH 262144 )
58
59 #| Unknown ARM
60 else ()
61         message( AUTHOR_WARNING "CHIP: ${CHIP} - Unknown ARM microcontroller" )
62 endif ()
63
64
65 #| Chip Base Type
66 #| Automatically chosed based on the chip name.
67 if ( "${CHIP}" MATCHES "^mk20dx.*$" )
68         set( CHIP_FAMILY "mk20dx" )
69         message( STATUS "Chip Family:" )
70         message( "${CHIP_FAMILY}" )
71 else ()
72         message( FATAL_ERROR "Unknown chip family: ${CHIP}" )
73 endif ()
74
75
76 #| CPU Type
77 #| You _MUST_ set this to match the board you are using
78 #| type "make clean" after changing this, so all files will be rebuilt
79 #|
80 #| "cortex-m4"        # Teensy   3.0, 3.1, McHCK
81 set( CPU "cortex-m4" )
82
83 message( STATUS "CPU Selected:" )
84 message( "${CPU}" )
85
86
87 #| Extra Compiler Sources
88 #| Mostly for convenience functions like interrupt handlers
89 set( COMPILER_SRCS
90         Lib/${CHIP_FAMILY}.c
91         Lib/delay.c
92 )
93
94 message( STATUS "Compiler Source Files:" )
95 message( "${COMPILER_SRCS}" )
96
97
98 #| USB Defines, this is how the loader programs detect which type of chip base is used
99 message( STATUS "Bootloader Type:" )
100 if ( "${CHIP}" MATCHES "mk20dx128vlf5" OR "${CHIP}" MATCHES "mk20dx256vlh7" )
101         set( VENDOR_ID       "0x1C11" )
102         set( PRODUCT_ID      "0xB04D" )
103         set( BOOT_VENDOR_ID  "0x1C11" )
104         set( BOOT_PRODUCT_ID "0xB007" )
105         set( DFU 1 )
106         message( "dfu" )
107 elseif ( "${CHIP}" MATCHES "mk20dx128" OR "${CHIP}" MATCHES "mk20dx256" )
108         set( VENDOR_ID       "0x1C11" )
109         set( PRODUCT_ID      "0xB04D" )
110         set( BOOT_VENDOR_ID  "0x16c0" ) # TODO Double check, this is likely incorrect
111         set( BOOT_PRODUCT_ID "0x0487" )
112         set( TEENSY 1 )
113         message( "Teensy" )
114 endif ()
115
116
117 #| Compiler flag to set the C Standard level.
118 #|     c89   = "ANSI" C
119 #|     gnu89 = c89 plus GCC extensions
120 #|     c99   = ISO C99 standard (not yet fully implemented)
121 #|     gnu99 = c99 plus GCC extensions
122 #|     gnu11 = c11 plus GCC extensions
123 set( CSTANDARD "-std=gnu11" )
124
125
126 #| Warning Options
127 #|  -Wall...:     warning level
128 set( WARN "-Wall -ggdb3" )
129
130
131 #| Tuning Options
132 #|  -f...:        tuning, see GCC manual
133 #| NOTE: -fshort-wchar is specified to allow USB strings be passed conveniently
134 if( BOOTLOADER )
135         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" )
136         #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_" )
137 else()
138         set( TUNING "-mthumb -nostdlib -fdata-sections -ffunction-sections -fshort-wchar -fno-builtin -nostartfiles" )
139 endif()
140
141
142 #| Optimization level, can be [0, 1, 2, 3, s].
143 #|     0 = turn off optimization. s = optimize for size.
144 #|     (Note: 3 is not always the best optimization level.)
145 set( OPT "s" )
146
147
148 #| Processor frequency.
149 #|   Normally the first thing your program should do is set the clock prescaler,
150 #|   so your program will run at the correct speed.  You should also set this
151 #|   variable to same clock speed.  The _delay_ms() macro uses this, and many
152 #|   examples use this variable to calculate timings.  Do not add a "UL" here.
153 set( F_CPU "48000000" )
154
155
156 #| Dependency Files
157 #| Compiler flags to generate dependency files.
158 set( GENDEPFLAGS "-MMD" )
159
160
161 #| Compiler Flags
162 add_definitions( "-mcpu=${CPU} -DF_CPU=${F_CPU} -D_${CHIP}_=1 -O${OPT} ${TUNING} ${WARN} ${CSTANDARD} ${GENDEPFLAGS}" )
163
164
165 #| Linker Flags
166 if( BOOTLOADER )
167         # Bootloader linker flags
168         set( LINKER_FLAGS "${TUNING} -Wl,--gc-sections -fwhole-program -T${CMAKE_CURRENT_SOURCE_DIR}/../Lib/${CHIP}.bootloader.ld -nostartfiles -Wl,-Map=link.map" )
169 else()
170         # Normal linker flags
171         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" )
172 endif()
173
174
175 #| Hex Flags (XXX, CMake seems to have issues if you quote the arguments for the custom commands...)
176 set( HEX_FLAGS -O ihex -R .eeprom )
177
178
179 #| Binary Flags
180 set( BIN_FLAGS -O binary )
181
182
183 #| Lss Flags
184 set( LSS_FLAGS -h -S -z )
185