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