- change to use CMAKE_SYSTEM_CPU to prevent CMAKE_SYSTEM_PROCESSOR conflict with zephyr

- change tinyusb CMakeLists.txt to function tinyusb_target_add() instead of defining tinyusb lib target
This commit is contained in:
hathach
2025-01-22 22:31:08 +07:00
parent 91214b4614
commit 6080f89f3d
67 changed files with 171 additions and 239 deletions

View File

@@ -73,34 +73,6 @@ if (NOT NO_WARN_RWX_SEGMENTS_SUPPORTED)
set(NO_WARN_RWX_SEGMENTS_SUPPORTED 1)
endif()
#set(WARNING_FLAGS_GNU
# -Wall
# -Wextra
# -Werror
# -Wfatal-errors
# -Wdouble-promotion
# -Wstrict-prototypes
# -Wstrict-overflow
# -Werror-implicit-function-declaration
# -Wfloat-equal
# -Wundef
# -Wshadow
# -Wwrite-strings
# -Wsign-compare
# -Wmissing-format-attribute
# -Wunreachable-code
# -Wcast-align
# -Wcast-function-type
# -Wcast-qual
# -Wnull-dereference
# -Wuninitialized
# -Wunused
# -Wreturn-type
# -Wredundant-decls
# )
set(WARNING_FLAGS_IAR "")
#if (BUILD_ZEPHYR)
# set(BOARD_ROOT ${TOP}/hw/bsp/${FAMILY})
# find_package(Zephyr REQUIRED HINTS ${TOP}/lib/zephyr)
@@ -182,7 +154,6 @@ endfunction()
# Add RTOS to example
function(family_add_rtos TARGET RTOS)
if (RTOS STREQUAL "freertos")
# freertos config
if (NOT TARGET freertos_config)
add_library(freertos_config INTERFACE)
target_include_directories(freertos_config INTERFACE ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/${FAMILY}/FreeRTOSConfig)
@@ -190,12 +161,16 @@ function(family_add_rtos TARGET RTOS)
target_link_libraries(freertos_config INTERFACE board_${BOARD})
endif()
# freertos kernel
if (NOT TARGET freertos_kernel)
add_subdirectory(${TOP}/lib/FreeRTOS-Kernel ${CMAKE_BINARY_DIR}/lib/freertos_kernel)
endif ()
target_link_libraries(${TARGET} PUBLIC freertos_kernel)
target_compile_definitions(${TARGET} PUBLIC CFG_TUSB_OS=OPT_OS_FREERTOS)
elseif (RTOS STREQUAL "zephyr")
target_compile_definitions(${TARGET} PUBLIC CFG_TUSB_OS=OPT_OS_ZEPHYR)
target_include_directories(${TARGET} PUBLIC ${ZEPHYR_BASE}/include)
target_link_libraries(${TARGET} PUBLIC zephyr_interface kernel)
endif ()
endfunction()
@@ -203,6 +178,7 @@ endfunction()
function(family_configure_common TARGET RTOS)
family_add_rtos(${TARGET} ${RTOS})
# Add BOARD_${BOARD} define
string(TOUPPER ${BOARD} BOARD_UPPER)
string(REPLACE "-" "_" BOARD_UPPER ${BOARD_UPPER})
target_compile_definitions(${TARGET} PUBLIC
@@ -215,20 +191,6 @@ function(family_configure_common TARGET RTOS)
target_compile_options(${TARGET} PUBLIC ${CFLAGS_CLI})
endif()
target_compile_options(${TARGET} PUBLIC ${WARNING_FLAGS_${CMAKE_C_COMPILER_ID}})
# Generate linker map file
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
target_link_options(${TARGET} PUBLIC "LINKER:-Map=$<TARGET_FILE:${TARGET}>.map")
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 12.0 AND NO_WARN_RWX_SEGMENTS_SUPPORTED)
# target_link_options(${TARGET} PUBLIC "LINKER:--no-warn-rwx-segments")
endif ()
elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang")
target_link_options(${TARGET} PUBLIC "LINKER:-Map=$<TARGET_FILE:${TARGET}>.map")
elseif (CMAKE_C_COMPILER_ID STREQUAL "IAR")
target_link_options(${TARGET} PUBLIC "LINKER:--map=$<TARGET_FILE:${TARGET}>.map")
endif()
# ETM Trace option
if (TRACE_ETM STREQUAL "1")
target_compile_definitions(${TARGET} PUBLIC TRACE_ETM)
@@ -248,6 +210,42 @@ function(family_configure_common TARGET RTOS)
endif ()
endif ()
if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
target_compile_options(${TARGET} PRIVATE
-Wall
-Wextra
#-Werror
-Wfatal-errors
-Wdouble-promotion
-Wstrict-prototypes
-Wstrict-overflow
-Werror-implicit-function-declaration
-Wfloat-equal
-Wundef
-Wshadow
-Wwrite-strings
-Wsign-compare
-Wmissing-format-attribute
-Wunreachable-code
-Wcast-align
-Wcast-function-type
-Wcast-qual
-Wnull-dereference
-Wuninitialized
-Wunused
-Wunused-function
-Wreturn-type
-Wredundant-decls
-Wmissing-prototypes
)
target_link_options(${TARGET} PUBLIC "LINKER:-Map=$<TARGET_FILE:${TARGET}>.map")
if (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 12.0 AND NO_WARN_RWX_SEGMENTS_SUPPORTED)
target_link_options(${TARGET} PUBLIC "LINKER:--no-warn-rwx-segments")
endif ()
elseif (CMAKE_C_COMPILER_ID STREQUAL "IAR")
target_link_options(${TARGET} PUBLIC "LINKER:--map=$<TARGET_FILE:${TARGET}>.map")
endif ()
# run size after build
# find_program(SIZE_EXE ${CMAKE_SIZE})
# if(NOT ${SIZE_EXE} STREQUAL SIZE_EXE-NOTFOUND)
@@ -257,54 +255,32 @@ function(family_configure_common TARGET RTOS)
# endif ()
endfunction()
# Add tinyusb to example
# Add tinyusb to target with RTOS
function(family_add_tinyusb TARGET OPT_MCU RTOS)
# tinyusb target is built for each example since it depends on example's tusb_config.h
set(TINYUSB_TARGET_PREFIX ${TARGET}-)
add_library(${TARGET}-tinyusb_config INTERFACE)
# path to tusb_config.h
target_include_directories(${TARGET}-tinyusb_config INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/src)
target_compile_definitions(${TARGET}-tinyusb_config INTERFACE CFG_TUSB_MCU=${OPT_MCU})
if (DEFINED LOG)
target_compile_definitions(${TARGET}-tinyusb_config INTERFACE CFG_TUSB_DEBUG=${LOG})
if (LOG STREQUAL "4")
# no inline for debug level 4
target_compile_definitions(${TARGET}-tinyusb_config INTERFACE TU_ATTR_ALWAYS_INLINE=)
endif ()
endif()
if (RTOS STREQUAL "freertos")
target_compile_definitions(${TARGET}-tinyusb_config INTERFACE CFG_TUSB_OS=OPT_OS_FREERTOS)
elseif (RTOS STREQUAL "zephyr")
target_compile_definitions(${TARGET}-tinyusb_config INTERFACE CFG_TUSB_OS=OPT_OS_ZEPHYR)
endif ()
# tinyusb's CMakeList.txt
add_subdirectory(${TOP}/src ${CMAKE_CURRENT_BINARY_DIR}/tinyusb)
if (RTOS STREQUAL "freertos")
# link tinyusb with freeRTOS kernel
target_link_libraries(${TARGET}-tinyusb PUBLIC freertos_kernel)
elseif (RTOS STREQUAL "zephyr")
target_include_directories(${TARGET}-tinyusb PUBLIC ${ZEPHYR_BASE}/include)
endif ()
# Add TinyUSB sources, include and common define
tinyusb_target_add(${TARGET})
# path to tusb_config.h
target_include_directories(${TARGET} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)
target_compile_definitions(${TARGET} PUBLIC CFG_TUSB_MCU=${OPT_MCU})
if (DEFINED LOG)
target_compile_definitions(${TARGET} PUBLIC CFG_TUSB_DEBUG=${LOG})
if (LOG STREQUAL "4") # no inline for debug level 4
target_compile_definitions(${TARGET} PUBLIC TU_ATTR_ALWAYS_INLINE=)
endif ()
endif()
# use max3421 as host controller
if (MAX3421_HOST STREQUAL "1")
target_compile_definitions(${TARGET}-tinyusb_config INTERFACE CFG_TUH_MAX3421=1)
target_sources(${TARGET}-tinyusb PUBLIC
target_compile_definitions(${TARGET} PUBLIC CFG_TUH_MAX3421=1)
target_sources(${TARGET} PUBLIC
${TOP}/src/portable/analog/max3421/hcd_max3421.c
)
endif ()
# compile define from command line
if(DEFINED CFLAGS_CLI)
separate_arguments(CFLAGS_CLI)
target_compile_options(${TARGET}-tinyusb PUBLIC ${CFLAGS_CLI})
endif()
endfunction()
# Add bin/hex output
@@ -330,10 +306,10 @@ function(family_add_uf2 TARGET FAMILY_ID)
VERBATIM)
endfunction()
#----------------------------------
#-------------------------------------------------------
# Example Target Configure (Default rule)
# These function can be redefined in FAMILY/family.cmake
#----------------------------------
#--------------------------------------------------------
function(family_configure_example TARGET RTOS)
# empty function, should be redefined in FAMILY/family.cmake