-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
102 lines (73 loc) · 3.17 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
cmake_minimum_required(VERSION 3.6)
include(cmake_arduino_local_install/arduino-local-install.cmake)
SET(ArduinoToolchainVersion 1.8.8)
set(DOWNLOADS ${CMAKE_SOURCE_DIR}/Downloads)
file(MAKE_DIRECTORY ${DOWNLOADS})
set(ARDUINO_SDK_PATH ${CMAKE_SOURCE_DIR}/arduino-${ArduinoToolchainVersion})
if(NOT EXISTS ${ARDUINO_SDK_PATH}/revisions.txt)
install_arduino_localy(${ArduinoToolchainVersion} ${CMAKE_SOURCE_DIR} ${DOWNLOADS})
endif()
project(at16u2_cmsis_dap)
SET(MCU atmega16u2)
SET(CMAKE_SYSTEM_NAME Generic)
SET(CMAKE_CROSSCOMPILING 1)
SET(AVR_TOOLS_PATH ${ARDUINO_SDK_PATH}/hardware/tools/avr)
SET(CMAKE_C_COMPILER ${AVR_TOOLS_PATH}/bin/avr-gcc)
SET(CMAKE_CXX_COMPILER ${AVR_TOOLS_PATH}/bin/avr-g++)
SET(C_FLAGS "-mmcu=${MCU} -g0 -Os -fno-exceptions -ffunction-sections -fdata-sections -Wno-error=narrowing -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums")
SET(CMAKE_C_FLAGS "${C_FLAGS}")
SET(CMAKE_CXX_FLAGS "-std=gnu++11 -fpermissive -fno-threadsafe-statics ${C_FLAGS}")
SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--gc-sections,--relax -mmcu=atmega16u2")
SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS)
SET(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS)
include_directories(
${CMAKE_SOURCE_DIR}
${AVR_TOOLS_PATH}/avr/include
${ARDUINO_SDK_PATH}/hardware/arduino/avr/cores/arduino
${CMAKE_SOURCE_DIR}/HID/src
${ARDUINO_SDK_PATH}/hardware/arduino/avr/libraries/HID/src/
)
add_definitions(
-D__AVR_ATmega16U2__
-DF_CPU=16000000
-DUSB_VID=0x2341
-DUSB_PID=0x003D
-DUSB_PRODUCT="Arduino CMSIS-DAP"
-DARDUINO=10808
-DARDUINO_ARCH_AVR
-DDAP_SERIAL_LOG=0
-DDAP_JTAG=0
-DDAP_SWD=1
-DAT16U2_DUE
-DBOARD_ID="\\x1\\x1\\x1\\x1"
-DBOARD_SECRET="\\x1\\x1\\x1\\x1\\x1\\x1\\x1\\x1"
)
function(get_folder_sources var folder)
set(SRC_FILES ${${var}})
foreach(pattern IN LISTS ARGN)
file(GLOB_RECURSE FILES ${folder}/${pattern})
list(APPEND SRC_FILES ${FILES})
endforeach()
set(${var} ${SRC_FILES} PARENT_SCOPE)
endfunction()
get_folder_sources(ARDUINO_CMSIS_DAP_SRC_FILES ${CMAKE_SOURCE_DIR}/arduino-cmsis-dap *.c *.cpp)
add_library(arduino_cmsis_dap STATIC ${ARDUINO_CMSIS_DAP_SRC_FILES})
get_folder_sources(AVR_CORE_SRC_FILES ${ARDUINO_SDK_PATH}/hardware/arduino/avr/cores/arduino *.c *.cpp)
add_library(avr_core STATIC ${AVR_CORE_SRC_FILES})
get_folder_sources(HID_SRC_FILES ${CMAKE_SOURCE_DIR}/HID/src/SingleReport *.c *.cpp)
add_library(HID STATIC ${HID_SRC_FILES})
add_executable(at16u2_cmsis_dap sketch.cpp)
set_target_properties(at16u2_cmsis_dap PROPERTIES SUFFIX ".elf")
target_link_libraries(at16u2_cmsis_dap arduino_cmsis_dap HID avr_core)
set(ELF_FILE_PATH "$<TARGET_FILE:at16u2_cmsis_dap>")
set(HEX_FILE_PATH ${CMAKE_SOURCE_DIR}/$<TARGET_FILE_NAME:at16u2_cmsis_dap>.hex)
add_custom_target(hex
COMMAND ${AVR_TOOLS_PATH}/bin/avr-size -A ${ELF_FILE_PATH}
COMMAND ${AVR_TOOLS_PATH}/bin/avr-objcopy -O ihex -R .eeprom ${ELF_FILE_PATH} ${HEX_FILE_PATH}
BYPRODUCTS ${ELF_FILE_PATH}
DEPENDS at16u2_cmsis_dap
)
add_custom_target(flash_avrisp2
COMMAND ${AVR_TOOLS_PATH}/bin/avrdude -c avrisp2 -p m16u2 -v -e -U flash:w:${HEX_FILE_PATH}:i -C ${AVR_TOOLS_PATH}/etc/avrdude.conf
DEPENDS ${HEX_FILE_PATH}
)