Skip to content

Commit 0afe1b3

Browse files
committed
example run well with cmake for imxrt
1 parent 2ac2896 commit 0afe1b3

File tree

5 files changed

+74
-63
lines changed

5 files changed

+74
-63
lines changed
Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.13)
1+
cmake_minimum_required(VERSION 3.17)
22

33
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake)
44

@@ -27,37 +27,6 @@ target_include_directories(${PROJECT} PUBLIC
2727
${CMAKE_CURRENT_SOURCE_DIR}/src
2828
)
2929

30-
if(FAMILY STREQUAL "rp2040")
31-
# Configure compilation flags and libraries for the example... see the corresponding function
32-
# in hw/bsp/FAMILY/family.cmake for details.
33-
family_configure_device_example(${PROJECT})
34-
else ()
35-
# TOP is absolute path to root directory of TinyUSB git repo
36-
set(TOP "${CMAKE_CURRENT_LIST_DIR}/../../..")
37-
get_filename_component(TOP "${TOP}" REALPATH)
38-
39-
# re-include family.cmake
40-
include(${TOP}/hw/bsp/${FAMILY}/family.cmake)
41-
42-
target_sources(${PROJECT} PUBLIC
43-
${TOP}/src/device/usbd.c
44-
${TOP}/src/device/usbd_control.c
45-
${TOP}/src/class/audio/audio_device.c
46-
${TOP}/src/class/cdc/cdc_device.c
47-
${TOP}/src/class/dfu/dfu_device.c
48-
${TOP}/src/class/dfu/dfu_rt_device.c
49-
${TOP}/src/class/hid/hid_device.c
50-
${TOP}/src/class/midi/midi_device.c
51-
${TOP}/src/class/msc/msc_device.c
52-
${TOP}/src/class/net/ecm_rndis_device.c
53-
${TOP}/src/class/net/ncm_device.c
54-
${TOP}/src/class/usbtmc/usbtmc_device.c
55-
${TOP}/src/class/vendor/vendor_device.c
56-
${TOP}/src/class/video/video_device.c
57-
)
58-
59-
target_include_directories(${PROJECT} PUBLIC
60-
${TOP}/hw
61-
${TOP}/src
62-
)
63-
endif ()
30+
# Configure compilation flags and libraries for the example... see the corresponding function
31+
# in hw/bsp/FAMILY/family.cmake for details.
32+
family_configure_device_example(${PROJECT})

examples/device/cdc_msc/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.13)
1+
cmake_minimum_required(VERSION 3.17)
22

33
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake)
44

examples/device/msc_dual_lun/CMakeLists.txt

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,33 @@
1-
cmake_minimum_required(VERSION 3.5)
1+
cmake_minimum_required(VERSION 3.17)
22

33
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake)
44

55
# gets PROJECT name for the example (e.g. <BOARD>-<DIR_NAME>)
66
family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR})
77

8-
project(${PROJECT})
8+
project(${PROJECT} C CXX ASM)
99

1010
# Checks this example is valid for the family and initializes the project
1111
family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})
1212

13+
# Espressif has its own cmake build system
14+
if(FAMILY STREQUAL "espressif")
15+
return()
16+
endif()
17+
1318
add_executable(${PROJECT})
1419

1520
# Example source
1621
target_sources(${PROJECT} PUBLIC
17-
${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
18-
${CMAKE_CURRENT_SOURCE_DIR}/src/msc_disk_dual.c
19-
${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c
20-
)
22+
${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
23+
${CMAKE_CURRENT_SOURCE_DIR}/src/msc_disk_dual.c
24+
${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c
25+
)
2126

2227
# Example include
2328
target_include_directories(${PROJECT} PUBLIC
24-
${CMAKE_CURRENT_SOURCE_DIR}/src
25-
)
29+
${CMAKE_CURRENT_SOURCE_DIR}/src
30+
)
2631

2732
# Configure compilation flags and libraries for the example... see the corresponding function
2833
# in hw/bsp/FAMILY/family.cmake for details.

hw/bsp/imxrt/family.cmake

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,46 @@
1+
# toolchain set up
2+
set(CMAKE_SYSTEM_PROCESSOR cortex-m7 CACHE INTERNAL "System Processor")
3+
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../../../cmake/toolchain/arm_${TOOLCHAIN}.cmake)
14

2-
3-
if (NOT TARGET ${PROJECT})
4-
# toolchain set up, include before project()
5-
set(CMAKE_SYSTEM_PROCESSOR cortex-m7 CACHE INTERNAL "System Processor")
6-
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_LIST_DIR}/../../../cmake/toolchain/arm_${TOOLCHAIN}.cmake)
7-
else ()
5+
function(family_configure_target TARGET)
86
if (NOT BOARD)
97
message(FATAL_ERROR "BOARD not specified")
108
endif ()
119

10+
# set output name to .elf
11+
set_target_properties(${TARGET} PROPERTIES OUTPUT_NAME ${TARGET}.elf)
12+
13+
# TOP is absolute path to root directory of TinyUSB git repo
14+
set(TOP "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../../..")
15+
get_filename_component(TOP "${TOP}" REALPATH)
16+
1217
set(SDK_DIR ${TOP}/hw/mcu/nxp/mcux-sdk)
1318
set(DEPS_SUBMODULES ${SDK_DIR})
1419

15-
# include basic family CMake functionality
16-
#set(FAMILY_MCUS RP2040)
20+
include(${CMAKE_CURRENT_FUNCTION_LIST_DIR}/boards/${BOARD}/board.cmake)
1721

18-
include(${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/board.cmake)
22+
cmake_print_variables(TOP CMAKE_CURRENT_FUNCTION_LIST_DIR)
1923

20-
target_compile_definitions(${PROJECT} PUBLIC
24+
target_compile_definitions(${TARGET} PUBLIC
2125
CFG_TUSB_MCU=OPT_MCU_MIMXRT
2226
__ARMVFP__=0
2327
__ARMFPV5__=0
2428
XIP_EXTERNAL_FLASH=1
2529
XIP_BOOT_HEADER_ENABLE=1
2630
)
2731

28-
target_link_options(${PROJECT} PUBLIC
32+
target_link_options(${TARGET} PUBLIC
2933
--specs=nosys.specs
3034
--specs=nano.specs
3135
)
3236

33-
target_sources(${PROJECT} PUBLIC
37+
target_sources(${TARGET} PUBLIC
3438
# TinyUSB
3539
${TOP}/src/portable/chipidea/ci_hs/dcd_ci_hs.c
3640
${TOP}/src/portable/chipidea/ci_hs/hcd_ci_hs.c
3741
${TOP}/src/portable/ehci/ehci.c
3842
# BSP
39-
${CMAKE_CURRENT_LIST_DIR}/family.c
43+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/family.c
4044
${SDK_DIR}/drivers/common/fsl_common.c
4145
${SDK_DIR}/drivers/igpio/fsl_gpio.c
4246
${SDK_DIR}/drivers/lpuart/fsl_lpuart.c
@@ -47,18 +51,19 @@ else ()
4751
)
4852

4953
if (TOOLCHAIN STREQUAL "gcc")
50-
target_sources(${PROJECT} PUBLIC
54+
target_sources(${TARGET} PUBLIC
5155
${SDK_DIR}/devices/${MCU_VARIANT}/gcc/startup_${MCU_VARIANT}.S
5256
)
5357

54-
target_link_options(${PROJECT} PUBLIC
58+
target_link_options(${TARGET} PUBLIC
5559
"LINKER:--script=${SDK_DIR}/devices/${MCU_VARIANT}/gcc/${MCU_VARIANT}xxxxx_flexspi_nor.ld"
5660
)
5761
endif ()
5862

59-
target_include_directories(${PROJECT} PUBLIC
60-
${CMAKE_CURRENT_LIST_DIR}
61-
${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}
63+
target_include_directories(${TARGET} PUBLIC
64+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}
65+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../../
66+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/boards/${BOARD}
6267
${SDK_DIR}/CMSIS/Include
6368
${SDK_DIR}/devices/${MCU_VARIANT}
6469
${SDK_DIR}/devices/${MCU_VARIANT}/project_template
@@ -67,4 +72,11 @@ else ()
6772
${SDK_DIR}/drivers/igpio
6873
${SDK_DIR}/drivers/lpuart
6974
)
70-
endif ()
75+
76+
# include tinyusb cmake
77+
include(${TOP}/src/CMakeLists.txt)
78+
endfunction()
79+
80+
function(family_configure_device_example TARGET)
81+
family_configure_target(${TARGET})
82+
endfunction()

src/CMakeLists.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# cmake_minimum_required(VERSION 3.17)
2+
# TODO make tinyusb as library that depends on 'tusb_config' interface that exposes the tusb_config.h file
3+
4+
target_sources(${PROJECT} PUBLIC
5+
${CMAKE_CURRENT_LIST_DIR}/tusb.c
6+
${CMAKE_CURRENT_LIST_DIR}/common/tusb_fifo.c
7+
${CMAKE_CURRENT_LIST_DIR}/device/usbd.c
8+
${CMAKE_CURRENT_LIST_DIR}/device/usbd_control.c
9+
${CMAKE_CURRENT_LIST_DIR}/class/audio/audio_device.c
10+
${CMAKE_CURRENT_LIST_DIR}/class/cdc/cdc_device.c
11+
${CMAKE_CURRENT_LIST_DIR}/class/dfu/dfu_device.c
12+
${CMAKE_CURRENT_LIST_DIR}/class/dfu/dfu_rt_device.c
13+
${CMAKE_CURRENT_LIST_DIR}/class/hid/hid_device.c
14+
${CMAKE_CURRENT_LIST_DIR}/class/midi/midi_device.c
15+
${CMAKE_CURRENT_LIST_DIR}/class/msc/msc_device.c
16+
${CMAKE_CURRENT_LIST_DIR}/class/net/ecm_rndis_device.c
17+
${CMAKE_CURRENT_LIST_DIR}/class/net/ncm_device.c
18+
${CMAKE_CURRENT_LIST_DIR}/class/usbtmc/usbtmc_device.c
19+
${CMAKE_CURRENT_LIST_DIR}/class/vendor/vendor_device.c
20+
${CMAKE_CURRENT_LIST_DIR}/class/video/video_device.c
21+
)
22+
23+
target_include_directories(${PROJECT} PUBLIC
24+
${CMAKE_CURRENT_LIST_DIR}
25+
)

0 commit comments

Comments
 (0)