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.

avr.cmake 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. # avr-gcc CMake Build Configuration
  9. #
  10. ###
  11. #| Set the Compilers (must be set first)
  12. include( CMakeForceCompiler )
  13. cmake_force_c_compiler ( avr-gcc AVRCCompiler )
  14. cmake_force_cxx_compiler( avr-g++ AVRCxxCompiler )
  15. set( _CMAKE_TOOLCHAIN_PREFIX avr- )
  16. ###
  17. # Atmel Defines and Linker Options
  18. #
  19. #| MCU Name
  20. #|
  21. #| "at90usb162" # Teensy 1.0
  22. #| "atmega32u4" # Teensy 2.0
  23. #| "at90usb646" # Teensy++ 1.0
  24. #| "at90usb1286" # Teensy++ 2.0
  25. set( MCU "${CHIP}" )
  26. message( STATUS "MCU Selected:" )
  27. message( "${MCU}" )
  28. #| Chip Size Database
  29. #| Teensy 1.0
  30. if ( "${CHIP}" MATCHES "at90usb162" )
  31. set( SIZE_RAM 512 )
  32. set( SIZE_FLASH 15872 )
  33. #| Teensy 2.0
  34. elseif ( "${CHIP}" MATCHES "atmega32u4" )
  35. set( SIZE_RAM 2560 )
  36. set( SIZE_FLASH 32256 )
  37. #| Teensy++ 1.0
  38. elseif ( "${CHIP}" MATCHES "at90usb646" )
  39. set( SIZE_RAM 4096 )
  40. set( SIZE_FLASH 64512 )
  41. #| Teensy++ 2.0
  42. elseif ( "${CHIP}" MATCHES "at90usb1286" )
  43. set( SIZE_RAM 8192 )
  44. set( SIZE_FLASH 130048 )
  45. #| Unknown AVR
  46. else ()
  47. message( AUTHOR_WARNING "CHIP: ${CHIP} - Unknown AVR microcontroller" )
  48. endif ()
  49. #| Extra Compiler Sources
  50. #| Mostly for convenience functions like interrupt handlers
  51. set( COMPILER_SRCS
  52. # XXX Not needed for avr-gcc
  53. )
  54. #| CPU Type
  55. #| This is only informational for AVR microcontrollers
  56. #| The field can be determined by the microcontroller chip, but currently only one CPU type is used atm
  57. set( CPU "megaAVR" )
  58. message( STATUS "CPU Selected:" )
  59. message( "${CPU}" )
  60. #| USB Defines
  61. set( VENDOR_ID "0x1C11" )
  62. set( PRODUCT_ID "0xB04D" )
  63. set( BOOT_VENDOR_ID "0x16C0" ) # TODO Double check, this is likely incorrect
  64. set( BOOT_PRODUCT_ID "0x047D" )
  65. #| Only Teensy based AVRs supported
  66. set ( TEENSY 1 )
  67. message( STATUS "Bootloader Type:" )
  68. message( "Teensy" )
  69. #| Compiler flag to set the C Standard level.
  70. #| c89 = "ANSI" C
  71. #| gnu89 = c89 plus GCC extensions
  72. #| c99 = ISO C99 standard (not yet fully implemented)
  73. #| gnu99 = c99 plus GCC extensions
  74. set( CSTANDARD "-std=gnu99" )
  75. #| Warning Options
  76. #| -Wall...: warning level
  77. set( WARN "-Wall" )
  78. #| Tuning Options
  79. #| -f...: tuning, see GCC manual and avr-libc documentation
  80. #| NOTE: -fshort-wchar is specified to allow USB strings be passed conveniently
  81. set( TUNING "-funsigned-char -funsigned-bitfields -ffunction-sections -fpack-struct -fshort-enums" )
  82. #| Optimization level, can be [0, 1, 2, 3, s].
  83. #| 0 = turn off optimization. s = optimize for size.
  84. #| (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
  85. set( OPT "s" )
  86. #| Output Format
  87. #| srec, ihex, binary
  88. set( FORMAT "ihex" )
  89. #| Processor frequency.
  90. #| Normally the first thing your program should do is set the clock prescaler,
  91. #| so your program will run at the correct speed. You should also set this
  92. #| variable to same clock speed. The _delay_ms() macro uses this, and many
  93. #| examples use this variable to calculate timings. Do not add a "UL" here.
  94. set( F_CPU "16000000" )
  95. #| Dependency Files
  96. #| Compiler flags to generate dependency files.
  97. set( GENDEPFLAGS "-MMD -MP" )
  98. #| Compiler Flags
  99. add_definitions( "-mmcu=${MCU} -DF_CPU=${F_CPU} -D_${MCU}_=1 -O${OPT} ${TUNING} ${WARN} ${CSTANDARD} ${GENDEPFLAGS}" )
  100. #| Linker Flags
  101. set( LINKER_FLAGS "-mmcu=${MCU} -Wl,-Map=link.map,--cref -Wl,--relax -Wl,--gc-sections" )
  102. #| Hex Flags (XXX, CMake seems to have issues if you quote the arguments for the custom commands...)
  103. set( HEX_FLAGS -O ${FORMAT} -R .eeprom -R .fuse -R .lock -R .signature )
  104. #| Eep Flags (XXX, I've removed this target from the builds, but keeping the set line as a note)
  105. set( EEP_FLAGS -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 --no-change-warnings -O ${FORMAT} )
  106. #| Lss Flags
  107. set( LSS_FLAGS -h -S -z )