@@ -84,8 +84,8 @@ endfunction()
8484
8585
8686function (family_initialize_project PROJECT DIR)
87- # set output suffix to .elf (skip espressif)
88- if (NOT FAMILY STREQUAL "espressif" )
87+ # set output suffix to .elf (skip espressif and rp2040 )
88+ if (NOT FAMILY STREQUAL "espressif" AND NOT FAMILY STREQUAL "rp2040" )
8989 set (CMAKE_EXECUTABLE_SUFFIX .elf PARENT_SCOPE)
9090 endif ()
9191
@@ -97,6 +97,87 @@ function(family_initialize_project PROJECT DIR)
9797endfunction ()
9898
9999
100+ #------------------------------------
101+ # Main target configure
102+ #------------------------------------
103+
104+ # Add common configuration to example
105+ function (family_configure_common TARGET )
106+ # run size after build
107+ add_custom_command (TARGET ${TARGET} POST_BUILD
108+ COMMAND ${CMAKE_SIZE} $<TARGET_FILE:${TARGET} >
109+ )
110+
111+ if (CMAKE_C_COMPILER_ID STREQUAL "GNU" )
112+ # Generate map file
113+ target_link_options (${TARGET} PUBLIC
114+ # link map
115+ "LINKER:-Map=$<TARGET_FILE:${TARGET} >.map"
116+ )
117+ endif ()
118+ endfunction ()
119+
120+
121+ # configure an executable target to link to tinyusb in device mode, and add the board implementation
122+ function (family_configure_device_example TARGET )
123+ # default implementation is empty, the function should be redefined in the FAMILY/family.cmake
124+ endfunction ()
125+
126+
127+ # configure an executable target to link to tinyusb in host mode, and add the board implementation
128+ function (family_configure_host_example TARGET )
129+ # default implementation is empty, the function should be redefined in the FAMILY/family.cmake
130+ endfunction ()
131+
132+
133+ # Add tinyusb to example
134+ function (family_add_tinyusb TARGET OPT_MCU)
135+ # tinyusb target is built for each example since it depends on example's tusb_config.h
136+ set (TINYUSB_TARGET_PREFIX ${TARGET} -)
137+ add_library (${TARGET} -tinyusb_config INTERFACE )
138+
139+ target_include_directories (${TARGET} -tinyusb_config INTERFACE
140+ ${CMAKE_CURRENT_SOURCE_DIR} /src
141+ )
142+ target_compile_definitions (${TARGET} -tinyusb_config INTERFACE
143+ CFG_TUSB_MCU=${OPT_MCU}
144+ )
145+
146+ # tinyusb's CMakeList.txt
147+ add_subdirectory (${TOP} /src ${CMAKE_CURRENT_BINARY_DIR} /tinyusb)
148+ endfunction ()
149+
150+
151+ # Add freeRTOS support to example
152+ function (family_add_freertos TARGET )
153+ # freeros config
154+ if (NOT TARGET freertos_config)
155+ add_library (freertos_config INTERFACE )
156+ target_include_directories (freertos_config INTERFACE
157+ ${CMAKE_CURRENT_FUNCTION_LIST_DIR} /${FAMILY} /FreeRTOSConfig
158+ )
159+ endif ()
160+
161+ # freertos kernel should be generic as freertos_config however, CMAKE complains with missing variable
162+ # such as CMAKE_C_COMPILE_OBJECT
163+ if (NOT TARGET freertos_kernel)
164+ add_subdirectory (${TOP} /lib/FreeRTOS-Kernel ${CMAKE_BINARY_DIR} /lib/freertos_kernel)
165+ endif ()
166+
167+ # Add FreeRTOS option to tinyusb_config
168+ target_compile_definitions (${TARGET} -tinyusb_config INTERFACE
169+ CFG_TUSB_OS=OPT_OS_FREERTOS
170+ )
171+ # link tinyusb with freeRTOS kernel
172+ target_link_libraries (${TARGET} -tinyusb PUBLIC
173+ freertos_kernel
174+ )
175+ target_link_libraries (${TARGET} PUBLIC
176+ freertos_kernel
177+ )
178+ endfunction ()
179+
180+
100181function (family_add_default_example_warnings TARGET )
101182 target_compile_options (${TARGET} PUBLIC
102183 -Wall
@@ -144,20 +225,6 @@ function(family_add_default_example_warnings TARGET)
144225endfunction ()
145226
146227
147- function (family_configure_common TARGET )
148- # run size after build
149- add_custom_command (TARGET ${TARGET} POST_BUILD
150- COMMAND ${CMAKE_SIZE} $<TARGET_FILE:${TARGET} >
151- )
152-
153- # Generate map file
154- target_link_options (${TARGET} PUBLIC
155- # link map
156- "LINKER:-Map=$<TARGET_FILE:${TARGET} >.map"
157- )
158- endfunction ()
159-
160-
161228# Add bin/hex output
162229function (family_add_bin_hex TARGET )
163230 add_custom_command (TARGET ${TARGET} POST_BUILD
@@ -167,6 +234,10 @@ function(family_add_bin_hex TARGET)
167234endfunction ()
168235
169236
237+ #----------------------------------
238+ # Flashing target
239+ #----------------------------------
240+
170241# Add flash jlink target
171242function (family_flash_jlink TARGET )
172243 if (NOT DEFINED JLINKEXE)
@@ -233,48 +304,7 @@ function(family_flash_nxplink TARGET)
233304endfunction ()
234305
235306
236- # configure an executable target to link to tinyusb in device mode, and add the board implementation
237- function (family_configure_device_example TARGET )
238- # default implementation is empty, the function should be redefined in the FAMILY/family.cmake
239- endfunction ()
240-
241-
242- # configure an executable target to link to tinyusb in host mode, and add the board implementation
243- function (family_configure_host_example TARGET )
244- # default implementation is empty, the function should be redefined in the FAMILY/family.cmake
245- endfunction ()
246-
247-
248- # Add freeRTOS support to example, can be overridden by FAMILY/family.cmake
249- function (family_add_freertos TARGET )
250- # freeros config
251- if (NOT TARGET freertos_config)
252- add_library (freertos_config INTERFACE )
253- target_include_directories (freertos_config SYSTEM INTERFACE
254- ${CMAKE_CURRENT_FUNCTION_LIST_DIR} /${FAMILY} /FreeRTOSConfig
255- )
256- endif ()
257-
258- # freertos kernel should be generic as freertos_config however, CMAKE complains with missing variable
259- # such as CMAKE_C_COMPILE_OBJECT
260- if (NOT TARGET freertos_kernel)
261- add_subdirectory (${TOP} /lib/FreeRTOS-Kernel ${CMAKE_BINARY_DIR} /lib/freertos_kernel)
262- endif ()
263-
264- # Add FreeRTOS option to tinyusb_config
265- target_compile_definitions (${TARGET} -tinyusb_config INTERFACE
266- CFG_TUSB_OS=OPT_OS_FREERTOS
267- )
268- # link tinyusb with freeRTOS kernel
269- target_link_libraries (${TARGET} -tinyusb PUBLIC
270- freertos_kernel
271- )
272- target_link_libraries (${TARGET} PUBLIC
273- freertos_kernel
274- )
275- endfunction ()
276-
277-
307+ # family specific: can override above functions
278308include (${CMAKE_CURRENT_LIST_DIR} /${FAMILY} /family.cmake)
279309
280310if (NOT FAMILY_MCUS)
0 commit comments