diff --git a/cpu/efm32/include/periph_cpu.h b/cpu/efm32/include/periph_cpu.h index 0d809f30c3..b60018246d 100644 --- a/cpu/efm32/include/periph_cpu.h +++ b/cpu/efm32/include/periph_cpu.h @@ -682,6 +682,13 @@ typedef struct { #define WDT_HAS_STOP (1U) /** @} */ +/** + * @name USB device definitions + * @{ + */ +#define USBDEV_NUM_ENDPOINTS 7 /**< Number of USB OTG FS endpoints including EP0 */ +/** @} */ + /* GPIO_LL's overrides */ #ifndef DOXYGEN diff --git a/cpu/esp32/include/periph_cpu_esp32s2.h b/cpu/esp32/include/periph_cpu_esp32s2.h index faf9cce0c4..cc54995d56 100644 --- a/cpu/esp32/include/periph_cpu_esp32s2.h +++ b/cpu/esp32/include/periph_cpu_esp32s2.h @@ -270,6 +270,11 @@ extern "C" { * @brief Buffers have to be word aligned for DMA */ #define USBDEV_CPU_DMA_ALIGNMENT (4) + +/** + * @brief Number of USB IN and OUT endpoints available + */ +#define USBDEV_NUM_ENDPOINTS DWC2_USB_OTG_FS_NUM_EP /** @} */ diff --git a/cpu/esp32/include/periph_cpu_esp32s3.h b/cpu/esp32/include/periph_cpu_esp32s3.h index 39d3cc58b0..f90932cc87 100644 --- a/cpu/esp32/include/periph_cpu_esp32s3.h +++ b/cpu/esp32/include/periph_cpu_esp32s3.h @@ -271,6 +271,11 @@ extern "C" { * @brief Buffers have to be word aligned for DMA */ #define USBDEV_CPU_DMA_ALIGNMENT (4) + +/** + * @brief Number of USB IN and OUT endpoints available + */ +#define USBDEV_NUM_ENDPOINTS DWC2_USB_OTG_FS_NUM_EP /** @} */ #ifdef __cplusplus diff --git a/cpu/gd32v/include/periph_cpu.h b/cpu/gd32v/include/periph_cpu.h index 9051edb42d..8fed2b6977 100644 --- a/cpu/gd32v/include/periph_cpu.h +++ b/cpu/gd32v/include/periph_cpu.h @@ -458,6 +458,13 @@ typedef struct { #define RTT_MIN_FREQUENCY (1U) /**< minimum RTT frequency in Hz */ /** @} */ +/** + * @name USB device definitions + * @{ + */ +#define USBDEV_NUM_ENDPOINTS 4 /**< Number of USB OTG FS endpoints including EP0 */ +/** @} */ + /** * @brief Enable the given peripheral clock * diff --git a/cpu/stm32/include/periph_cpu.h b/cpu/stm32/include/periph_cpu.h index 77cb3ac776..2fa42b2c81 100644 --- a/cpu/stm32/include/periph_cpu.h +++ b/cpu/stm32/include/periph_cpu.h @@ -113,6 +113,57 @@ typedef struct { #define HAVE_PTP_TIMER_SET_ABSOLUTE 1 /**< Native implementation available */ /** @} */ +#if !DOXYGEN /* hide implementation details */ +/** + * @name USB device definitions + * @{ + */ +/* Detect the IP version based on the available register define */ +#if defined(USB_OTG_GCCFG_NOVBUSSENS) +#define STM32_USB_OTG_CID_1x /**< USB OTG FS version 0x00001200 */ +#elif defined(USB_OTG_GCCFG_VBDEN) +#define STM32_USB_OTG_CID_2x /**< USB OTG FS version 0x00002000 */ +#elif defined(USB) +#define STM32_USB_FS_CID_1x /**< USB FS version 0x00001200 */ +#endif + +/** + * @brief Number of endpoints available with the OTG FS peripheral + * including the control endpoint + */ +#ifdef STM32_USB_OTG_CID_1x +#define STM32_USB_OTG_FS_NUM_EP (4) /**< OTG FS with 4 endpoints */ +#elif defined(STM32_USB_OTG_CID_2x) +#define STM32_USB_OTG_FS_NUM_EP (6) /**< OTG FS with 6 endpoints */ +#endif + +/** + * @brief Number of endpoints available with the OTG HS peripheral + * including the control endpoint + */ +#ifdef STM32_USB_OTG_CID_1x +#define STM32_USB_OTG_HS_NUM_EP (6) /**< OTG HS with 6 endpoints */ +#elif defined(STM32_USB_OTG_CID_2x) +#define STM32_USB_OTG_HS_NUM_EP (9) /**< OTG HS with 9 endpoints */ +#endif + +/** + * @brief Number of IN/OUT endpoints including EP0 as used by USBUS + * + * @note Since only a single number of EPs can be defined for USBUS that is + * valid for all devices, the smallest number of EPs must be used for + * multiple USB devices. + */ +#if defined(STM32_USB_OTG_FS_NUM_EP) +#define USBDEV_NUM_ENDPOINTS STM32_USB_OTG_FS_NUM_EP +#elif defined(STM32_USB_OTG_HS_NUM_EP) +#define USBDEV_NUM_ENDPOINTS STM32_USB_OTG_HS_NUM_EP +#else +#define USBDEV_NUM_ENDPOINTS 8 +#endif + +#endif /* !DOXYGEN */ + #ifdef __cplusplus } #endif diff --git a/cpu/stm32/include/usbdev_stm32.h b/cpu/stm32/include/usbdev_stm32.h index 02d234e7a2..1d0c397f1a 100644 --- a/cpu/stm32/include/usbdev_stm32.h +++ b/cpu/stm32/include/usbdev_stm32.h @@ -41,42 +41,22 @@ #include #include #include "periph_cpu.h" -#include "periph/usbdev.h" #ifdef __cplusplus extern "C" { #endif -/* Detect the IP version based on the available register define */ -#if defined(USB_OTG_GCCFG_NOVBUSSENS) -#define STM32_USB_OTG_CID_1x /**< USB OTG FS version 0x00001200 */ -#elif defined(USB_OTG_GCCFG_VBDEN) -#define STM32_USB_OTG_CID_2x /**< USB OTG FS version 0x00002000 */ -#elif defined(USB) -#define STM32_USB_FS_CID_1x /**< USB FS version 0x00001200 */ -#else -#error Unknown USB peripheral version -#endif - /** * @brief Number of endpoints available with the OTG FS peripheral * including the control endpoint */ -#ifdef STM32_USB_OTG_CID_1x -#define DWC2_USB_OTG_FS_NUM_EP (4) /**< OTG FS with 4 endpoints */ -#elif defined(STM32_USB_OTG_CID_2x) -#define DWC2_USB_OTG_FS_NUM_EP (6) /**< OTG FS with 6 endpoints */ -#endif +#define DWC2_USB_OTG_FS_NUM_EP STM32_USB_OTG_FS_NUM_EP /** * @brief Number of endpoints available with the OTG HS peripheral * including the control endpoint */ -#ifdef STM32_USB_OTG_CID_1x -#define DWC2_USB_OTG_HS_NUM_EP (6) /**< OTG HS with 6 endpoints */ -#elif defined(STM32_USB_OTG_CID_2x) -#define DWC2_USB_OTG_HS_NUM_EP (9) /**< OTG HS with 9 endpoints */ -#endif +#define DWC2_USB_OTG_HS_NUM_EP STM32_USB_OTG_HS_NUM_EP /** * @brief USB OTG FS FIFO reception buffer space in 32-bit words @@ -144,6 +124,9 @@ extern "C" { #endif #endif +/* periph/usbdev.h is included after the definitions above by intention */ +#include "periph/usbdev.h" + /** * @brief stm32 USB Device FS only peripheral device context */ diff --git a/pkg/nanors/Makefile b/pkg/nanors/Makefile index 2ae22abf82..6255eec068 100644 --- a/pkg/nanors/Makefile +++ b/pkg/nanors/Makefile @@ -1,6 +1,6 @@ PKG_NAME=nanors PKG_URL=https://github.com/sleepybishop/nanors.git -PKG_VERSION=395e5ada44dd8d5974eaf6bb6b17f23406e3ca72 +PKG_VERSION=e9e242e98e27037830490b2a752895ca68f75f8b PKG_LICENSE=MIT include $(RIOTBASE)/pkg/pkg.mk diff --git a/sys/auto_init/usb/auto_init_usb.c b/sys/auto_init/usb/auto_init_usb.c index fe288faace..4ed1a746df 100644 --- a/sys/auto_init/usb/auto_init_usb.c +++ b/sys/auto_init/usb/auto_init_usb.c @@ -27,6 +27,7 @@ #include #include "usb/usbus.h" +#include "usb/usbus/control.h" #ifdef MODULE_USBUS_CDC_ECM #include "usb/usbus/cdc/ecm.h" @@ -39,11 +40,52 @@ usbus_cdcecm_device_t cdcecm; #include "usb/usbus/dfu.h" static usbus_dfu_device_t dfu; #endif +#ifdef MODULE_USBUS_HID +#include "usb/usbus/hid.h" +#endif #ifdef MODULE_USBUS_MSC #include "usb/usbus/msc.h" static usbus_msc_device_t msc; #endif +#ifndef MODULE_USBUS_CDC_ACM +#define USBUS_CDC_ACM_EP_IN_REQUIRED_NUMOF 0 +#define USBUS_CDC_ACM_EP_OUT_REQUIRED_NUMOF 0 +#endif + +#ifndef MODULE_USBUS_CDC_ECM +#define USBUS_CDC_ECM_EP_IN_REQUIRED_NUMOF 0 +#define USBUS_CDC_ECM_EP_OUT_REQUIRED_NUMOF 0 +#endif + +#ifndef MODULE_USBUS_HID +#define USBUS_HID_EP_IN_REQUIRED_NUMOF 0 +#define USBUS_HID_EP_OUT_REQUIRED_NUMOF 0 +#endif + +#ifndef MODULE_USBUS_MSC +#define USBUS_MSC_EP_IN_REQUIRED_NUMOF 0 +#define USBUS_MSC_EP_OUT_REQUIRED_NUMOF 0 +#endif + +#define USBUS_EP_IN_REQUIRED_NUMOF (USBUS_CONTROL_EP_IN_REQUIRED_NUMOF + \ + USBUS_CDC_ACM_EP_IN_REQUIRED_NUMOF + \ + USBUS_CDC_ECM_EP_IN_REQUIRED_NUMOF + \ + USBUS_HID_EP_IN_REQUIRED_NUMOF + \ + USBUS_MSC_EP_IN_REQUIRED_NUMOF) + +#define USBUS_EP_OUT_REQUIRED_NUMOF (USBUS_CONTROL_EP_OUT_REQUIRED_NUMOF + \ + USBUS_CDC_ACM_EP_OUT_REQUIRED_NUMOF + \ + USBUS_CDC_ECM_EP_OUT_REQUIRED_NUMOF + \ + USBUS_HID_EP_OUT_REQUIRED_NUMOF + \ + USBUS_MSC_EP_OUT_REQUIRED_NUMOF) + +static_assert(USBUS_EP_IN_REQUIRED_NUMOF <= USBDEV_NUM_ENDPOINTS, + "Number of required IN endpoints exceeded"); + +static_assert(USBUS_EP_OUT_REQUIRED_NUMOF <= USBDEV_NUM_ENDPOINTS, + "Number of required OUT endpoints exceeded"); + static char _stack[USBUS_STACKSIZE]; static usbus_t usbus; diff --git a/sys/include/usb/hid.h b/sys/include/usb/hid.h index 5100d6f93d..516dd7ebf9 100644 --- a/sys/include/usb/hid.h +++ b/sys/include/usb/hid.h @@ -83,6 +83,16 @@ extern "C" { #define USB_HID_REQUEST_SET_PROTOCOL 0x0b /** @} */ +/** + * @brief Number of IN EPs required for the HID interface + */ +#define USBUS_HID_EP_IN_REQUIRED_NUMOF 1 + +/** + * @brief Number of Out EPs required for the HID interface + */ +#define USBUS_HID_EP_OUT_REQUIRED_NUMOF 1 + /** * @brief USB HID descriptor struct * diff --git a/sys/include/usb/usbus/cdc/acm.h b/sys/include/usb/usbus/cdc/acm.h index 0a580b0855..103da7ffdb 100644 --- a/sys/include/usb/usbus/cdc/acm.h +++ b/sys/include/usb/usbus/cdc/acm.h @@ -89,6 +89,16 @@ extern "C" { */ #define USBUS_CDC_ACM_INT_EP_SIZE (8) +/** + * @brief Number of IN EPs required for the CDC ACM interface + */ +#define USBUS_CDC_ACM_EP_IN_REQUIRED_NUMOF 2 + +/** + * @brief Number of Out EPs required for the CDC ACM interface + */ +#define USBUS_CDC_ACM_EP_OUT_REQUIRED_NUMOF 1 + /** * @brief CDC ACM line state as reported by the host computer */ diff --git a/sys/include/usb/usbus/cdc/ecm.h b/sys/include/usb/usbus/cdc/ecm.h index 5f99af2dde..adaec1b732 100644 --- a/sys/include/usb/usbus/cdc/ecm.h +++ b/sys/include/usb/usbus/cdc/ecm.h @@ -87,6 +87,16 @@ extern "C" { */ #define USBUS_ETHERNET_FRAME_BUF MATH_ALIGN(ETHERNET_FRAME_LEN, USBUS_CDCECM_EP_DATA_SIZE) +/** + * @brief Number of IN EPs required for the CDC ECM interface + */ +#define USBUS_CDC_ECM_EP_IN_REQUIRED_NUMOF 2 + +/** + * @brief Number of Out EPs required for the CDC ECM interface + */ +#define USBUS_CDC_ECM_EP_OUT_REQUIRED_NUMOF 1 + /** * @brief notification state, used to track which information must be send to * the host diff --git a/sys/include/usb/usbus/control.h b/sys/include/usb/usbus/control.h index 69e8028111..3afa2ff880 100644 --- a/sys/include/usb/usbus/control.h +++ b/sys/include/usb/usbus/control.h @@ -21,6 +21,16 @@ #ifndef USB_USBUS_CONTROL_H #define USB_USBUS_CONTROL_H +/** + * @brief Number of IN EPs required for the control interface + */ +#define USBUS_CONTROL_EP_IN_REQUIRED_NUMOF 1 + +/** + * @brief Number of IN EPs required for the control interface + */ +#define USBUS_CONTROL_EP_OUT_REQUIRED_NUMOF 1 + #include "usb/usbus.h" #ifdef __cplusplus diff --git a/sys/include/usb/usbus/msc.h b/sys/include/usb/usbus/msc.h index 4e3ee02e8d..4f664ca13f 100644 --- a/sys/include/usb/usbus/msc.h +++ b/sys/include/usb/usbus/msc.h @@ -31,6 +31,16 @@ extern "C" { #endif +/** + * @brief Number of IN EPs required for the MSC interface + */ +#define USBUS_MSC_EP_IN_REQUIRED_NUMOF 1 + +/** + * @brief Number of Out EPs required for the MSC interface + */ +#define USBUS_MSC_EP_OUT_REQUIRED_NUMOF 1 + /** * @brief USBUS MSC Number of exported MTD device through USB */ diff --git a/tests/pkg_nanors/main.c b/tests/pkg_nanors/main.c index 313e9ef5cc..343579d53c 100644 --- a/tests/pkg_nanors/main.c +++ b/tests/pkg_nanors/main.c @@ -36,10 +36,14 @@ int main(void) static uint8_t data[(DATA_SHARDS + RECOVERY_SHARDS) * SHARD_SIZE]; /* copy of data for comparison */ static uint8_t data_cmp[DATA_SHARDS * SHARD_SIZE]; + /* nanors work buffer */ + static uint8_t rs_buf[reed_solomon_bufsize(DATA_SHARDS, RECOVERY_SHARDS)]; + /* pointer to shards */ - static uint8_t *shards[DATA_SHARDS + RECOVERY_SHARDS]; + uint8_t *shards[DATA_SHARDS + RECOVERY_SHARDS]; /* map of missing shards */ - static uint8_t marks[DATA_SHARDS + RECOVERY_SHARDS]; + uint8_t marks[DATA_SHARDS + RECOVERY_SHARDS]; + memset(marks, 0, sizeof(marks)); /* generate random data */ random_bytes(data, sizeof(data_cmp)); @@ -51,8 +55,7 @@ int main(void) } puts("START"); - reed_solomon_init(); - rs_t *rs = reed_solomon_new(DATA_SHARDS, RECOVERY_SHARDS); + rs_t *rs = reed_solomon_new_static(rs_buf, sizeof(rs_buf), DATA_SHARDS, RECOVERY_SHARDS); if (!rs) { puts("failed to init codec"); return -1; @@ -79,7 +82,6 @@ int main(void) } else { puts("done."); } - reed_solomon_release(rs); if (memcmp(data, data_cmp, sizeof(data_cmp))) { puts("FAILED"); diff --git a/tests/usbus_cdc_ecm/Makefile b/tests/usbus_cdc_ecm/Makefile index f632e5d40c..b25c9e7699 100644 --- a/tests/usbus_cdc_ecm/Makefile +++ b/tests/usbus_cdc_ecm/Makefile @@ -9,4 +9,30 @@ USEMODULE += shell USEMODULE += shell_cmds_default USEMODULE += ps +# Boards that don't have enough endpoints to use CDC ACM together with CDC ECM +ifeq (,$(filter stdio_%,$(filter-out stdio_cdc_acm,$(USEMODULE)))) + BOARD_BLACKLIST += \ + stm32f429i-disco \ + stm32f4discovery \ + weact-f401cc \ + weact-f401ce \ + weact-f411ce \ + # +endif + +define _usbus_cdc_ecm_blacklist_info +Warning: + The board is blacklisted because it uses `stdio_cdc_acm` as STDIO, which needs + a CDC ACM interface in addition to the CDC ECM interface, but the number of + available endpoints is not sufficient for this. To use this application you + have to use `stdio_uart` or any other `stdio_*` module, for example: + + USEMODULE=stdio_uart BOARD=$(BOARD) make -C tests/usbus_cdc_ecm + +endef + +ifneq (,$(filter $(BOARD),$(BOARD_BLACKLIST))) + $(info $(_usbus_cdc_ecm_blacklist_info)) +endif + include $(RIOTBASE)/Makefile.include