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 6.1KB

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