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

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