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