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