-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
214 lines (180 loc) · 6.76 KB
/
CMakeLists.txt
File metadata and controls
214 lines (180 loc) · 6.76 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work ==
if(WIN32)
set(USERHOME $ENV{USERPROFILE})
else()
set(USERHOME $ENV{HOME})
endif()
set(sdkVersion 2.2.0)
set(toolchainVersion 14_2_Rel1)
set(picotoolVersion 2.2.0-a4)
set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake)
if (EXISTS ${picoVscode})
include(${picoVscode})
endif()
# ====================================================================================
set(PICO_BOARD pico CACHE STRING "Board type")
cmake_minimum_required(VERSION 3.13)
option(BUILD_TESTS "Enable building the unit tests" OFF)
# Pull in SDK (must be before project)
include(pico_sdk_import.cmake)
include(pico_extras_import_optional.cmake)
project(pico_project_template C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
if (PICO_SDK_VERSION_STRING VERSION_LESS "2.2.0")
message(FATAL_ERROR "Raspberry Pi Pico SDK version 2.2.0 (or later) required. Your version is ${PICO_SDK_VERSION_STRING}")
endif()
# If you want debug output from USB (pass -DPICO_STDIO_USB=1) this ensures you don't lose any debug output while USB is set up
if (NOT DEFINED PICO_STDIO_USB_CONNECT_WAIT_TIMEOUT_MS)
set(PICO_STDIO_USB_CONNECT_WAIT_TIMEOUT_MS 3000)
endif()
# Allow using the example keys, as this is the examples repository
if (NOT DEFINED PICO_ALLOW_EXAMPLE_KEYS)
set(PICO_ALLOW_EXAMPLE_KEYS 1)
endif()
# FreeRTOS configuration (must be before pico_sdk_init)
add_library(freertos_config INTERFACE)
target_include_directories(freertos_config INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
include(FetchContent)
FetchContent_Populate(freertos_kernel
GIT_REPOSITORY "https://github.com/FreeRTOS/FreeRTOS-Kernel.git"
GIT_TAG "V11.2.0"
)
set(FREERTOS_KERNEL_PATH "${CMAKE_CURRENT_BINARY_DIR}/freertos_kernel-src" CACHE STRING "FreeRTOS Location" FORCE)
# Initialize the SDK
pico_sdk_init()
# Add appropriate FreeRTOS port based on platform
if(PICO_PLATFORM STREQUAL "rp2040")
add_subdirectory(${FREERTOS_KERNEL_PATH}/portable/ThirdParty/GCC/RP2040)
elseif(PICO_PLATFORM STREQUAL "rp2350-arm-s")
add_subdirectory(${FREERTOS_KERNEL_PATH}/portable/ThirdParty/Community-Supported-Ports/GCC/RP2350_ARM_NTZ)
elseif(PICO_PLATFORM STREQUAL "rp2350-riscv")
add_subdirectory(${FREERTOS_KERNEL_PATH}/portable/ThirdParty/Community-Supported-Ports/GCC/RP2350_RISC-V)
else()
message(FATAL_ERROR "Unsupported PICO_PLATFORM: ${PICO_PLATFORM}")
endif()
# add cryptoauthlib
include(FetchContent)
# Set options for cryptoauthlib BEFORE it is fetched.
set(UNIX FALSE) # Prevent cryptoauthlib from thinking we are on linux
set(ATCA_HAL_I2C ON CACHE BOOL "Enable the I2C HAL infrastructure (which we will override)")
set(ATCA_HAL_SPI OFF CACHE BOOL "Disable default SPI HAL")
set(ATCA_HAL_SWI OFF CACHE BOOL "Disable default SWI HAL")
set(ATCA_HAL_UART OFF CACHE BOOL "Disable default UART HAL")
set(ATCA_HAL_KIT_HID OFF CACHE BOOL "Disable default Kit HID HAL")
set(ATCA_HAL_KIT_CDC OFF CACHE BOOL "Disable default Kit CDC HAL")
set(ATCA_HAL_CUSTOM OFF CACHE BOOL "Disable the 'custom' HAL mechanism")
set(ATCA_TNGTLS_SUPPORT OFF CACHE BOOL "Disable TNGTLS support")
set(ATCA_OPENSSL_SUPPORT OFF CACHE BOOL "Disable OpenSSL support")
set(ATCA_BUILD_TESTS OFF CACHE BOOL "Disable building tests")
FetchContent_Declare(
cryptoauthlib
GIT_REPOSITORY https://github.com/MicrochipTech/cryptoauthlib.git
GIT_TAG v3.7.9
)
FetchContent_MakeAvailable(cryptoauthlib)
get_target_property(CRYPTOAUTHLIB_SOURCES cryptoauth SOURCES)
# Filter the list, EXCLUDING the Linux-specific HAL files
list(FILTER CRYPTOAUTHLIB_SOURCES EXCLUDE REGEX ".*hal_linux.c")
list(FILTER CRYPTOAUTHLIB_SOURCES EXCLUDE REGEX ".*hal_linux_i2c_userspace.c")
# Set the target's sources to our new, filtered list
set_target_properties(cryptoauth PROPERTIES SOURCES "${CRYPTOAUTHLIB_SOURCES}")
include(example_auto_set_url.cmake)
# Performance optimization flags
add_compile_options(
-Wall
-Wno-format # int != int32_t as far as the compiler is concerned because gcc has int32_t as long int
-Wno-unused-function # we have some for the docs that aren't called
-O3
-ffunction-sections
-fdata-sections
)
add_link_options(-Wl,--gc-sections)
# Platform-specific CPU optimizations
if(PICO_PLATFORM STREQUAL "rp2040")
add_compile_options(
-mcpu=cortex-m0plus
-mthumb
)
elseif(PICO_PLATFORM STREQUAL "rp2350-arm-s")
add_compile_options(
-mcpu=cortex-m33
-mthumb
)
elseif(PICO_PLATFORM STREQUAL "rp2350-riscv")
add_compile_options(
-march=rv32imac
-mabi=ilp32
)
endif()
# Link-time optimization and dead code elimination
add_link_options(
-Wl,--gc-sections # Remove unused sections
-Wl,--print-memory-usage # Show memory usage after linking
)
# Don't enable LTO globally - we'll enable it per-target to avoid library issues
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION FALSE)
# DEBUG mode control (defaults to OFF for production builds)
# Set -DENABLE_DEBUG=ON to enable debug logging and serial provisioning
option(ENABLE_DEBUG "Enable debug logging and serial provisioning" OFF)
if(ENABLE_DEBUG)
add_compile_definitions(DEBUG)
message(STATUS "DEBUG mode enabled - debug logging and serial provisioning active")
else()
message(STATUS "PRODUCTION mode - debug features disabled")
endif()
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
add_compile_options(-Wno-maybe-uninitialized)
endif()
add_executable(pico_project_template
src/main.c
src/serial.c
src/protocol.c
src/crypto.c
src/cpu_monitor.c
src/hooks.c
src/hal/hal_pico_i2c.c
src/net/wifi_ap.c
src/net/ap/ap_manager.c
src/net/http/http_server.c
src/net/api/api.c
src/net/dhcp/dhcpserver.c
src/flash_config.c
)
# Link to pico_stdlib
target_link_libraries(pico_project_template
pico_stdlib
hardware_i2c
hardware_gpio
cryptoauth
pico_mbedtls
FreeRTOS-Kernel-Heap4
freertos_config
pico_cyw43_arch_lwip_threadsafe_background
pico_lwip_http
hardware_adc
hardware_watchdog
hardware_flash
hardware_sync
pico_multicore
)
# Enable usb output, disable uart output
pico_enable_stdio_usb(pico_project_template 1)
pico_enable_stdio_uart(pico_project_template 0)
# Create map/bin/hex file etc.
pico_add_extra_outputs(pico_project_template)
# Add include directory
target_include_directories(pico_project_template
PUBLIC
${CMAKE_CURRENT_LIST_DIR}/include
${CMAKE_CURRENT_LIST_DIR}/src
${CMAKE_CURRENT_LIST_DIR}/src/net
${cryptoauthlib_SOURCE_DIR}/lib
${cryptoauthlib_SOURCE_DIR}/lib/hal
${cryptoauthlib_SOURCE_DIR}/lib/calib
${PICO_SDK_PATH}/lib/lwip/src/include
${PICO_SDK_PATH}/lib/lwip/contrib/ports/freertos/include
)
if(BUILD_TESTS)
add_subdirectory(test)
endif()