@@ -23,12 +23,11 @@ if (EXISTS ${picoVscode})
2323 include (${picoVscode} )
2424endif ()
2525# ====================================================================================
26-
2726set (PICO_BOARD_HEADER_DIRS ${CMAKE_SOURCE_DIR} )
2827# Board type selection:
2928#
30- # Please select RP2040-Decoder-board.h for Rev >= 1.0 or RP2040-Decoder-board-legacy.h for Rev < 1.0
31- set (PICO_BOARD RP2040-Decoder-board.h CACHE STRING "Board type" )
29+ # Please select RP2040-Decoder-board-Rev-1_0 for Rev >= 1.0 or RP2040-Decoder-board-Rev-0_3 for Rev <= 0.3
30+ set (PICO_BOARD RP2040-Decoder-board-Rev-1_0 )
3231
3332# Pull in Raspberry Pi Pico SDK (must be before project)
3433include (pico_sdk_import.cmake)
@@ -38,12 +37,13 @@ project(RP2040-Decoder C CXX ASM)
3837# Initialise the Raspberry Pi Pico SDK
3938pico_sdk_init()
4039
40+ # Manual compiler options, these generally override configuration set by CMAKE_BUILD_TYPE
4141add_compile_options (-Wall
42- -Ofast
43- -g3
44- -Wno-format # int != int32 _t as far as the compiler is concerned because gcc has int32_t as long int
45- -Wno-unused-function # we have some for the docs that aren't called
46- -Wno-maybe-uninitialized )
42+ # -O0 # Overrides optimization flags specified by CMAKE_BUILD_TYPE
43+ # -g3 # Overrides debug flags specified by CMAKE_BUILD_TYPE
44+ -Wno-format # unsigned int = uint32_t using gcc so don't warn about format
45+ -Wno-unused-function # Some defined functions used for debugging are never called or not used when logging is disabled
46+ )
4747
4848# Add executable
4949add_executable ( RP2040-Decoder
@@ -55,8 +55,14 @@ add_executable( RP2040-Decoder
5555 shared.h )
5656
5757pico_set_program_name(RP2040-Decoder "RP2040-Decoder" )
58- pico_set_program_version(RP2040-Decoder "1.0" )
5958
59+ # Build type
60+ message ("CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE} " )
61+ message ("PICO_DEOPTIMIZED_DEBUG: ${PICO_DEOPTIMIZED_DEBUG} " )
62+ if (NOT CMAKE_BUILD_TYPE )
63+ message (WARNING "CMAKE_BUILD_TYPE is not set. Defaulting to 'Release'" )
64+ set (CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type" FORCE)
65+ endif ()
6066
6167# Logging configuration:
6268#
@@ -119,61 +125,16 @@ pico_add_extra_outputs(RP2040-Decoder)
119125# Program size check
120126#
121127# Check for program size exceeding limits as CVs are stored at the end of flash, the program could theoretically overwrite this.
122- # In practice the program size is usually only about 100KiB.
128+ # In practice the program size is usually does not exceed about 100KiB, the actual size is printed by CMake from arm-none-eabi-size .
123129# Extract the directory of the C compiler and construct the path to the 'arm-none-eabi-size' tool
124130get_filename_component (C_COMPILER_DIR ${CMAKE_C_COMPILER} DIRECTORY )
125131set (SIZE_TOOL ${C_COMPILER_DIR} /arm-none-eabi-size)
126-
127- # Add custom command to check the flash size after build
132+ set (BOARD_HEADER " ${CMAKE_SOURCE_DIR} / ${PICO_BOARD} .h" )
133+ set (ELF_FILE " ${CMAKE_BINARY_DIR} / ${PROJECT_NAME} .elf" )
128134add_custom_command (TARGET RP2040-Decoder POST_BUILD
129- COMMAND ${CMAKE_COMMAND} -E echo "Checking flash size for $<TARGET_FILE:RP2040-Decoder>"
130- COMMAND ${SIZE_TOOL} $<TARGET_FILE:RP2040-Decoder> > size_output.txt
131- )
132-
133- # Read the size output file
134- file (READ "${CMAKE_BINARY_DIR} /size_output.txt" SIZE_OUTPUT)
135-
136- # Print the content of SIZE_OUTPUT
137- message (STATUS "arm-none-eabi-size output:\n ${SIZE_OUTPUT} " )
138-
139- # Use regex to match all numbers
140- string (REGEX MATCHALL "[0-9]+" MATCHED_VALUES "${SIZE_OUTPUT} " )
141-
142- # Get third element from list of matches, this corresponds with dec table value in "size_output.txt"
143- list (GET MATCHED_VALUES 3 PROGRAM_SIZE_DEC)
144-
145- # Check for success of program size extraction from "size_output.txt"
146- if (PROGRAM_SIZE_DEC)
147- message (STATUS "PROGRAM_SIZE_DEC: ${PROGRAM_SIZE_DEC} bytes" )
148- else ()
149- message (FATAL_ERROR "Could not extract program size from size_output.txt" )
150- endif ()
151-
152-
153- # Path to the header file that defines PICO_FLASH_SIZE_BYTES
154- set (FLASH_CONFIG_HEADER ${CMAKE_SOURCE_DIR} /${PICO_BOARD} .h)
155- # Read the contents of the header file into a variable
156- file (READ ${FLASH_CONFIG_HEADER} HEADER_CONTENT)
157-
158- # Extract the value of PICO_FLASH_SIZE_BYTES using a regular expression
159- string (REGEX MATCHALL "#define PICO_FLASH_SIZE_BYTES [0-9]+" MACRO_MATCH "${HEADER_CONTENT} " )
160- string (REGEX MATCHALL "[0-9]+" PICO_FLASH_SIZE_BYTES "${MACRO_MATCH} " )
161-
162-
163- # Check for success of PICO_FLASH_SIZE_BYTES extraction from board header file
164- if (PICO_FLASH_SIZE_BYTES)
165- message (STATUS "PICO_FLASH_SIZE_BYTES: ${PICO_FLASH_SIZE_BYTES} bytes" )
166- else ()
167- message (FATAL_ERROR "Failed to find PICO_FLASH_SIZE_BYTES in the header file." )
168- endif ()
169-
170- # Sector size is always 4096 bytes
171- set (FLASH_SECTOR_SIZE 4096)
172- message (STATUS "FLASH_SECTOR_SIZE: ${FLASH_SECTOR_SIZE} bytes" )
173- # Subtract flash sector size from flash size
174- math (EXPR FLASH_TARGET_OFFSET "${PICO_FLASH_SIZE_BYTES} - ${FLASH_SECTOR_SIZE} " )
175- message (STATUS "FLASH_TARGET_OFFSET: ${FLASH_TARGET_OFFSET} bytes" )
176-
177- if (PROGRAM_SIZE_DEC GREATER FLASH_TARGET_OFFSET)
178- message (FATAL_ERROR "Program size exceeds allowed flash size. Flash sector containing the CVs would be overwritten! Please reduce the size of the program." )
179- endif ()
135+ COMMAND ${CMAKE_COMMAND}
136+ -D BOARD_HEADER=${BOARD_HEADER}
137+ -D SIZE_TOOL=${SIZE_TOOL}
138+ -D ELF_FILE=${ELF_FILE}
139+ -P ${CMAKE_SOURCE_DIR} /post_build.cmake
140+ )
0 commit comments