Merge pull request #2127 from hathach/rp2040-cmake-cleanup

Rp2040 cmake cleanup
This commit is contained in:
Ha Thach 2023-06-26 23:50:38 +07:00 committed by GitHub
commit bc0d6c7e92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 340 additions and 341 deletions

2
.idea/cmake.xml generated
View File

@ -25,7 +25,7 @@
</envs> </envs>
</ADDITIONAL_GENERATION_ENVIRONMENT> </ADDITIONAL_GENERATION_ENVIRONMENT>
</configuration> </configuration>
<configuration PROFILE_NAME="rp2040" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=raspberry_pi_pico" /> <configuration PROFILE_NAME="rp2040" ENABLED="true" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=raspberry_pi_pico -DLOG=2 -DLOGGER=RTT" />
<configuration PROFILE_NAME="rt1010 evk" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=mimxrt1010_evk" /> <configuration PROFILE_NAME="rt1010 evk" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=mimxrt1010_evk" />
<configuration PROFILE_NAME="rt1060 evk" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=mimxrt1060_evk" /> <configuration PROFILE_NAME="rt1060 evk" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=mimxrt1060_evk" />
<configuration PROFILE_NAME="rt1064 evk" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=mimxrt1064_evk" /> <configuration PROFILE_NAME="rt1064 evk" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=mimxrt1064_evk" />

View File

@ -93,12 +93,12 @@ bool __no_inline_not_in_flash_func(get_bootsel_button)(void) {
static void stdio_rtt_write (const char *buf, int length) static void stdio_rtt_write (const char *buf, int length)
{ {
SEGGER_RTT_Write(0, buf, length); SEGGER_RTT_Write(0, buf, (unsigned) length);
} }
static int stdio_rtt_read (char *buf, int len) static int stdio_rtt_read (char *buf, int len)
{ {
return SEGGER_RTT_Read(0, buf, len); return (int) SEGGER_RTT_Read(0, buf, (unsigned) len);
} }
static stdio_driver_t stdio_rtt = static stdio_driver_t stdio_rtt =

View File

@ -1,72 +1,68 @@
cmake_minimum_required(VERSION 3.13) cmake_minimum_required(VERSION 3.13)
if (NOT TARGET _rp2040_family_inclusion_marker) include_guard()
add_library(_rp2040_family_inclusion_marker INTERFACE)
if (NOT BOARD) if (NOT BOARD)
message("BOARD not specified, defaulting to pico_sdk") message("BOARD not specified, defaulting to pico_sdk")
set(BOARD pico_sdk) set(BOARD pico_sdk)
endif() endif()
# add the SDK in case we are standalone tinyusb example (noop if already present) # add the SDK in case we are standalone tinyusb example (noop if already present)
include(${CMAKE_CURRENT_LIST_DIR}/pico_sdk_import.cmake) include(${CMAKE_CURRENT_LIST_DIR}/pico_sdk_import.cmake)
# include basic family CMake functionality # include basic family CMake functionality
set(FAMILY_MCUS RP2040) set(FAMILY_MCUS RP2040)
include(${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/board.cmake) include(${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/board.cmake)
# TOP is absolute path to root directory of TinyUSB git repo if (NOT PICO_TINYUSB_PATH)
#set(TOP "${CMAKE_CURRENT_LIST_DIR}/../../..")
#get_filename_component(TOP "${TOP}" REALPATH)
if (NOT PICO_TINYUSB_PATH)
set(PICO_TINYUSB_PATH ${TOP}) set(PICO_TINYUSB_PATH ${TOP})
endif() endif()
if (NOT TINYUSB_OPT_OS) if (NOT TINYUSB_OPT_OS)
set(TINYUSB_OPT_OS OPT_OS_PICO) set(TINYUSB_OPT_OS OPT_OS_PICO)
endif() endif()
#------------------------------------ #------------------------------------
# Base config for both device and host; wrapped by SDK's tinyusb_common # Base config for both device and host; wrapped by SDK's tinyusb_common
#------------------------------------ #------------------------------------
add_library(tinyusb_common_base INTERFACE) add_library(tinyusb_common_base INTERFACE)
target_sources(tinyusb_common_base INTERFACE target_sources(tinyusb_common_base INTERFACE
${TOP}/src/tusb.c ${TOP}/src/tusb.c
${TOP}/src/common/tusb_fifo.c ${TOP}/src/common/tusb_fifo.c
) )
target_include_directories(tinyusb_common_base INTERFACE target_include_directories(tinyusb_common_base INTERFACE
${TOP}/src ${TOP}/src
${TOP}/src/common
${TOP}/hw
) )
target_link_libraries(tinyusb_common_base INTERFACE if(DEFINED LOG)
set(TINYUSB_DEBUG_LEVEL ${LOG})
elseif (CMAKE_BUILD_TYPE STREQUAL "Debug")
message("Compiling TinyUSB with CFG_TUSB_DEBUG=1")
set(TINYUSB_DEBUG_LEVEL 1)
else ()
set(TINYUSB_DEBUG_LEVEL 0)
endif()
target_compile_definitions(tinyusb_common_base INTERFACE
CFG_TUSB_MCU=OPT_MCU_RP2040
CFG_TUSB_OS=${TINYUSB_OPT_OS}
CFG_TUSB_DEBUG=${TINYUSB_DEBUG_LEVEL}
)
target_link_libraries(tinyusb_common_base INTERFACE
hardware_structs hardware_structs
hardware_irq hardware_irq
hardware_resets hardware_resets
pico_sync pico_sync
) )
set(TINYUSB_DEBUG_LEVEL 0) #------------------------------------
if (CMAKE_BUILD_TYPE STREQUAL "Debug") # Base config for device mode; wrapped by SDK's tinyusb_device
message("Compiling TinyUSB with CFG_TUSB_DEBUG=1") #------------------------------------
set(TINYUSB_DEBUG_LEVEL 1) add_library(tinyusb_device_base INTERFACE)
endif() target_sources(tinyusb_device_base INTERFACE
target_compile_definitions(tinyusb_common_base INTERFACE
CFG_TUSB_MCU=OPT_MCU_RP2040
CFG_TUSB_OS=${TINYUSB_OPT_OS}
#CFG_TUSB_DEBUG=${TINYUSB_DEBUG_LEVEL}
)
#------------------------------------
# Base config for device mode; wrapped by SDK's tinyusb_device
#------------------------------------
add_library(tinyusb_device_base INTERFACE)
target_sources(tinyusb_device_base INTERFACE
${TOP}/src/portable/raspberrypi/rp2040/dcd_rp2040.c ${TOP}/src/portable/raspberrypi/rp2040/dcd_rp2040.c
${TOP}/src/portable/raspberrypi/rp2040/rp2040_usb.c ${TOP}/src/portable/raspberrypi/rp2040/rp2040_usb.c
${TOP}/src/device/usbd.c ${TOP}/src/device/usbd.c
@ -85,11 +81,11 @@ if (NOT TARGET _rp2040_family_inclusion_marker)
${TOP}/src/class/video/video_device.c ${TOP}/src/class/video/video_device.c
) )
#------------------------------------ #------------------------------------
# Base config for host mode; wrapped by SDK's tinyusb_host # Base config for host mode; wrapped by SDK's tinyusb_host
#------------------------------------ #------------------------------------
add_library(tinyusb_host_base INTERFACE) add_library(tinyusb_host_base INTERFACE)
target_sources(tinyusb_host_base INTERFACE target_sources(tinyusb_host_base INTERFACE
${TOP}/src/portable/raspberrypi/rp2040/hcd_rp2040.c ${TOP}/src/portable/raspberrypi/rp2040/hcd_rp2040.c
${TOP}/src/portable/raspberrypi/rp2040/rp2040_usb.c ${TOP}/src/portable/raspberrypi/rp2040/rp2040_usb.c
${TOP}/src/host/usbh.c ${TOP}/src/host/usbh.c
@ -100,34 +96,31 @@ if (NOT TARGET _rp2040_family_inclusion_marker)
${TOP}/src/class/vendor/vendor_host.c ${TOP}/src/class/vendor/vendor_host.c
) )
# Sometimes have to do host specific actions in mostly common functions # Sometimes have to do host specific actions in mostly common functions
target_compile_definitions(tinyusb_host_base INTERFACE target_compile_definitions(tinyusb_host_base INTERFACE
RP2040_USB_HOST_MODE=1 RP2040_USB_HOST_MODE=1
) )
#------------------------------------ #------------------------------------
# BSP & Additions # BSP & Additions
#------------------------------------ #------------------------------------
add_library(tinyusb_bsp INTERFACE) add_library(tinyusb_bsp INTERFACE)
target_sources(tinyusb_bsp INTERFACE target_sources(tinyusb_bsp INTERFACE
${TOP}/hw/bsp/rp2040/family.c ${TOP}/hw/bsp/rp2040/family.c
) )
# target_include_directories(tinyusb_bsp INTERFACE target_include_directories(tinyusb_bsp INTERFACE
# ${TOP}/hw/bsp/rp2040) ${TOP}/hw
# tinyusb_additions will hold our extra settings for examples
add_library(tinyusb_additions INTERFACE)
target_compile_definitions(tinyusb_additions INTERFACE
PICO_RP2040_USB_DEVICE_ENUMERATION_FIX=1
PICO_RP2040_USB_DEVICE_UFRAME_FIX=1
) )
if(DEFINED LOG) # tinyusb_additions will hold our extra settings for examples
target_compile_definitions(tinyusb_additions INTERFACE CFG_TUSB_DEBUG=${LOG}) add_library(tinyusb_additions INTERFACE)
endif()
if(LOGGER STREQUAL "rtt") target_compile_definitions(tinyusb_additions INTERFACE
PICO_RP2040_USB_DEVICE_ENUMERATION_FIX=1
PICO_RP2040_USB_DEVICE_UFRAME_FIX=1
)
if(LOGGER STREQUAL "RTT" OR LOGGER STREQUAL "rtt")
target_compile_definitions(tinyusb_additions INTERFACE target_compile_definitions(tinyusb_additions INTERFACE
LOGGER_RTT LOGGER_RTT
SEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL SEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
@ -137,22 +130,26 @@ if (NOT TARGET _rp2040_family_inclusion_marker)
${TOP}/lib/SEGGER_RTT/RTT/SEGGER_RTT.c ${TOP}/lib/SEGGER_RTT/RTT/SEGGER_RTT.c
) )
set_source_files_properties(${TOP}/lib/SEGGER_RTT/RTT/SEGGER_RTT.c
PROPERTIES
COMPILE_FLAGS "-Wno-cast-qual -Wno-cast-align -Wno-sign-conversion")
target_include_directories(tinyusb_additions INTERFACE target_include_directories(tinyusb_additions INTERFACE
${TOP}/lib/SEGGER_RTT/RTT ${TOP}/lib/SEGGER_RTT/RTT
) )
endif() endif()
#------------------------------------ #------------------------------------
# Functions # Functions
#------------------------------------ #------------------------------------
function(family_configure_target TARGET) function(family_configure_target TARGET)
pico_add_extra_outputs(${TARGET}) pico_add_extra_outputs(${TARGET})
pico_enable_stdio_uart(${TARGET} 1) pico_enable_stdio_uart(${TARGET} 1)
target_link_libraries(${TARGET} PUBLIC pico_stdlib pico_bootsel_via_double_reset tinyusb_board tinyusb_additions) target_link_libraries(${TARGET} PUBLIC pico_stdlib pico_bootsel_via_double_reset tinyusb_board tinyusb_additions)
endfunction() endfunction()
function(rp2040_family_configure_example_warnings TARGET) function(rp2040_family_configure_example_warnings TARGET)
if (NOT PICO_TINYUSB_NO_EXAMPLE_WARNINGS) if (NOT PICO_TINYUSB_NO_EXAMPLE_WARNINGS)
family_add_default_example_warnings(${TARGET}) family_add_default_example_warnings(${TARGET})
endif() endif()
@ -160,19 +157,19 @@ if (NOT TARGET _rp2040_family_inclusion_marker)
target_compile_options(${TARGET} PRIVATE -Wno-unreachable-code) target_compile_options(${TARGET} PRIVATE -Wno-unreachable-code)
endif() endif()
suppress_tinyusb_warnings() suppress_tinyusb_warnings()
endfunction() endfunction()
function(family_configure_device_example TARGET) function(family_configure_device_example TARGET)
family_configure_target(${TARGET}) family_configure_target(${TARGET})
target_link_libraries(${TARGET} PUBLIC pico_stdlib tinyusb_device) target_link_libraries(${TARGET} PUBLIC pico_stdlib tinyusb_device)
rp2040_family_configure_example_warnings(${TARGET}) rp2040_family_configure_example_warnings(${TARGET})
endfunction() endfunction()
function(family_add_pico_pio_usb TARGET) function(family_add_pico_pio_usb TARGET)
target_link_libraries(${TARGET} PUBLIC tinyusb_pico_pio_usb) target_link_libraries(${TARGET} PUBLIC tinyusb_pico_pio_usb)
endfunction() endfunction()
function(family_configure_host_example TARGET) function(family_configure_host_example TARGET)
family_configure_target(${TARGET}) family_configure_target(${TARGET})
target_link_libraries(${TARGET} PUBLIC pico_stdlib tinyusb_host) target_link_libraries(${TARGET} PUBLIC pico_stdlib tinyusb_host)
rp2040_family_configure_example_warnings(${TARGET}) rp2040_family_configure_example_warnings(${TARGET})
@ -184,16 +181,16 @@ if (NOT TARGET _rp2040_family_inclusion_marker)
family_add_pico_pio_usb(${PROJECT}) family_add_pico_pio_usb(${PROJECT})
endif() endif()
endif() endif()
endfunction() endfunction()
function(family_configure_dual_usb_example TARGET) function(family_configure_dual_usb_example TARGET)
family_configure_target(${TARGET}) family_configure_target(${TARGET})
# require tinyusb_pico_pio_usb # require tinyusb_pico_pio_usb
target_link_libraries(${TARGET} PUBLIC pico_stdlib tinyusb_device tinyusb_host tinyusb_pico_pio_usb ) target_link_libraries(${TARGET} PUBLIC pico_stdlib tinyusb_device tinyusb_host tinyusb_pico_pio_usb )
rp2040_family_configure_example_warnings(${TARGET}) rp2040_family_configure_example_warnings(${TARGET})
endfunction() endfunction()
function(check_and_add_pico_pio_usb_support) function(check_and_add_pico_pio_usb_support)
# check for pico_generate_pio_header (as depending on environment we may be called before SDK is # check for pico_generate_pio_header (as depending on environment we may be called before SDK is
# initialized in which case it isn't available yet), and only do the initialization once # initialized in which case it isn't available yet), and only do the initialization once
if (COMMAND pico_generate_pio_header AND NOT TARGET tinyusb_pico_pio_usb) if (COMMAND pico_generate_pio_header AND NOT TARGET tinyusb_pico_pio_usb)
@ -239,14 +236,14 @@ if (NOT TARGET _rp2040_family_inclusion_marker)
pico_generate_pio_header(tinyusb_pico_pio_usb ${PICO_PIO_USB_PATH}/src/usb_rx.pio) pico_generate_pio_header(tinyusb_pico_pio_usb ${PICO_PIO_USB_PATH}/src/usb_rx.pio)
endif() endif()
endif() endif()
endfunction() endfunction()
# Try to add Pico-PIO_USB support now for the case where this file is included directly # Try to add Pico-PIO_USB support now for the case where this file is included directly
# after Pico SDK initialization, but without using the family_ functions (as is the case # after Pico SDK initialization, but without using the family_ functions (as is the case
# when included by the SDK itself) # when included by the SDK itself)
check_and_add_pico_pio_usb_support() check_and_add_pico_pio_usb_support()
function(family_initialize_project PROJECT DIR) function(family_initialize_project PROJECT DIR)
# call the original version of this function from family_common.cmake # call the original version of this function from family_common.cmake
_family_initialize_project(${PROJECT} ${DIR}) _family_initialize_project(${PROJECT} ${DIR})
enable_language(C CXX ASM) enable_language(C CXX ASM)
@ -254,10 +251,10 @@ if (NOT TARGET _rp2040_family_inclusion_marker)
# now re-check for adding Pico-PIO_USB support now SDK is definitely available # now re-check for adding Pico-PIO_USB support now SDK is definitely available
check_and_add_pico_pio_usb_support() check_and_add_pico_pio_usb_support()
endfunction() endfunction()
# This method must be called from the project scope to suppress known warnings in TinyUSB source files # This method must be called from the project scope to suppress known warnings in TinyUSB source files
function(suppress_tinyusb_warnings) function(suppress_tinyusb_warnings)
# some of these are pretty silly warnings only occurring in some older GCC versions 9 or prior # some of these are pretty silly warnings only occurring in some older GCC versions 9 or prior
if (CMAKE_C_COMPILER_ID STREQUAL "GNU") if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
if (CMAKE_C_COMPILER_VERSION VERSION_LESS 10.0) if (CMAKE_C_COMPILER_VERSION VERSION_LESS 10.0)
@ -329,9 +326,8 @@ if (NOT TARGET _rp2040_family_inclusion_marker)
PROPERTIES PROPERTIES
COMPILE_FLAGS "-Wno-cast-qual") COMPILE_FLAGS "-Wno-cast-qual")
endif() endif()
endfunction() endfunction()
# rp2040 does not support freeRTOS example yet # rp2040 does not support freeRTOS example yet
function(family_add_freertos TARGET) function(family_add_freertos TARGET)
endfunction() endfunction()
endif()

View File

@ -75,8 +75,11 @@ endfunction()
#------------------------------------ #------------------------------------
# TinyUSB as library target # TinyUSB as library target
#------------------------------------ #------------------------------------
set(TINYUSB_TARGET "tinyusb") if (NOT DEFINED TINYUSB_TARGET)
set(TINYUSB_CONFIG_TARGET "tinyusb_config") set(TINYUSB_TARGET "tinyusb")
endif ()
set(TINYUSB_CONFIG_TARGET "${TINYUSB_TARGET}_config")
if (DEFINED TINYUSB_TARGET_PREFIX) if (DEFINED TINYUSB_TARGET_PREFIX)
set(TINYUSB_TARGET "${TINYUSB_TARGET_PREFIX}${TINYUSB_TARGET}") set(TINYUSB_TARGET "${TINYUSB_TARGET_PREFIX}${TINYUSB_TARGET}")

View File

@ -189,7 +189,7 @@ static void hw_endpoint_xfer(uint8_t ep_addr, uint8_t *buffer, uint16_t total_by
static void __tusb_irq_path_func(hw_handle_buff_status)(void) static void __tusb_irq_path_func(hw_handle_buff_status)(void)
{ {
uint32_t remaining_buffers = usb_hw->buf_status; uint32_t remaining_buffers = usb_hw->buf_status;
pico_trace("buf_status = 0x%08x\n", remaining_buffers); pico_trace("buf_status = 0x%08lx\n", remaining_buffers);
uint bit = 1u; uint bit = 1u;
for (uint8_t i = 0; remaining_buffers && i < USB_MAX_ENDPOINTS * 2; i++) for (uint8_t i = 0; remaining_buffers && i < USB_MAX_ENDPOINTS * 2; i++)
{ {

View File

@ -419,7 +419,7 @@ static bool __tusb_irq_path_func(e15_is_critical_frame_period) (struct hw_endpoi
if (delta < 800 || delta > 998) { if (delta < 800 || delta > 998) {
return false; return false;
} }
TU_LOG(3, "Avoiding sof %u now %lu last %lu\n", (usb_hw->sof_rd + 1) & USB_SOF_RD_BITS, time_us_32(), e15_last_sof); TU_LOG(3, "Avoiding sof %lu now %lu last %lu\n", (usb_hw->sof_rd + 1) & USB_SOF_RD_BITS, time_us_32(), e15_last_sof);
return true; return true;
} }