]> git.donarmstrong.com Git - kiibohd-controller.git/blob - Lib/CMake/arm.cmake
More work on mk20dx128vlf5 port.
[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 #| "mk20dx128"        # Teensy   3.0 and McHCK mk20dx128
29 #| "mk20dx256"        # Teensy   3.1
30
31 message( STATUS "Chip Selected:" )
32 message( "${CHIP}" )
33 set( MCU "${CHIP}" ) # For loading script compatibility
34
35
36 #| Chip Size Database
37 #| Teensy 3.0
38 if ( "${CHIP}" MATCHES "mk20dx128" OR "${CHIP}" MATCHES "mk20dx128vlf5" )
39         set( SIZE_RAM    16384 )
40         set( SIZE_FLASH 131072 )
41
42 #| Teensy 3.1
43 elseif ( "${CHIP}" MATCHES "mk20dx256" )
44         set( SIZE_RAM    65536 )
45         set( SIZE_FLASH 262144 )
46
47 #| Unknown ARM
48 else ()
49         message( AUTHOR_WARNING "CHIP: ${CHIP} - Unknown ARM microcontroller" )
50 endif ()
51
52
53 #| Chip Base Type
54 #| Automatically chosed based on the chip name.
55 if ( "${CHIP}" MATCHES "^mk20dx.*$" )
56         set( CHIP_FAMILY "mk20dx" )
57         message( STATUS "Chip Family:" )
58         message( "${CHIP_FAMILY}" )
59 else ()
60         message( FATAL_ERROR "Unknown chip family: ${CHIP}" )
61 endif ()
62
63
64 #| CPU Type
65 #| You _MUST_ set this to match the board you are using
66 #| type "make clean" after changing this, so all files will be rebuilt
67 #|
68 #| "cortex-m4"        # Teensy   3.0, 3.1, McHCK
69 set( CPU "cortex-m4" )
70
71 message( STATUS "CPU Selected:" )
72 message( "${CPU}" )
73
74
75 #| Extra Compiler Sources
76 #| Mostly for convenience functions like interrupt handlers
77 set( COMPILER_SRCS
78         Lib/${CHIP_FAMILY}.c
79         Lib/delay.c
80 )
81
82 message( STATUS "Compiler Source Files:" )
83 message( "${COMPILER_SRCS}" )
84
85
86 #| USB Defines, this is how the loader programs detect which type of chip base is used
87 if ( "${CHIP}" MATCHES "mk20dx128" OR "${CHIP}" MATCHES "mk20dx256" )
88         set( VENDOR_ID  "0x16C0" )
89         set( PRODUCT_ID "0x0487" )
90 elseif ( "${CHIP}" MATCHES "mk20dx128vlf5" )
91         set( VENDOR_ID  "0x2323" )
92         set( PRODUCT_ID "0x0001" )
93 endif ()
94
95
96 #| Compiler flag to set the C Standard level.
97 #|     c89   = "ANSI" C
98 #|     gnu89 = c89 plus GCC extensions
99 #|     c99   = ISO C99 standard (not yet fully implemented)
100 #|     gnu99 = c99 plus GCC extensions
101 set( CSTANDARD "-std=gnu99" )
102
103
104 #| Warning Options
105 #|  -Wall...:     warning level
106 set( WARN "-Wall -g" )
107
108
109 #| Tuning Options
110 #|  -f...:        tuning, see GCC manual
111 #| NOTE: -fshort-wchar is specified to allow USB strings be passed conveniently
112 set( TUNING "-mthumb -nostdlib -fdata-sections -ffunction-sections -fshort-wchar" )
113
114
115 #| Optimization level, can be [0, 1, 2, 3, s].
116 #|     0 = turn off optimization. s = optimize for size.
117 #|     (Note: 3 is not always the best optimization level.)
118 set( OPT "s" )
119
120
121 #| Processor frequency.
122 #|   Normally the first thing your program should do is set the clock prescaler,
123 #|   so your program will run at the correct speed.  You should also set this
124 #|   variable to same clock speed.  The _delay_ms() macro uses this, and many
125 #|   examples use this variable to calculate timings.  Do not add a "UL" here.
126 set( F_CPU "48000000" )
127
128
129 #| Dependency Files
130 #| Compiler flags to generate dependency files.
131 set( GENDEPFLAGS "-MMD" )
132
133
134 #| Compiler Flags
135 add_definitions( "-mcpu=${CPU} -DF_CPU=${F_CPU} -D_${CHIP}_=1 -O${OPT} ${TUNING} ${WARN} ${CSTANDARD} ${GENDEPFLAGS}" )
136
137
138 #| Linker Flags
139 set( LINKER_FLAGS "-mcpu=${CPU} -Wl,-Map=link.map,--cref -Wl,--gc-sections -mthumb -Wl,--no-wchar-size-warning -T${CMAKE_CURRENT_SOURCE_DIR}/Lib/${CHIP}.ld" )
140
141
142 #| Hex Flags (XXX, CMake seems to have issues if you quote the arguments for the custom commands...)
143 set( HEX_FLAGS -O ihex -R .eeprom )
144
145
146 #| Binary Flags
147 set( BIN_FLAGS -O binary )
148
149
150 #| Lss Flags
151 set( LSS_FLAGS -h -S -z )
152