Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/tinyusb: add tinyUSB netdev driver #18903

Merged
merged 8 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions drivers/Kconfig.net
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ rsource "$(RIOTCPU)/stm32/periph/Kconfig.eth"
rsource "sx126x/Kconfig"
rsource "sx127x/Kconfig"
rsource "sx1280/Kconfig"
rsource "$(RIOTPKG)/tinyusb/netdev/Kconfig"
rsource "tja1042/Kconfig"
rsource "w5100/Kconfig"
endmenu # Network Device Drivers
1 change: 1 addition & 0 deletions drivers/include/net/netdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ typedef enum {
NETDEV_ESP_ETH,
NETDEV_ESP_WIFI,
NETDEV_CDC_ECM,
NETDEV_TINYUSB,
/* add more if needed */
} netdev_type_t;
/** @} */
Expand Down
11 changes: 4 additions & 7 deletions pkg/tinyusb/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ config MODULE_TINYUSB_HOST
help
Select to enable tinyUSB host stack

config MODULE_TINYUSB_LIB_NETWORKING
bool

config MODULE_TINYUSB_PORTABLE_ESPRESSIF
bool
help
Expand Down Expand Up @@ -170,13 +173,7 @@ menu "Device Classes"
bool "Musical Instrument Digital Interface (MIDI)"
depends on MODULE_TINYUSB_DEVICE

config MODULE_TINYUSB_CLASS_NET_ECM_RNDIS
bool "Network with RNDIS, Ethernet Control Model (ECM)"
depends on MODULE_TINYUSB_DEVICE

config MODULE_TINYUSB_CLASS_NET_NCM
bool "Network with Network Control Model (NCM)"
depends on MODULE_TINYUSB_DEVICE
rsource "Kconfig.net"

config MODULE_TINYUSB_CLASS_USBTMC
bool "Test and Measurement Class (USBTMC)"
Expand Down
60 changes: 60 additions & 0 deletions pkg/tinyusb/Kconfig.net
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Copyright (c) 2022 Gunar Schorcht
#
# This file is subject to the terms and conditions of the GNU Lesser
# General Public License v2.1. See the file LICENSE in the top level
# directory for more details.
#

menuconfig MODULE_TINYUSB_CLASS_NET
bool "Network Device Class"
depends on MODULE_TINYUSB_DEVICE

if MODULE_TINYUSB_CLASS_NET

config MODULE_TINYUSB_CLASS_NET_CDC_ECM
bool "CDC ECM network device"
default y

config MODULE_TINYUSB_CLASS_NET_CDC_NCM
bool "CDC NCM network device"

config MODULE_TINYUSB_CLASS_NET_RNDIS
bool "RNDIS network device"
select MODULE_TINYUSB_LIB_NETWORKING

config TUSBD_NET_NUMOF
int
default 1

if TUSBD_NET_NUMOF > 0

config TUSBD_NET_NOTIF_EP_SIZE
int "Net Notification endpoint size [byte]"
default 64

config TUSBD_NET_FS_EP_SIZE
int "Net Full-Speed endpoint size [byte]"
default 64

config TUSBD_NET_HS_EP_SIZE
int "Net High-Speed endpoint size [byte]"
default 512

config TUSBD_NET_MTU_SIZE
int "MTU size [byte]"
default 1514

config TUSBD_NET_DESC_STRING
string "Class descriptor string"
default "TinyUSB Net"

config TUSBD_NET_CUSTOM_MAC
bool "Use custom MAC address string"

config TUSBD_NET_MAC_STRING
string "MAC address string"
depends on TUSBD_ECM_CUSTOM_MAC
default "0123456789ab"

endif # TUSBD_NET_NUMOF > 0
endif # MODULE_TINYUSB_CLASS_NET
14 changes: 9 additions & 5 deletions pkg/tinyusb/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ PKG_LICENSE=MIT
include $(RIOTBASE)/pkg/pkg.mk

PSRC = $(PKG_SOURCE_DIR)/src
PLIB = $(PKG_SOURCE_DIR)/lib

.PHONY: all

all: $(filter tinyusb_% stdio_tinyusb_cdc_acm,$(USEMODULE))
all: $(filter tinyusb_% stdio_tinyusb_cdc_acm,$(filter-out tinyusb_class_net_%,$(USEMODULE)))
$(QQ)"$(MAKE)" -C $(PSRC) -f $(RIOTBASE)/Makefile.base MODULE=tinyusb

stdio_tinyusb_cdc_acm:
Expand All @@ -26,6 +27,9 @@ tinyusb_dfu:
tinyusb_hw:
$(QQ)"$(MAKE)" -C $(RIOTPKG)/$(PKG_NAME)/hw

tinyusb_netdev:
$(QQ)"$(MAKE)" -C $(RIOTPKG)/$(PKG_NAME)/netdev

tinyusb_class_audio:
$(QQ)"$(MAKE)" -C $(PSRC)/class/audio -f $(RIOTBASE)/Makefile.base MODULE=$@

Expand All @@ -50,10 +54,7 @@ tinyusb_class_midi:
tinyusb_class_msc:
$(QQ)"$(MAKE)" -C $(PSRC)/class/msc -f $(RIOTBASE)/Makefile.base MODULE=$@

tinyusb_class_net_ecm_rndis:
$(QQ)"$(MAKE)" -C $(PSRC)/class/net -f $(RIOTBASE)/Makefile.base MODULE=$@

tinyusb_class_net_ncm:
tinyusb_class_net:
$(QQ)"$(MAKE)" -C $(PSRC)/class/net -f $(RIOTBASE)/Makefile.base MODULE=$@

tinyusb_class_usbtmc:
Expand All @@ -74,6 +75,9 @@ tinyusb_device:
tinyusb_host:
$(QQ)"$(MAKE)" -C $(PSRC)/host -f $(RIOTBASE)/Makefile.base MODULE=$@

tinyusb_lib_networking:
$(QQ)"$(MAKE)" -C $(PLIB)/networking -f $(RIOTPKG)/$(PKG_NAME)/Makefile.lib_networking

tinyusb_portable_espressif:
$(QQ)"$(MAKE)" -C $(PSRC)/portable/espressif/esp32sx -f $(RIOTBASE)/Makefile.base MODULE=$@

Expand Down
23 changes: 19 additions & 4 deletions pkg/tinyusb/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,24 @@ ifneq (,$(filter tinyusb_dfu,$(USEMODULE)))
endif
endif

ifneq (,$(filter tinyusb_class_net_%,$(USEMODULE)))
USEMODULE += tinyusb_class_net
endif

ifneq (,$(filter tinyusb_netdev,$(USEMODULE)))
USEMODULE += luid
USEMODULE += netdev_eth
USEMODULE += tinyusb_device
ifeq (,$(filter tinyusb_class_net_%,$(USEMODULE)))
# default to CDC ECM
USEMODULE += tinyusb_class_net_cdc_ecm
endif
endif

ifneq (,$(filter tinyusb_class_net_rndis,$(USEMODULE)))
USEMODULE += tinyusb_lib_networking
endif

ifeq (,$(filter tinyusb_class_%,$(USEMODULE)))
$(error At least one tinyusb_class_* module has to be enabled)
endif
Expand Down Expand Up @@ -60,10 +78,7 @@ endif
ifneq (,$(filter tinyusb_class_midi,$(USEMODULE)))
USEMODULE += tinyusb_device
endif
ifneq (,$(filter tinyusb_class_net_ecm_rndis,$(USEMODULE)))
USEMODULE += tinyusb_device
endif
ifneq (,$(filter tinyusb_class_net_ncm,$(USEMODULE)))
ifneq (,$(filter tinyusb_class_net,$(USEMODULE)))
USEMODULE += tinyusb_device
endif
ifneq (,$(filter tinyusb_class_usbtmc,$(USEMODULE)))
Expand Down
10 changes: 9 additions & 1 deletion pkg/tinyusb/Makefile.include
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
PSEUDOMODULES += tinyusb_class_net_cdc_ecm
PSEUDOMODULES += tinyusb_class_net_cdc_ncm
PSEUDOMODULES += tinyusb_class_net_rndis

INCLUDES += -I$(RIOTBASE)/pkg/tinyusb/contrib
INCLUDES += -I$(RIOTBASE)/pkg/tinyusb/contrib/include
INCLUDES += -I$(RIOTBASE)/pkg/tinyusb/hw/include
Expand Down Expand Up @@ -30,10 +34,14 @@ else
$(error CPU $(CPU) or CPU family $(CPU_FAM) not supported)
endif

ifneq (,$(filter tinyusb_class_net_ecm_rndis,$(USEMODULE)))
ifneq (,$(filter tinyusb_class_net tinyusb_lib_networking,$(USEMODULE)))
INCLUDES += -I$(PKGDIRBASE)/tinyusb/lib/networking
endif

ifneq (,$(filter tinyusb_dfu,$(USEMODULE)))
INCLUDES += -I$(RIOTBASE)/pkg/tinyusb/dfu/include
endif

ifneq (,$(filter tinyusb_netdev,$(USEMODULE)))
INCLUDES += -I$(RIOTBASE)/pkg/tinyusb/netdev/include
endif
5 changes: 5 additions & 0 deletions pkg/tinyusb/Makefile.lib_networking
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
MODULE = tinyusb_lib_networking

SRC = rndis_reports.c

include $(RIOTBASE)/Makefile.base
4 changes: 4 additions & 0 deletions pkg/tinyusb/contrib/include/tinyusb.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
extern "C" {
#endif

#if MODULE_TINYUSB_CLASS_NET_RNDIS
#define SIZEOF_ETH_HDR 14
#endif

/**
* @brief Initialize the tinyUSB stack including used peripherals and start the tinyUSB thread
*
Expand Down
51 changes: 49 additions & 2 deletions pkg/tinyusb/contrib/include/tinyusb_descriptors.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ enum {
#if CONFIG_TUSBD_MSC_NUMOF
TUSBD_ITF_MSC, /**< MSC interface */
#endif
#if CONFIG_TUSBD_NET_NUMOF
TUSBD_ITF_NET, /**< NET Notification interface */
TUSBD_ITF_NET_DATA, /**< NET Data interface */
#endif
#if CONFIG_TUSBD_VENDOR_NUMOF
TUSBD_ITF_VENDOR, /**< Vendor interface */
#endif
Expand Down Expand Up @@ -87,6 +91,11 @@ enum {
TUSBD_EP_MSC_OUT = TUSBD_ITF_MSC + 0x01, /**< MSC EP OUT */
TUSBD_EP_MSC_IN = TUSBD_ITF_MSC + 0x81, /**< MSC EP IN */
#endif
#if CONFIG_TUSBD_NET_NUMOF
TUSBD_EP_NET_NOTIF = TUSBD_ITF_NET + 0x81, /**< NET Notification EP IN */
TUSBD_EP_NET_OUT = TUSBD_ITF_NET_DATA + 0x01, /**< NET Data EP OUT */
TUSBD_EP_NET_IN = TUSBD_ITF_NET_DATA + 0x81, /**< NET Data EP IN */
#endif
#if CONFIG_TUSBD_VENDOR_NUMOF
TUSBD_EP_VENDOR_OUT = TUSBD_ITF_VENDOR + 0x01, /**< Vendor EP OUT */
TUSBD_EP_VENDOR_IN = TUSBD_ITF_VENDOR + 0x81, /**< Vendor EP IN */
Expand Down Expand Up @@ -123,6 +132,20 @@ enum {
#if CONFIG_TUSBD_MSC_NUMOF
TUSBD_STR_IDX_MSC,
#endif

#if CONFIG_TUSBD_NET_NUMOF
#if CONFIG_TUSBD_NET_CDC_ECM
TUSBD_STR_IDX_NET_CDC_ECM,
#endif /* CONFIG_TUSBD_NET_CDC_ECM */
#if CONFIG_TUSBD_NET_CDC_NCM
TUSBD_STR_IDX_NET_CDC_NCM,
#endif /* CONFIG_TUSBD_NET_CDC_NCM */
#if CONFIG_TUSBD_NET_RNDIS
TUSBD_STR_IDX_NET_RNDIS,
#endif /* CONFIG_TUSBD_NET_RNDIS */
TUSBD_STR_IDX_NET_MAC,
#endif /* CONFIG_TUSBD_NET_NUMOF */

#if CONFIG_TUSBD_VENDOR_NUMOF
TUSBD_STR_IDX_VENDOR,
#endif
Expand All @@ -134,22 +157,46 @@ enum {
#define CONFIG_TUSBD_DFU_ALT_NUMOF 2

#if !defined(TUSBD_DESC_TOTAL_LEN)

#if CONFIG_TUSBD_NET_CDC_ECM
#define TUSBD_DESC_NET_LEN TUD_CDC_ECM_DESC_LEN
#elif CONFIG_TUSBD_NET_CDC_NCM
#define TUSBD_DESC_NET_LEN TUD_CDC_NCM_DESC_LEN
#elif CONFIG_TUSBD_NET_RNDIS
#define TUSBD_DESC_NET_LEN TUD_RNDIS_DESC_LEN
#else
#define TUSBD_DESC_NET_LEN 0
#endif

#define TUSBD_DESC_TOTAL_LEN (TUD_CONFIG_DESC_LEN + \
(CONFIG_TUSBD_CDC_NUMOF * TUD_CDC_DESC_LEN) + \
(CONFIG_TUSBD_DFU_NUMOF * TUD_DFU_DESC_LEN(CONFIG_TUSBD_DFU_ALT_NUMOF)) + \
(CONFIG_TUSBD_DFU_RT_NUMOF * TUD_DFU_RT_DESC_LEN) + \
(CONFIG_TUSBD_HID_NUMOF * TUD_HID_INOUT_DESC_LEN) + \
(CONFIG_TUSBD_MSC_NUMOF * TUD_MSC_DESC_LEN) + \
(CONFIG_TUSBD_VENDOR_NUMOF * TUD_VENDOR_DESC_LEN))
(CONFIG_TUSBD_VENDOR_NUMOF * TUD_VENDOR_DESC_LEN) + \
TUSBD_DESC_NET_LEN)

#endif /* !defined(TUSBD_DESC_TOTAL_LEN) */

/* If CDC ECM and RNDIS are used simultaneously, an alternative configuration
* descriptor is required. In this case, the main configuration descriptor
* contains the CDC ECM interface descriptor and the alternative configuration
* descriptor contains the RNDIS interface descriptor. */
#if CONFIG_TUSBD_NET_CDC_ECM && CONFIG_TUSBD_NET_RNDIS

#define TUSBD_DESC_ALT_NET_LEN TUD_RNDIS_DESC_LEN

#define TUSBD_DESC_ALT_TOTAL_LEN (TUD_CONFIG_DESC_LEN + \
(CONFIG_TUSBD_CDC_NUMOF * TUD_CDC_DESC_LEN) + \
(CONFIG_TUSBD_DFU_NUMOF * TUD_DFU_DESC_LEN(CONFIG_TUSBD_DFU_ALT_NUMOF)) + \
(CONFIG_TUSBD_DFU_RT_NUMOF * TUD_DFU_RT_DESC_LEN) + \
(CONFIG_TUSBD_HID_NUMOF * TUD_HID_INOUT_DESC_LEN) + \
(CONFIG_TUSBD_MSC_NUMOF * TUD_MSC_DESC_LEN) + \
(CONFIG_TUSBD_VENDOR_NUMOF * TUD_VENDOR_DESC_LEN))
(CONFIG_TUSBD_VENDOR_NUMOF * TUD_VENDOR_DESC_LEN) + \
TUSBD_DESC_ALT_NET_LEN)

#endif /* CONFIG_TUSBD_NET_CDC_ECM && CONFIG_TUSBD_NET_RNDIS */

#endif /* !defined(CONFIG_TUSBD_USE_CUSTOM_DESC) */

Expand Down
Loading