-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathCMakeLists.txt
128 lines (111 loc) · 4.15 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
cmake_minimum_required(VERSION 3.24)
include(CMakeDependentOption)
set(WITH_MCU OFF) # Disable target name modification setting from toolchain
set(AVR_MCU "attiny3216")
set(AVR_UPLOADTOOL_PORT /dev/ttyUSB1)
set(AVR_PROGRAMMER serialupdi)
set(AVR_UPLOADTOOL_BAUDRATE 230400)
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/cmake/avr-gcc-toolchain.cmake")
project(avclan-mockingboard VERSION 1 LANGUAGES C CXX ASM)
set(FREQSEL 16MHz CACHE STRING "Select the operating frequency")
set_property(CACHE FREQSEL PROPERTY STRINGS "20MHz" "16MHz")
if(FREQSEL MATCHES "20MHz")
set(FREQSEL 20000000L)
set(AVR_UPLOADTOOL_BASE_OPTIONS ${AVR_UPLOADTOOL_BASE_OPTIONS} -U osccfg:w:0x2:m)
else()
set(FREQSEL 16000000L)
set(AVR_UPLOADTOOL_BASE_OPTIONS ${AVR_UPLOADTOOL_BASE_OPTIONS} -U osccfg:w:0x1:m)
endif()
option(CLK_PRESCALE "Enable the main clock prescaler")
cmake_dependent_option(CLK_PRESCALE_DIV "Prescaler divisor" CLKCTRL_PDIV_2X_gc STRING "CLK_PRESCALE")
if(DEFINED CACHE{CLK_PRESCALE_DIV})
set_property(CACHE CLK_PRESCALE_DIV PROPERTY STRINGS
CLKCTRL_PDIV_2X_gc
CLKCTRL_PDIV_4X_gc
CLKCTRL_PDIV_8X_gc
CLKCTRL_PDIV_16X_gc
CLKCTRL_PDIV_32X_gc
CLKCTRL_PDIV_64X_gc
CLKCTRL_PDIV_6X_gc
CLKCTRL_PDIV_10X_gc
CLKCTRL_PDIV_12X_gc
CLKCTRL_PDIV_24X_gc
CLKCTRL_PDIV_48X_gc
)
else()
set(CLK_PRESCALE_DIV CLKCTRL_PDIV_2X_gc)
endif()
set(TCB_CLKSEL "TCB_CLKSEL_CLKDIV2_gc" CACHE STRING "Choose the clock for TCB")
set_property(CACHE TCB_CLKSEL PROPERTY STRINGS
TCB_CLKSEL_CLKDIV1_gc
TCB_CLKSEL_CLKDIV2_gc
TCB_CLKSEL_CLKTCA_gc
)
set(USART_RXMODE "USART_RXMODE_CLK2X_gc" CACHE STRING "USART at normal or double speed operation")
set_property(CACHE USART_RXMODE PROPERTY STRINGS
USART_RXMODE_CLK2X_gc
USART_RXMODE_NORMAL_gc
)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "8.3")
message(FATAL_ERROR "Insufficient AVR-GCC version; Support for ATtiny3216 was added in GCC v8")
endif()
endif()
# Handle libc versioning
try_compile(LIBC_VERSION_TEST
SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/cmake/libc-version-test.cpp"
COMPILE_DEFINITIONS -mmcu=${AVR_MCU}
)
if(NOT LIBC_VERSION_TEST)
include(FetchContent)
FetchContent_Declare(
attiny_atpack
URL http://packs.download.atmel.com/Atmel.ATtiny_DFP.2.0.368.atpack
URL_HASH SHA512=ee16a8ebecb57bd998a9cd4373368e3d45982cbbc3825e18d1dcac58215db6b9d907ad1ba2020cba9187fed7ba8c6f255a4fa1214e40c7a17ab2d18474f4d079
DOWNLOAD_NAME Atmel.ATtiny_DFP.2.0.368.atpack.zip
)
FetchContent_MakeAvailable(attiny_atpack)
try_compile(LIBC_VERSION_TEST
SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/cmake/libc-version-test.cpp"
COMPILE_DEFINITIONS
-B "${attiny_atpack_SOURCE_DIR}/gcc/dev/${AVR_MCU}"
-isystem "${attiny_atpack_SOURCE_DIR}/include"
-mmcu=${AVR_MCU}
)
if(NOT LIBC_VERSION_TEST)
message(FATAL_ERROR "Insufficient AVR-LIBC/Microchip pack for chosen MCU '${AVR_MCU}'")
else()
include_directories(SYSTEM "${attiny_atpack_SOURCE_DIR}/include")
add_compile_options(
-B "${attiny_atpack_SOURCE_DIR}/gcc/dev/${AVR_MCU}"
)
endif()
endif()
set(CMAKE_C_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_C_FLAGS_RELEASE "-Os")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -save-temps -g -gdwarf-3 -gstrict-dwarf")
set(CMAKE_C_FLAGS_DEBUG "-O0 -save-temps -g -gdwarf-3 -gstrict-dwarf")
# Set startup time to 8 ms (0x4)
set(AVR_UPLOADTOOL_BASE_OPTIONS ${AVR_UPLOADTOOL_BASE_OPTIONS} -U syscfg1:w:0x4:m)
add_avr_executable(mockingboard
src/sniffer.c
src/com232.c
src/avclandrv.c)
target_link_options(mockingboard PUBLIC
-B "${attiny_atpack_SOURCE_DIR}/gcc/dev/${AVR_MCU}"
)
target_compile_definitions(mockingboard PRIVATE
FREQSEL=${FREQSEL}
CLK_PRESCALE=$<IF:$<BOOL:${CLK_PRESCALE}>,0x01,0x00>
CLK_PRESCALE_DIV=${CLK_PRESCALE_DIV}
__CLK_PRESCALE_DIV=__${CLK_PRESCALE_DIV}
TCB_CLKSEL=${TCB_CLKSEL}
USART_RXMODE=${USART_RXMODE}
)
target_compile_options(mockingboard PRIVATE
--param=min-pagesize=0
-ffunction-sections
-fdata-sections
-fshort-enums
)