summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorHa Thach <[email protected]>2021-01-23 23:28:35 +0700
committerGitHub <[email protected]>2021-01-23 23:28:35 +0700
commit469ca2f1559800f4b1eabc860336ff33ed118718 (patch)
treea6b68799030fd5cdc41881ebdbd259a8ee97b1e6 /examples
parentedd91d28f5afa175d7f52ec1bf1845ff29aabab9 (diff)
parente6ce18b01990d5e06f12e0aeb57d53ce365ba7b7 (diff)
Merge pull request #600 from hathach/refactor-bsp
Refactor bsp
Diffstat (limited to 'examples')
-rw-r--r--examples/device/board_test/CMakeLists.txt64
-rw-r--r--examples/device/cdc_msc/CMakeLists.txt72
-rw-r--r--examples/device/cdc_msc/src/tusb_config.h2
-rw-r--r--examples/device/cdc_msc_freertos/CMakeLists.txt15
-rw-r--r--examples/device/hid_composite_freertos/CMakeLists.txt15
-rw-r--r--examples/device/uac2_headset/.skip.MCU_SAMD110
-rw-r--r--examples/device/uac2_headset/.skip.MCU_SAME5X0
-rw-r--r--examples/device/uac2_headset/.skip.MCU_SAMG0
-rw-r--r--examples/make.mk2
-rw-r--r--examples/rules.mk28
10 files changed, 170 insertions, 28 deletions
diff --git a/examples/device/board_test/CMakeLists.txt b/examples/device/board_test/CMakeLists.txt
index c09ffe215..54a4009fe 100644
--- a/examples/device/board_test/CMakeLists.txt
+++ b/examples/device/board_test/CMakeLists.txt
@@ -1,15 +1,65 @@
-# The following five lines of boilerplate have to be in your project's
-# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)
+# use directory name for project id
+get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME)
+
# TOP is absolute path to root directory of TinyUSB git repo
set(TOP "../../..")
get_filename_component(TOP "${TOP}" REALPATH)
-# Add example src and bsp directories
-set(EXTRA_COMPONENT_DIRS "src" "${TOP}/hw/bsp/esp32s2/boards" "${TOP}/hw/bsp/esp32s2/components")
+# Check for -DFAMILY=
+if(NOT DEFINED FAMILY)
+ message(FATAL_ERROR "Invalid FAMILY specified")
+endif()
+
+include(${TOP}/hw/bsp/${FAMILY}/family.cmake)
+project(${PROJECT})
+
+if(FAMILY STREQUAL "rp2040")
+
+pico_sdk_init()
+
+add_executable(${PROJECT})
+
+# TinyUSB Stack source
+set(SRC_TINYUSB
+ ${TOP}/src/tusb.c
+ ${TOP}/src/common/tusb_fifo.c
+ ${TOP}/src/device/usbd.c
+ ${TOP}/src/device/usbd_control.c
+ ${TOP}/src/class/audio/audio_device.c
+ ${TOP}/src/class/cdc/cdc_device.c
+ ${TOP}/src/class/dfu/dfu_rt_device.c
+ ${TOP}/src/class/hid/hid_device.c
+ ${TOP}/src/class/midi/midi_device.c
+ ${TOP}/src/class/msc/msc_device.c
+ ${TOP}/src/class/net/net_device.c
+ ${TOP}/src/class/usbtmc/usbtmc_device.c
+ ${TOP}/src/class/vendor/vendor_device.c
+ ${TOP}/src/portable/raspberrypi/${FAMILY}/dcd_rp2040.c
+ ${TOP}/src/portable/raspberrypi/${FAMILY}/rp2040_usb.c
+)
+
+target_sources(${PROJECT} PUBLIC
+ src/main.c
+ ${TOP}/hw/bsp/${FAMILY}/family.c
+ ${SRC_TINYUSB}
+)
+
+target_include_directories(${PROJECT} PUBLIC
+ src/
+ ${TOP}/hw
+ ${TOP}/src
+ ${TOP}/hw/bsp/${FAMILY}/boards/${BOARD}
+)
+
+target_compile_definitions(${PROJECT} PUBLIC
+ CFG_TUSB_MCU=OPT_MCU_RP2040
+ CFG_TUSB_OS=OPT_OS_PICO
+)
+
+target_link_libraries(${PROJECT} pico_stdlib)
-include($ENV{IDF_PATH}/tools/cmake/project.cmake)
-set(SUPPORTED_TARGETS esp32s2)
+pico_add_extra_outputs(${PROJECT})
-project(board_test)
+endif()
diff --git a/examples/device/cdc_msc/CMakeLists.txt b/examples/device/cdc_msc/CMakeLists.txt
new file mode 100644
index 000000000..ada122b62
--- /dev/null
+++ b/examples/device/cdc_msc/CMakeLists.txt
@@ -0,0 +1,72 @@
+cmake_minimum_required(VERSION 3.5)
+
+# use directory name for project id
+get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME)
+
+# TOP is absolute path to root directory of TinyUSB git repo
+set(TOP "../../..")
+get_filename_component(TOP "${TOP}" REALPATH)
+
+# Check for -DFAMILY=
+if(NOT DEFINED FAMILY)
+ message(FATAL_ERROR "Invalid FAMILY specified")
+endif()
+
+include(${TOP}/hw/bsp/${FAMILY}/family.cmake)
+project(${PROJECT})
+
+if(FAMILY STREQUAL "rp2040")
+
+pico_sdk_init()
+
+add_executable(${PROJECT})
+
+# TinyUSB Stack source
+set(SRC_TINYUSB
+ ${TOP}/src/tusb.c
+ ${TOP}/src/common/tusb_fifo.c
+ ${TOP}/src/device/usbd.c
+ ${TOP}/src/device/usbd_control.c
+ ${TOP}/src/class/audio/audio_device.c
+ ${TOP}/src/class/cdc/cdc_device.c
+ ${TOP}/src/class/dfu/dfu_rt_device.c
+ ${TOP}/src/class/hid/hid_device.c
+ ${TOP}/src/class/midi/midi_device.c
+ ${TOP}/src/class/msc/msc_device.c
+ ${TOP}/src/class/net/net_device.c
+ ${TOP}/src/class/usbtmc/usbtmc_device.c
+ ${TOP}/src/class/vendor/vendor_device.c
+ ${TOP}/src/portable/raspberrypi/${FAMILY}/dcd_rp2040.c
+ ${TOP}/src/portable/raspberrypi/${FAMILY}/rp2040_usb.c
+)
+
+# Example source
+set(SRC_EXAMPLE
+ src/main.c
+ src/msc_disk.c
+ src/usb_descriptors.c
+)
+
+target_sources(${PROJECT} PUBLIC
+ ${SRC_EXAMPLE}
+ ${TOP}/hw/bsp/${FAMILY}/family.c
+ ${SRC_TINYUSB}
+)
+
+target_include_directories(${PROJECT} PUBLIC
+ src/
+ ${TOP}/hw
+ ${TOP}/src
+ ${TOP}/hw/bsp/${FAMILY}/boards/${BOARD}
+)
+
+target_compile_definitions(${PROJECT} PUBLIC
+ CFG_TUSB_MCU=OPT_MCU_RP2040
+ CFG_TUSB_OS=OPT_OS_PICO
+)
+
+target_link_libraries(${PROJECT} pico_stdlib)
+
+pico_add_extra_outputs(${PROJECT})
+
+endif()
diff --git a/examples/device/cdc_msc/src/tusb_config.h b/examples/device/cdc_msc/src/tusb_config.h
index 1370e61c5..e0099785b 100644
--- a/examples/device/cdc_msc/src/tusb_config.h
+++ b/examples/device/cdc_msc/src/tusb_config.h
@@ -65,7 +65,9 @@
#endif
// This example doesn't use an RTOS
+#ifndef CFG_TUSB_OS
#define CFG_TUSB_OS OPT_OS_NONE
+#endif
// CFG_TUSB_DEBUG is defined by compiler in DEBUG build
// #define CFG_TUSB_DEBUG 0
diff --git a/examples/device/cdc_msc_freertos/CMakeLists.txt b/examples/device/cdc_msc_freertos/CMakeLists.txt
index 146b49cb0..2e55d8c47 100644
--- a/examples/device/cdc_msc_freertos/CMakeLists.txt
+++ b/examples/device/cdc_msc_freertos/CMakeLists.txt
@@ -1,15 +1,18 @@
-# The following five lines of boilerplate have to be in your project's
-# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)
+# use directory name for project id
+get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME)
+
# TOP is absolute path to root directory of TinyUSB git repo
set(TOP "../../..")
get_filename_component(TOP "${TOP}" REALPATH)
-# Add example src and bsp directories
-set(EXTRA_COMPONENT_DIRS "src" "${TOP}/hw/bsp/esp32s2/boards" "${TOP}/hw/bsp/esp32s2/components")
+# Check for -DFAMILY=
+if(NOT DEFINED FAMILY)
+ message(FATAL_ERROR "Invalid FAMILY specified")
+endif()
-include($ENV{IDF_PATH}/tools/cmake/project.cmake)
-set(SUPPORTED_TARGETS esp32s2)
+include(${TOP}/hw/bsp/${FAMILY}/family.cmake)
+project(${PROJECT})
project(cdc_msc_freertos)
diff --git a/examples/device/hid_composite_freertos/CMakeLists.txt b/examples/device/hid_composite_freertos/CMakeLists.txt
index 3c48e4e70..c4777f122 100644
--- a/examples/device/hid_composite_freertos/CMakeLists.txt
+++ b/examples/device/hid_composite_freertos/CMakeLists.txt
@@ -1,15 +1,18 @@
-# The following five lines of boilerplate have to be in your project's
-# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)
+# use directory name for project id
+get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME)
+
# TOP is absolute path to root directory of TinyUSB git repo
set(TOP "../../..")
get_filename_component(TOP "${TOP}" REALPATH)
-# Add example src and bsp directories
-set(EXTRA_COMPONENT_DIRS "src" "${TOP}/hw/bsp/esp32s2/boards" "${TOP}/hw/bsp/esp32s2/components")
+# Check for -DFAMILY=
+if(NOT DEFINED FAMILY)
+ message(FATAL_ERROR "Invalid FAMILY specified")
+endif()
-include($ENV{IDF_PATH}/tools/cmake/project.cmake)
-set(SUPPORTED_TARGETS esp32s2)
+include(${TOP}/hw/bsp/${FAMILY}/family.cmake)
+project(${PROJECT})
project(hid_composite_freertos)
diff --git a/examples/device/uac2_headset/.skip.MCU_SAMD11 b/examples/device/uac2_headset/.skip.MCU_SAMD11
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/examples/device/uac2_headset/.skip.MCU_SAMD11
diff --git a/examples/device/uac2_headset/.skip.MCU_SAME5X b/examples/device/uac2_headset/.skip.MCU_SAME5X
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/examples/device/uac2_headset/.skip.MCU_SAME5X
diff --git a/examples/device/uac2_headset/.skip.MCU_SAMG b/examples/device/uac2_headset/.skip.MCU_SAMG
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/examples/device/uac2_headset/.skip.MCU_SAMG
diff --git a/examples/make.mk b/examples/make.mk
index bf3b36a62..da0f60d2f 100644
--- a/examples/make.mk
+++ b/examples/make.mk
@@ -40,7 +40,7 @@ ifeq ($(FAMILY),)
include $(TOP)/hw/bsp/$(BOARD)/board.mk
else
# Include Family and Board specific defs
- include $(TOP)/$(FAMILY_PATH)/family.mk
+ -include $(TOP)/$(FAMILY_PATH)/family.mk
SRC_C += $(subst $(TOP)/,,$(wildcard $(TOP)/$(FAMILY_PATH)/*.c))
endif
diff --git a/examples/rules.mk b/examples/rules.mk
index fb1fe76c2..ab0373bac 100644
--- a/examples/rules.mk
+++ b/examples/rules.mk
@@ -2,34 +2,46 @@
# Common make rules for all examples
# ---------------------------------------
-ifeq ($(CROSS_COMPILE),xtensa-esp32s2-elf-)
+ifeq ($(FAMILY),esp32s2)
# Espressif IDF use CMake build system, this add wrapper target to call idf.py
.PHONY: all clean flash
.DEFAULT_GOAL := all
all:
- idf.py -B$(BUILD) -DBOARD=$(BOARD) build
+ idf.py -B$(BUILD) -DFAMILY=$(FAMILY) -DBOARD=$(BOARD) build
build: all
clean:
- idf.py -B$(BUILD) -DBOARD=$(BOARD) clean
+ idf.py -B$(BUILD) -DFAMILY=$(FAMILY) -DBOARD=$(BOARD) clean
+
+fullclean:
+ idf.py -B$(BUILD) -DFAMILY=$(FAMILY) -DBOARD=$(BOARD) fullclean
flash:
- idf.py -B$(BUILD) -DBOARD=$(BOARD) flash
+ idf.py -B$(BUILD) -DFAMILY=$(FAMILY) -DBOARD=$(BOARD) flash
bootloader-flash:
- idf.py -B$(BUILD) -DBOARD=$(BOARD) bootloader-flash
+ idf.py -B$(BUILD) -DFAMILY=$(FAMILY) -DBOARD=$(BOARD) bootloader-flash
app-flash:
- idf.py -B$(BUILD) -DBOARD=$(BOARD) app-flash
+ idf.py -B$(BUILD) -DFAMILY=$(FAMILY) -DBOARD=$(BOARD) app-flash
erase:
- idf.py -B$(BUILD) -DBOARD=$(BOARD) erase_flash
+ idf.py -B$(BUILD) -DFAMILY=$(FAMILY) -DBOARD=$(BOARD) erase_flash
monitor:
- idf.py -B$(BUILD) -DBOARD=$(BOARD) monitor
+ idf.py -B$(BUILD) -DFAMILY=$(FAMILY) -DBOARD=$(BOARD) monitor
+
+else ifeq ($(FAMILY),rp2040)
+
+all:
+ [ -d $(BUILD) ] || cmake -S . -B $(BUILD) -DFAMILY=$(FAMILY) -DBOARD=$(BOARD) -DPICO_BUILD_DOCS=0
+ $(MAKE) -C $(BUILD)
+
+clean:
+ $(RM) -rf $(BUILD)
else
# GNU Make build system