1+
12cmake_minimum_required (VERSION 3.20)
23
34set (CMAKE_C_STANDARD 17)
45set (CMAKE_CXX_STANDARD 20)
56set (FAMILY rp2040)
67set (BOARD pico_sdk)
78
8- include ($ENV{PICO_SDK_PATH} /lib/tinyusb/hw/bsp/family_support.cmake)
9-
109include ($ENV{PICO_SDK_PATH} /external/pico_sdk_import.cmake)
1110
12- if (PICO_SDK_VERSION_STRING VERSION_LESS "1.4.0" )
13- message (FATAL_ERROR "Raspberry Pi Pico SDK version 1.4.0 (or later) required. Your version is ${PICO_SDK_VERSION_STRING} " )
14- endif ()
15-
1611project (debug_on_pico C CXX ASM)
1712
1813pico_sdk_init()
1914
15+ include (FetchContent)
16+ FetchContent_Declare(
17+ pico_mcp2515
18+ GIT_REPOSITORY https://github.com/adamczykpiotr/pico-mcp2515.git
19+ GIT_TAG main
20+ )
21+ FetchContent_Populate(pico_mcp2515)
22+
23+ include ($ENV{PICO_SDK_PATH} /lib/tinyusb/hw/bsp/family_support.cmake)
24+
25+ # if (PICO_SDK_VERSION_STRING VERSION_LESS "1.4.0")
26+ # message(FATAL_ERROR "Raspberry Pi Pico SDK version 1.4.0 (or later) required. Your version is ${PICO_SDK_VERSION_STRING}")
27+ # endif()
28+
2029check_and_add_pico_pio_usb_support()
2130
2231if (CMAKE_HOST_UNIX AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin" )
23- SET (MACOS_BUILD true )
32+ SET (MACOS_BUILD true )
2433else ()
25- SET (MACOS_BUILD false )
26- endif ()
34+ SET (MACOS_BUILD false )
35+ endif ()
2736
2837if (NOT CMAKE_BUILD_TYPE )
29- set (CMAKE_BUILD_TYPE Release)
30- message (STATUS "Build type not specified: defaulting to release." )
31- endif ()
38+ set (CMAKE_BUILD_TYPE Release)
39+ message (STATUS "Build type not specified: defaulting to release." )
40+ endif ()
3241
3342IF (CMAKE_C_COMPILER_ID STREQUAL "GNU" )
34- SET (CMAKE_C_STANDARD 11)
35- ELSEIF (CMAKE_C_COMPILER_ID MATCHES "Clang" )
36- SET (CMAKE_C_STANDARD 11)
43+ SET (CMAKE_C_STANDARD 11)
44+ ELSEIF (CMAKE_C_COMPILER_ID MATCHES "Clang" )
45+ SET (CMAKE_C_STANDARD 11)
3746ELSE ()
38- #message(WARNING "C standard could not be set because compiler is not GNU or Clang.")
47+ #message(WARNING "C standard could not be set because compiler is not GNU or Clang.")
3948ENDIF ()
4049
4150option (DISABLE_SOCKET "Disable SocketCAN build" OFF )
@@ -60,40 +69,41 @@ set(INCLUDES
6069 ${PICO_SDK_PATH} /lib/tinyusb/hw
6170 ${PICO_SDK_PATH} /lib/tinyusb/src/portable/raspberrypi/rp2040
6271 ${PICO_SDK_PATH} /lib/tinyusb/src/portable/raspberrypi/rp2040/dcd_rp2040
72+ ${pico_mcp2515_SOURCE_DIR} /include
6373)
6474
6575if (MSVC )
66- # Use case-insensitive match to catch Debug/Release values
67- if (CMAKE_BUILD_TYPE MATCHES "^[Dd]ebug$" )
68- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Od /Zi /D_DEBUG" )
69- else ()
70- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /O2 /Oy /DNDEBUG" )
71- endif ()
76+ # Use case-insensitive match to catch Debug/Release values
77+ if (CMAKE_BUILD_TYPE MATCHES "^[Dd]ebug$" )
78+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Od /Zi /D_DEBUG" )
79+ else ()
80+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /O2 /Oy /DNDEBUG" )
81+ endif ()
7282else ()
73- #
74- # clang or gcc
75- #
76- add_definitions (-D_GNU_SOURCE)
77-
78- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-unused-parameter -Wno-unused-function -Wno-unused-variable -ffunction-sections" )
79-
80- if ("${PROFILE} " STREQUAL "ON" )
81- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pg -fprofile-arcs -ftest-coverage --coverage" )
82- endif ()
83-
84- if (CMAKE_BUILD_TYPE MATCHES "^[Dd]ebug$" )
85- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ggdb -D_DEBUG -Og -fno-omit-frame-pointer -fno-optimize-sibling-calls" )
86- if (NOT CMAKE_HOST_WIN32 )
87- #set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DFORTIFY_SOURCE=2 -fstack-protector-all --param=ssp-buffer-size=4 -fstack-check -fsanitize=address -fsanitize=undefined ")
88- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DFORTIFY_SOURCE=2 -fstack-protector-all --param=ssp-buffer-size=4 -fstack-check -fsanitize=undefined " )
89- if (CMAKE_C_COMPILER_ID MATCHES "Clang" )
90- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wthread-safety" )
91- endif ()
83+ #
84+ # clang or gcc
85+ #
86+ add_definitions (-D_GNU_SOURCE)
87+
88+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-unused-parameter -Wno-unused-function -Wno-unused-variable -ffunction-sections" )
89+
90+ if ("${PROFILE} " STREQUAL "ON" )
91+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pg -fprofile-arcs -ftest-coverage --coverage" )
92+ endif ()
93+
94+ if (CMAKE_BUILD_TYPE MATCHES "^[Dd]ebug$" )
95+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ggdb -D_DEBUG -Og -fno-omit-frame-pointer -fno-optimize-sibling-calls" )
96+ if (NOT CMAKE_HOST_WIN32 )
97+ #set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DFORTIFY_SOURCE=2 -fstack-protector-all --param=ssp-buffer-size=4 -fstack-check -fsanitize=address -fsanitize=undefined ")
98+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DFORTIFY_SOURCE=2 -fstack-protector-all --param=ssp-buffer-size=4 -fstack-check -fsanitize=undefined " )
99+ if (CMAKE_C_COMPILER_ID MATCHES "Clang" )
100+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wthread-safety" )
101+ endif ()
102+ endif ()
103+ else ()
104+ # Treat non-Debug as Release here
105+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNDEBUG -O2" )
92106 endif ()
93- else ()
94- # Treat non-Debug as Release here
95- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNDEBUG -O2" )
96- endif ()
97107endif (MSVC )
98108
99109
@@ -104,18 +114,12 @@ target_include_directories(debug_on_pico PUBLIC ${INCLUDES}
104114 ${PICO_SDK_PATH} /lib/tinyusb/src/portable/raspberrypi/rp2040/dcd_rp2040
105115 ${PICO_SDK_PATH} /lib/tinyusb/hw
106116)
107- #
117+
108118
109119target_compile_features (debug_on_pico PRIVATE c_std_11)
110120# Link against Pico SDK libraries only
111121target_link_libraries (debug_on_pico pico_stdlib
112122 tinyusb_device
113123 tinyusb_board
124+ hardware_spi
114125)
115-
116-
117- # add_executable(debug_on_pico main.cpp)
118- # target_link_libraries(debug_on_pico pico_stdlib)
119- pico_add_extra_outputs(debug_on_pico)
120- pico_enable_stdio_usb(debug_on_pico 0)
121- pico_enable_stdio_uart(debug_on_pico 0)
0 commit comments