Kiibohd Controller
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

arm.cmake 7.5KB

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