From 0f6483b5a330bf9cdc9f97d6b709e00764baf368 Mon Sep 17 00:00:00 2001 From: Henrik Brix Andersen Date: Wed, 8 Apr 2026 17:58:25 +0000 Subject: [PATCH] treewide: remove support for the legacy USB device stack Remove support for the deprecated, legacy USB device stack. Signed-off-by: Henrik Brix Andersen --- README.md | 4 - app/Kconfig | 40 +- app/boards/canbardo_same70n20b_legacy.conf | 5 - .../canbardo_same70n20b_legacy_release.conf | 5 - app/boards/native_sim_legacy.overlay | 89 - app/boards/native_sim_legacy_release.overlay | 7 - .../native_sim_native_64_legacy.overlay | 7 - ...ative_sim_native_64_legacy_release.overlay | 7 - app/prj_legacy.conf | 10 - app/prj_legacy_release.conf | 13 - app/sample.yaml | 58 - app/src/led.c | 2 +- app/src/usb.c | 50 +- .../boards/canbardo_same70n20b_legacy.conf | 13 - .../canbardo_same70n20b_legacy_release.conf | 13 - .../boards/frdm_k64f_mk64f12_legacy.conf | 12 - .../frdm_k64f_mk64f12_legacy_release.conf | 12 - doc/building.rst | 5 - include/cannectivity/usb/class/gs_usb.h | 21 +- subsys/usb/CMakeLists.txt | 1 - subsys/usb/Kconfig | 1 - subsys/usb/device/CMakeLists.txt | 6 - subsys/usb/device/Kconfig | 8 - subsys/usb/device/class/CMakeLists.txt | 4 - subsys/usb/device/class/Kconfig | 4 - subsys/usb/device/class/Kconfig.gs_usb | 114 -- subsys/usb/device/class/gs_usb.c | 1598 ----------------- tests/subsys/usb/gs_usb/host/Kconfig | 19 - tests/subsys/usb/gs_usb/host/prj_legacy.conf | 23 - tests/subsys/usb/gs_usb/host/src/usb.c | 30 +- tests/subsys/usb/gs_usb/host/testcase.yaml | 8 - 31 files changed, 13 insertions(+), 2176 deletions(-) delete mode 100644 app/boards/canbardo_same70n20b_legacy.conf delete mode 100644 app/boards/canbardo_same70n20b_legacy_release.conf delete mode 100644 app/boards/native_sim_legacy.overlay delete mode 100644 app/boards/native_sim_legacy_release.overlay delete mode 100644 app/boards/native_sim_native_64_legacy.overlay delete mode 100644 app/boards/native_sim_native_64_legacy_release.overlay delete mode 100644 app/prj_legacy.conf delete mode 100644 app/prj_legacy_release.conf delete mode 100644 app/sysbuild/mcuboot/boards/canbardo_same70n20b_legacy.conf delete mode 100644 app/sysbuild/mcuboot/boards/canbardo_same70n20b_legacy_release.conf delete mode 100644 app/sysbuild/mcuboot/boards/frdm_k64f_mk64f12_legacy.conf delete mode 100644 app/sysbuild/mcuboot/boards/frdm_k64f_mk64f12_legacy_release.conf delete mode 100644 subsys/usb/device/CMakeLists.txt delete mode 100644 subsys/usb/device/Kconfig delete mode 100644 subsys/usb/device/class/CMakeLists.txt delete mode 100644 subsys/usb/device/class/Kconfig delete mode 100644 subsys/usb/device/class/Kconfig.gs_usb delete mode 100644 subsys/usb/device/class/gs_usb.c delete mode 100644 tests/subsys/usb/gs_usb/host/prj_legacy.conf diff --git a/README.md b/README.md index e7ed69a..d7fe82c 100644 --- a/README.md +++ b/README.md @@ -98,10 +98,6 @@ west build -b lpcxpresso55s16/lpc55s16 cannectivity/app/ -- -DFILE_SUFFIX=releas After building, the firmware can be flashed to the board by running the `west flash` command. -> **Note:** Build configurations for using the legacy USB device stack in Zephyr are also -> provided. These can be selected by setting either `FILE_SUFFIX=legacy` or -> `FILE_SUFFIX=legacy_release`. - ## USB Device Firmware Upgrade (DFU) Mode CANnectivity supports USB Device Firmware Upgrade diff --git a/app/Kconfig b/app/Kconfig index 06fe408..f35fb32 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -67,44 +67,9 @@ config CANNECTIVITY_MAX_CHANNELS The Linux kernel driver supports up to 3 channels. Other drivers may support just one channel. -if USB_DEVICE_STACK - -configdefault USB_DEVICE_MANUFACTURER - default CANNECTIVITY_USB_MANUFACTURER - -configdefault USB_DEVICE_PRODUCT - default CANNECTIVITY_USB_PRODUCT - -configdefault USB_DEVICE_VID - default CANNECTIVITY_USB_VID - -configdefault USB_DEVICE_PID - default CANNECTIVITY_USB_PID - -configdefault USB_SELF_POWERED - default CANNECTIVITY_USB_SELF_POWERED - -configdefault USB_MAX_POWER - default CANNECTIVITY_USB_MAX_POWER - -configdefault USB_DEVICE_GS_USB_MAX_CHANNELS - default CANNECTIVITY_MAX_CHANNELS - -configdefault USB_DEVICE_BOS - default y - -configdefault USB_DEVICE_INITIALIZE_AT_BOOT - default n - -endif # USB_DEVICE_STACK - -if USB_DEVICE_STACK_NEXT - configdefault USBD_GS_USB_MAX_CHANNELS default CANNECTIVITY_MAX_CHANNELS -endif # USB_DEVICE_STACK_NEXT - config CANNECTIVITY_LED bool "LED support" default y @@ -185,9 +150,8 @@ if CANNECTIVITY_DFU_SUPPORT choice CANNECTIVITY_DFU_BACKEND bool "DFU backend" default CANNECTIVITY_DFU_BACKEND_NONE if !BOOTLOADER_MCUBOOT - default CANNECTIVITY_DFU_BACKEND_MCUBOOT if BOOTLOADER_MCUBOOT && USB_DEVICE_STACK default CANNECTIVITY_DFU_BACKEND_MCUBOOT if BOOTLOADER_MCUBOOT && MCUBOOT_BOOTLOADER_MODE_SINGLE_APP - default CANNECTIVITY_DFU_BACKEND_APP if BOOTLOADER_MCUBOOT && USB_DEVICE_STACK_NEXT + default CANNECTIVITY_DFU_BACKEND_APP if BOOTLOADER_MCUBOOT config CANNECTIVITY_DFU_BACKEND_NONE bool "No backend" @@ -203,7 +167,7 @@ config CANNECTIVITY_DFU_BACKEND_MCUBOOT config CANNECTIVITY_DFU_BACKEND_APP bool "Application" - depends on BOOTLOADER_MCUBOOT && !MCUBOOT_BOOTLOADER_MODE_SINGLE_APP && USB_DEVICE_STACK_NEXT + depends on BOOTLOADER_MCUBOOT && !MCUBOOT_BOOTLOADER_MODE_SINGLE_APP help Device Firmware Upgrade is handled by the CANnectivity firmware application. The upgrade process is handled by MCUboot upon reboot. diff --git a/app/boards/canbardo_same70n20b_legacy.conf b/app/boards/canbardo_same70n20b_legacy.conf deleted file mode 100644 index 6841593..0000000 --- a/app/boards/canbardo_same70n20b_legacy.conf +++ /dev/null @@ -1,5 +0,0 @@ -# Copyright (c) 2024-2025 Henrik Brix Andersen -# SPDX-License-Identifier: Apache-2.0 - -CONFIG_CANNECTIVITY_USB_SELF_POWERED=n -CONFIG_USB_DEVICE_GS_USB_COMPATIBILITY_MODE=n diff --git a/app/boards/canbardo_same70n20b_legacy_release.conf b/app/boards/canbardo_same70n20b_legacy_release.conf deleted file mode 100644 index 1c9a3c7..0000000 --- a/app/boards/canbardo_same70n20b_legacy_release.conf +++ /dev/null @@ -1,5 +0,0 @@ -# Copyright (c) 2026 Henrik Brix Andersen -# SPDX-License-Identifier: Apache-2.0 - -CONFIG_CANNECTIVITY_USB_SELF_POWERED=n -CONFIG_USB_DEVICE_GS_USB_COMPATIBILITY_MODE=n diff --git a/app/boards/native_sim_legacy.overlay b/app/boards/native_sim_legacy.overlay deleted file mode 100644 index 226d5e4..0000000 --- a/app/boards/native_sim_legacy.overlay +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2024 Henrik Brix Andersen - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include "../app.overlay" - -/ { - leds { - compatible = "gpio-leds"; - - led_ch0_state: led_ch0_state { - gpios = <&gpio0 0 GPIO_ACTIVE_HIGH>; - label = "Channel 0 state LED"; - }; - - led_ch0_activity: led_ch0_activity { - gpios = <&gpio0 1 GPIO_ACTIVE_HIGH>; - label = "Channel 0 activity LED"; - }; - - led_ch1_state: led_ch1_state { - gpios = <&gpio0 2 GPIO_ACTIVE_HIGH>; - label = "Channel 1 state LED"; - }; - - led_ch1_activity: led_ch1_activity { - gpios = <&gpio0 3 GPIO_ACTIVE_HIGH>; - label = "Channel 1 activity LED"; - }; - - led_ch2_state: led_ch2_state { - gpios = <&gpio0 4 GPIO_ACTIVE_HIGH>; - label = "Channel 2 state LED"; - }; - - led_ch2_activity: led_ch2_activity { - gpios = <&gpio0 5 GPIO_ACTIVE_HIGH>; - label = "Channel 2 activity LED"; - }; - }; - - cannectivity: cannectivity { - compatible = "cannectivity"; - timestamp-counter = <&counter0>; - - channel0 { - compatible = "cannectivity-channel"; - can-controller = <&can_loopback0>; - termination-gpios = <&gpio0 0 GPIO_ACTIVE_HIGH>; - state-led = <&led_ch0_state>; - activity-leds = <&led_ch0_activity>; - }; - - channel1 { - compatible = "cannectivity-channel"; - can-controller = <&can_loopback1>; - termination-gpios = <&gpio0 3 GPIO_ACTIVE_HIGH>; - state-led = <&led_ch1_state>; - activity-leds = <&led_ch1_activity>; - }; - - channel2 { - compatible = "cannectivity-channel"; - can-controller = <&can_loopback2>; - termination-gpios = <&gpio0 6 GPIO_ACTIVE_HIGH>; - state-led = <&led_ch2_state>; - activity-leds = <&led_ch2_activity>; - }; - }; - - can_loopback0: can_loopback0 { - status = "okay"; - compatible = "zephyr,can-loopback"; - }; - - can_loopback1: can_loopback1 { - status = "okay"; - compatible = "zephyr,can-loopback"; - }; - - can_loopback2: can_loopback2 { - status = "okay"; - compatible = "zephyr,can-loopback"; - }; - -}; diff --git a/app/boards/native_sim_legacy_release.overlay b/app/boards/native_sim_legacy_release.overlay deleted file mode 100644 index 895b926..0000000 --- a/app/boards/native_sim_legacy_release.overlay +++ /dev/null @@ -1,7 +0,0 @@ -/* - * Copyright (c) 2026 Henrik Brix Andersen - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "native_sim_legacy.overlay" diff --git a/app/boards/native_sim_native_64_legacy.overlay b/app/boards/native_sim_native_64_legacy.overlay deleted file mode 100644 index 9828c1d..0000000 --- a/app/boards/native_sim_native_64_legacy.overlay +++ /dev/null @@ -1,7 +0,0 @@ -/* - * Copyright (c) 2024-2026 Henrik Brix Andersen - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "native_sim_legacy.overlay" diff --git a/app/boards/native_sim_native_64_legacy_release.overlay b/app/boards/native_sim_native_64_legacy_release.overlay deleted file mode 100644 index 50dc11a..0000000 --- a/app/boards/native_sim_native_64_legacy_release.overlay +++ /dev/null @@ -1,7 +0,0 @@ -/* - * Copyright (c) 2026 Henrik Brix Andersen - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "native_sim_native_64_legacy.overlay" diff --git a/app/prj_legacy.conf b/app/prj_legacy.conf deleted file mode 100644 index 10315f3..0000000 --- a/app/prj_legacy.conf +++ /dev/null @@ -1,10 +0,0 @@ -# This is using the deprecated USB device stack -CONFIG_DEPRECATION_TEST=y -CONFIG_USB_DEVICE_STACK=y - -# Logging configuration -CONFIG_LOG=y -CONFIG_USB_DRIVER_LOG_LEVEL_ERR=y -CONFIG_USB_DEVICE_LOG_LEVEL_ERR=y -CONFIG_USB_DEVICE_GS_USB_LOG_LEVEL_DBG=y -CONFIG_CANNECTIVITY_LOG_LEVEL_DBG=y diff --git a/app/prj_legacy_release.conf b/app/prj_legacy_release.conf deleted file mode 100644 index 706e911..0000000 --- a/app/prj_legacy_release.conf +++ /dev/null @@ -1,13 +0,0 @@ -# This is using the deprecated USB device stack -CONFIG_DEPRECATION_TEST=y -CONFIG_USB_DEVICE_STACK=y - -# Hardened configuration -CONFIG_BOOT_BANNER=n -CONFIG_BUILD_OUTPUT_STRIPPED=y -CONFIG_PRINTK=n -CONFIG_STACK_SENTINEL=y -CONFIG_OVERRIDE_FRAME_POINTER_DEFAULT=y - -# Arm-specific hardened configuration -CONFIG_FAULT_DUMP=0 diff --git a/app/sample.yaml b/app/sample.yaml index fb5bafb..c98954d 100644 --- a/app/sample.yaml +++ b/app/sample.yaml @@ -14,53 +14,6 @@ common: regex: - "CANnectivity firmware initialized with .*" tests: - app.cannectivity.legacy: - depends_on: - - can - - usb_device - extra_args: - - FILE_SUFFIX=legacy - integration_platforms: - - canbardo - - candlelight - - candlelightfd - - candlelightfd/stm32g0b1xx/dual - - frdm_k64f - - frdm_mcxn947/mcxn947/cpu0 - - lpcxpresso55s16 - - mks_canable_v20 - - nucleo_h723zg - - ucan - - usb2canfdv1 - app.cannectivity.legacy.sof: - depends_on: - - can - - usb_device - extra_args: - - FILE_SUFFIX=legacy - integration_platforms: - - nucleo_h723zg - extra_configs: - - CONFIG_USB_DEVICE_GS_USB_TIMESTAMP_SOF=y - app.cannectivity.legacy.release: - depends_on: - - can - - usb_device - extra_args: - - FILE_SUFFIX=legacy_release - integration_platforms: - - canbardo - - candlelight - - candlelightfd - - candlelightfd/stm32g0b1xx/dual - - frdm_k64f - - frdm_mcxn947/mcxn947/cpu0 - - lpcxpresso55s16 - - mks_canable_v20 - - nucleo_h723zg - - ucan - - usb2canfdv1 - build_only: true app.cannectivity: depends_on: - can @@ -102,17 +55,6 @@ tests: - ucan - usb2canfdv1 build_only: true - app.cannectivity.legacy.dfu: - sysbuild: true - depends_on: - - can - - usb_device - platform_allow: - - frdm_k64f - - lpcxpresso55s16 - - canbardo - extra_args: - - FILE_SUFFIX=legacy app.cannectivity.dfu: sysbuild: true depends_on: diff --git a/app/src/led.c b/app/src/led.c index d7c54da..62fdedb 100644 --- a/app/src/led.c +++ b/app/src/led.c @@ -477,7 +477,7 @@ int cannectivity_led_event(const struct device *dev, uint16_t ch, enum gs_usb_ev lctx->activity[idx] = sys_timepoint_calc(K_MSEC(LED_TICK_MS * LED_TICKS_ACTIVITY)); break; -#if defined(CONFIG_USB_DEVICE_GS_USB_IDENTIFICATION) || defined(CONFIG_USBD_GS_USB_IDENTIFICATION) +#ifdef CONFIG_USBD_GS_USB_IDENTIFICATION case GS_USB_EVENT_CHANNEL_IDENTIFY_ON: LOG_DBG("identify channel %u on", ch); led_event = LED_EVENT_CHANNEL_IDENTIFY_ON; diff --git a/app/src/usb.c b/app/src/usb.c index 013317b..246a8d5 100644 --- a/app/src/usb.c +++ b/app/src/usb.c @@ -8,13 +8,7 @@ #include #include -#ifdef CONFIG_USB_DEVICE_STACK_NEXT #include -#else /* CONFIG_USB_DEVICE_STACK_NEXT */ -#include -#include -#include -#endif /* !CONFIG_USB_DEVICE_STACK_NEXT*/ #ifdef CONFIG_CANNECTIVITY_DFU_BACKEND_APP #include #endif /* CONFIG_CANNECTIVITY_DFU_BACKEND_APP */ @@ -36,13 +30,7 @@ LOG_MODULE_REGISTER(usb, CONFIG_CANNECTIVITY_LOG_LEVEL); #define CANNECTIVITY_USB_BCD_DRN \ (USB_DEC_TO_BCD(APP_VERSION_MAJOR) << 8 | USB_DEC_TO_BCD(APP_VERSION_MINOR)) -#ifdef CONFIG_USB_DEVICE_STACK_NEXT -#define CANNECTIVITY_BOS_DESC_DEFINE_CAP static -#else /* CONFIG_USB_DEVICE_STACK_NEXT */ -#define CANNECTIVITY_BOS_DESC_DEFINE_CAP USB_DEVICE_BOS_DESC_DEFINE_CAP -#endif /* !CONFIG_USB_DEVICE_STACK_NEXT */ - -CANNECTIVITY_BOS_DESC_DEFINE_CAP const struct usb_bos_capability_lpm bos_cap_lpm = { +static const struct usb_bos_capability_lpm bos_cap_lpm = { .bLength = sizeof(struct usb_bos_capability_lpm), .bDescriptorType = USB_DESC_DEVICE_CAPABILITY, .bDevCapabilityType = USB_BOS_CAPABILITY_EXTENSION, @@ -227,9 +215,9 @@ struct usb_bos_capability_msosv2 { } __packed; #ifdef CONFIG_CANNECTIVITY_DFU_BACKEND_APP -CANNECTIVITY_BOS_DESC_DEFINE_CAP struct usb_bos_capability_msosv2 bos_cap_msosv2 = { +static struct usb_bos_capability_msosv2 bos_cap_msosv2 = { #else /* CONFIG_CANNECTIVITY_DFU_BACKEND_APP */ -CANNECTIVITY_BOS_DESC_DEFINE_CAP const struct usb_bos_capability_msosv2 bos_cap_msosv2 = { +static const struct usb_bos_capability_msosv2 bos_cap_msosv2 = { #endif /* CONFIG_CANNECTIVITY_DFU_BACKEND_APP */ .platform = { .bLength = sizeof(struct usb_bos_capability_msosv2), @@ -256,8 +244,6 @@ CANNECTIVITY_BOS_DESC_DEFINE_CAP const struct usb_bos_capability_msosv2 bos_cap_ }; /* clang-format on */ -#ifdef CONFIG_USB_DEVICE_STACK_NEXT - USBD_DEVICE_DEFINE(usbd, DEVICE_DT_GET(DT_NODELABEL(zephyr_udc0)), CONFIG_CANNECTIVITY_USB_VID, CONFIG_CANNECTIVITY_USB_PID); @@ -463,7 +449,7 @@ static void cannectivity_usb_msg_cb(struct usbd_context *const usbd_ctx, } #endif /* CONFIG_CANNECTIVITY_DFU_BACKEND_APP */ -static int cannectivity_usb_init_usbd(void) +int cannectivity_usb_init(void) { int err; @@ -613,31 +599,3 @@ static int cannectivity_usb_init_usbd(void) return 0; } -#else /* CONFIG_USB_DEVICE_STACK_NEXT */ -static int cannectivity_usb_vendorcode_handler(int32_t *tlen, uint8_t **tdata) -{ - *tdata = (uint8_t *)(&cannectivity_msosv2_descriptor); - *tlen = sizeof(cannectivity_msosv2_descriptor); - - return 0; -} -#endif /* !CONFIG_USB_DEVICE_STACK_NEXT */ - -int cannectivity_usb_init(void) -{ -#ifdef CONFIG_USB_DEVICE_STACK_NEXT - return cannectivity_usb_init_usbd(); -#else /* CONFIG_USB_DEVICE_STACK_NEXT */ - struct usb_device_descriptor *desc = - (struct usb_device_descriptor *)usb_get_device_descriptor(); - - desc->bcdDevice = sys_cpu_to_le16(CANNECTIVITY_USB_BCD_DRN); - - usb_bos_register_cap((void *)&bos_cap_lpm); - usb_bos_register_cap((void *)&bos_cap_msosv2); - - gs_usb_register_vendorcode_callback(cannectivity_usb_vendorcode_handler); - - return usb_enable(NULL); -#endif /* !CONFIG_USB_DEVICE_STACK_NEXT */ -} diff --git a/app/sysbuild/mcuboot/boards/canbardo_same70n20b_legacy.conf b/app/sysbuild/mcuboot/boards/canbardo_same70n20b_legacy.conf deleted file mode 100644 index f1e30df..0000000 --- a/app/sysbuild/mcuboot/boards/canbardo_same70n20b_legacy.conf +++ /dev/null @@ -1,13 +0,0 @@ -# Copyright (c) 2024-2025 Henrik Brix Andersen -# SPDX-License-Identifier: Apache-2.0 - -# This is using the deprecated USB device stack -CONFIG_DEPRECATION_TEST=y - -CONFIG_MCUBOOT_INDICATION_LED=y -CONFIG_BOOT_USB_DFU_GPIO=y -CONFIG_USB_DEVICE_MANUFACTURER="CANnectivity" -CONFIG_USB_DEVICE_PRODUCT="CANnectivity USB to CAN adapter (MCUboot DFU)" -CONFIG_USB_DEVICE_VID=0x1209 -CONFIG_USB_DEVICE_PID=0xca02 -CONFIG_USB_DEVICE_DFU_PID=0xca02 diff --git a/app/sysbuild/mcuboot/boards/canbardo_same70n20b_legacy_release.conf b/app/sysbuild/mcuboot/boards/canbardo_same70n20b_legacy_release.conf deleted file mode 100644 index adf7f00..0000000 --- a/app/sysbuild/mcuboot/boards/canbardo_same70n20b_legacy_release.conf +++ /dev/null @@ -1,13 +0,0 @@ -# Copyright (c) 2024-2026 Henrik Brix Andersen -# SPDX-License-Identifier: Apache-2.0 - -# This is using the deprecated USB device stack -CONFIG_DEPRECATION_TEST=y - -CONFIG_MCUBOOT_INDICATION_LED=y -CONFIG_BOOT_USB_DFU_GPIO=y -CONFIG_USB_DEVICE_MANUFACTURER="CANnectivity" -CONFIG_USB_DEVICE_PRODUCT="CANnectivity USB to CAN adapter (MCUboot DFU)" -CONFIG_USB_DEVICE_VID=0x1209 -CONFIG_USB_DEVICE_PID=0xca02 -CONFIG_USB_DEVICE_DFU_PID=0xca02 diff --git a/app/sysbuild/mcuboot/boards/frdm_k64f_mk64f12_legacy.conf b/app/sysbuild/mcuboot/boards/frdm_k64f_mk64f12_legacy.conf deleted file mode 100644 index 4468bf2..0000000 --- a/app/sysbuild/mcuboot/boards/frdm_k64f_mk64f12_legacy.conf +++ /dev/null @@ -1,12 +0,0 @@ -# Copyright (c) 2024 Henrik Brix Andersen -# SPDX-License-Identifier: Apache-2.0 - -# This is using the deprecated USB device stack -CONFIG_DEPRECATION_TEST=y - -CONFIG_BOOT_USB_DFU_GPIO=y -CONFIG_USB_DEVICE_MANUFACTURER="CANnectivity" -CONFIG_USB_DEVICE_PRODUCT="CANnectivity USB to CAN adapter (MCUboot DFU)" -CONFIG_USB_DEVICE_VID=0x1209 -CONFIG_USB_DEVICE_PID=0xca02 -CONFIG_USB_DEVICE_DFU_PID=0xca02 diff --git a/app/sysbuild/mcuboot/boards/frdm_k64f_mk64f12_legacy_release.conf b/app/sysbuild/mcuboot/boards/frdm_k64f_mk64f12_legacy_release.conf deleted file mode 100644 index a18a7e3..0000000 --- a/app/sysbuild/mcuboot/boards/frdm_k64f_mk64f12_legacy_release.conf +++ /dev/null @@ -1,12 +0,0 @@ -# Copyright (c) 2024-2026 Henrik Brix Andersen -# SPDX-License-Identifier: Apache-2.0 - -# This is using the deprecated USB device stack -CONFIG_DEPRECATION_TEST=y - -CONFIG_BOOT_USB_DFU_GPIO=y -CONFIG_USB_DEVICE_MANUFACTURER="CANnectivity" -CONFIG_USB_DEVICE_PRODUCT="CANnectivity USB to CAN adapter (MCUboot DFU)" -CONFIG_USB_DEVICE_VID=0x1209 -CONFIG_USB_DEVICE_PID=0xca02 -CONFIG_USB_DEVICE_DFU_PID=0xca02 diff --git a/doc/building.rst b/doc/building.rst index 4847dca..11d0fbb 100644 --- a/doc/building.rst +++ b/doc/building.rst @@ -35,11 +35,6 @@ To use the ``release`` configuration, which has reduced log levels, set ``FILE_S After building, the firmware can be flashed to the board by running the ``west flash`` command. -.. note:: - - Build configurations for using the legacy USB device stack in Zephyr are also provided. These can - be selected by setting either ``FILE_SUFFIX=legacy`` or ``FILE_SUFFIX=legacy_release``. - USB Device Firmware Upgrade (DFU) Mode -------------------------------------- diff --git a/include/cannectivity/usb/class/gs_usb.h b/include/cannectivity/usb/class/gs_usb.h index 06a63a1..c47e473 100644 --- a/include/cannectivity/usb/class/gs_usb.h +++ b/include/cannectivity/usb/class/gs_usb.h @@ -473,7 +473,7 @@ struct gs_usb_host_frame_hdr { /** * @brief Geschwister Schneider USB/CAN protocol timestamp field size */ -#if defined(CONFIG_USB_DEVICE_GS_USB_TIMESTAMP) || defined(CONFIG_USBD_GS_USB_TIMESTAMP) +#ifdef CONFIG_USBD_GS_USB_TIMESTAMP #define GS_USB_TIMESTAMP_SIZE sizeof(uint32_t) #else #define GS_USB_TIMESTAMP_SIZE 0U @@ -522,7 +522,7 @@ enum gs_usb_event { GS_USB_EVENT_CHANNEL_ACTIVITY_RX, /** Channel TX activity. */ GS_USB_EVENT_CHANNEL_ACTIVITY_TX, -#if defined(CONFIG_USB_DEVICE_GS_USB_IDENTIFICATION) || defined(CONFIG_USBD_GS_USB_IDENTIFICATION) +#ifdef CONFIG_USBD_GS_USB_IDENTIFICATION /** Visual channel identification on. */ GS_USB_EVENT_CHANNEL_IDENTIFY_ON, /** Visual channel identification off. */ @@ -535,19 +535,6 @@ enum gs_usb_event { */ #define GS_USB_MS_VENDORCODE 0xaa -#ifdef CONFIG_USB_DEVICE_GS_USB -/** - * @brief Defines the callback signature for responding to MSOSv2 vendor code USB requests - * - * @param[out] tlen Length of the MSOSv2 USB descriptor. - * @param[out] tdata The MSOSv2 USB descriptor. - * @return 0 on success, negative error number otherwise. - */ -typedef int (*gs_usb_vendorcode_callback_t)(int32_t *tlen, uint8_t **tdata); - -void gs_usb_register_vendorcode_callback(gs_usb_vendorcode_callback_t callback); -#endif /* CONFIG_USB_DEVICE_GS_USB */ - /** * @brief Defines the callback signature for obtaining a hardware timestamp * @@ -602,11 +589,11 @@ typedef int (*gs_usb_event_callback_t)(const struct device *dev, uint16_t ch, * @brief Callback operations structure. */ struct gs_usb_ops { -#if defined(CONFIG_USB_DEVICE_GS_USB_TIMESTAMP) || defined(CONFIG_USBD_GS_USB_TIMESTAMP) +#ifdef CONFIG_USBD_GS_USB_TIMESTAMP /** Optional timestamp callback */ gs_usb_timestamp_callback_t timestamp; #endif -#if defined(CONFIG_USB_DEVICE_GS_USB_TERMINATION) || defined(CONFIG_USBD_GS_USB_TERMINATION) +#ifdef CONFIG_USBD_GS_USB_TERMINATION /** Optional CAN channel set termination callback */ gs_usb_set_termination_callback_t set_termination; /** Optional CAN channel get termination callback */ diff --git a/subsys/usb/CMakeLists.txt b/subsys/usb/CMakeLists.txt index 26e3bb5..27dea1a 100644 --- a/subsys/usb/CMakeLists.txt +++ b/subsys/usb/CMakeLists.txt @@ -1,5 +1,4 @@ # Copyright (c) 2024 Henrik Brix Andersen # SPDX-License-Identifier: Apache-2.0 -add_subdirectory_ifdef(CONFIG_USB_DEVICE_STACK device) add_subdirectory_ifdef(CONFIG_USB_DEVICE_STACK_NEXT device_next) diff --git a/subsys/usb/Kconfig b/subsys/usb/Kconfig index 132121e..295626f 100644 --- a/subsys/usb/Kconfig +++ b/subsys/usb/Kconfig @@ -1,5 +1,4 @@ # Copyright (c) 2024 Henrik Brix Andersen # SPDX-License-Identifier: Apache-2.0 -rsource "device/Kconfig" rsource "device_next/Kconfig" diff --git a/subsys/usb/device/CMakeLists.txt b/subsys/usb/device/CMakeLists.txt deleted file mode 100644 index 0cb3cb8..0000000 --- a/subsys/usb/device/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -# Copyright (c) 2024 Henrik Brix Andersen -# SPDX-License-Identifier: Apache-2.0 - -if(CONFIG_USB_DEVICE_STACK) - add_subdirectory(class) -endif() diff --git a/subsys/usb/device/Kconfig b/subsys/usb/device/Kconfig deleted file mode 100644 index efa5730..0000000 --- a/subsys/usb/device/Kconfig +++ /dev/null @@ -1,8 +0,0 @@ -# Copyright (c) 2024 Henrik Brix Andersen -# SPDX-License-Identifier: Apache-2.0 - -if USB_DEVICE_STACK - -rsource "class/Kconfig" - -endif # USB_DEVICE_STACK diff --git a/subsys/usb/device/class/CMakeLists.txt b/subsys/usb/device/class/CMakeLists.txt deleted file mode 100644 index d98ed60..0000000 --- a/subsys/usb/device/class/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -# Copyright (c) 2024 Henrik Brix Andersen -# SPDX-License-Identifier: Apache-2.0 - -zephyr_sources_ifdef(CONFIG_USB_DEVICE_GS_USB gs_usb.c) diff --git a/subsys/usb/device/class/Kconfig b/subsys/usb/device/class/Kconfig deleted file mode 100644 index c2c0ecb..0000000 --- a/subsys/usb/device/class/Kconfig +++ /dev/null @@ -1,4 +0,0 @@ -# Copyright (c) 2024 Henrik Brix Andersen -# SPDX-License-Identifier: Apache-2.0 - -rsource "Kconfig.gs_usb" diff --git a/subsys/usb/device/class/Kconfig.gs_usb b/subsys/usb/device/class/Kconfig.gs_usb deleted file mode 100644 index 1081420..0000000 --- a/subsys/usb/device/class/Kconfig.gs_usb +++ /dev/null @@ -1,114 +0,0 @@ -# Copyright (c) 2022-2026 Henrik Brix Andersen -# SPDX-License-Identifier: Apache-2.0 - -config USB_DEVICE_GS_USB - bool "Geschwister Schneider USB/CAN Device Class support [DEPRECATED]" - default y - depends on DT_HAS_GS_USB_ENABLED - select NET_BUF - select CAN - select DEPRECATED - imply CAN_ACCEPT_RTR - help - Geschwister Schneider USB/CAN (gs_usb) device class support. - -if USB_DEVICE_GS_USB - -module = USB_DEVICE_GS_USB -module-str = gs_usb -source "subsys/logging/Kconfig.template.log_config" - -config USB_DEVICE_GS_USB_MAX_CHANNELS - int "Maximum number of supported channels" - default 1 - range 1 256 - help - Maximum number of supported Geschwister Schneider USB/CAN (gs_usb) channels. Each channel - represents one CAN controller. - - The Linux kernel driver supports up to 3 channels. Other drivers may support just one - channel. - -config USB_DEVICE_GS_USB_POOL_SIZE - int "Host frame buffer pool size" - default 20 - help - Size of the pool used for allocating Geschwister Schneider USB/CAN (gs_usb) host - frames. The pool is used for both RX and TX, and shared between all channels of a given - gs_usb instance. - -config USB_DEVICE_GS_USB_IDENTIFICATION - bool "Enable support for CAN channel identification" - help - Enable support for CAN channel identification callback provided by the application. - -config USB_DEVICE_GS_USB_TIMESTAMP - bool "Enable support for hardware timestamps" - help - Enable support for hardware timestamps provided by the application. - -config USB_DEVICE_GS_USB_TIMESTAMP_SOF - bool "Capture hardware timestamp on USB SoF" - depends on USB_DEVICE_GS_USB_TIMESTAMP - select USB_DEVICE_SOF - help - Capture the hardware timestamp on each USB Start of Frame event. This improves the - timestamp accurracy with the cost of a higher CPU load. - -config USB_DEVICE_GS_USB_TERMINATION - bool "Enable support for CAN bus termination resistors" - help - Enable support for software-controlled CAN termination resistors. - -config USB_DEVICE_GS_USB_RX_THREAD_STACK_SIZE - int "Stack size for the RX thread" - default 1024 - help - Size of the stack used for the internal RX thread. - -config USB_DEVICE_GS_USB_RX_THREAD_PRIO - int "Priority for the RX thread" - default 0 - help - Priority level for the internal RX thread. - -config USB_DEVICE_GS_USB_TX_THREAD_STACK_SIZE - int "Stack size for the TX thread" - default 1024 - help - Size of the stack used for the internal TX thread. - -config USB_DEVICE_GS_USB_TX_THREAD_PRIO - int "Priority for the TX thread" - default 0 - help - Priority level for the internal TX thread. - -config USB_DEVICE_GS_USB_MAX_PACKET_SIZE - int "Maximum bulk endpoint packet size" - default 512 if USB_DC_HAS_HS_SUPPORT - default 64 - range 64 512 - help - Maximum bulk endpoint packet size in bytes. Classic CAN host frames fit into 64 byte - packets, whereas CAN FD host frames can benefit from a maximum packet size of 512 bytes. - -config USB_DEVICE_GS_USB_COMPATIBILITY_MODE - bool "Enable compatibility mode" - default y - help - Enable Geschwister Schneider USB/CAN (gs_usb) driver compatibility mode. - - The Linux kernel gs_usb driver prior to kernel v6.12.5 uses hardcoded USB endpoint - addresses 0x81 (bulk IN) and 0x02 (bulk OUT). The same assumption on USB endpoint - addresses may be present in other drivers as well (e.g. python-can). - - Depending on the capabilities of the USB device controller, the requested USB endpoint - addresses may be rewritten by the Zephyr USB device stack at runtime. Enabling - compatibility mode will include a second bulk OUT endpoint to ensure correct operation - with gs_usb drivers using the hardcoded USB endpoint addresses described above. - - It is safe to enable compatibility mode regardless of the driver being used, but the - resulting firmware will require slightly more RAM and flash resources. - -endif # USB_DEVICE_GS_USB diff --git a/subsys/usb/device/class/gs_usb.c b/subsys/usb/device/class/gs_usb.c deleted file mode 100644 index 41e4511..0000000 --- a/subsys/usb/device/class/gs_usb.c +++ /dev/null @@ -1,1598 +0,0 @@ -/* - * Copyright (c) 2022-2025 Henrik Brix Andersen - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -LOG_MODULE_REGISTER(gs_usb, CONFIG_USB_DEVICE_GS_USB_LOG_LEVEL); - -#define DT_DRV_COMPAT gs_usb - -/* USB endpoint indexes */ -#define GS_USB_IN_EP_IDX 0U -#ifdef CONFIG_USB_DEVICE_GS_USB_COMPATIBILITY_MODE -#define GS_USB_OUT1_EP_IDX 1U -#define GS_USB_OUT2_EP_IDX 2U -#else /* CONFIG_USB_DEVICE_GS_USB_COMPATIBILITY_MODE */ -#define GS_USB_OUT2_EP_IDX 1U -#endif /* !CONFIG_USB_DEVICE_GS_USB_COMPATIBILITY_MODE */ - -struct gs_usb_config { - struct usb_if_descriptor if0; - struct usb_ep_descriptor if0_in_ep; -#ifdef CONFIG_USB_DEVICE_GS_USB_COMPATIBILITY_MODE - struct usb_ep_descriptor if0_out1_ep; -#endif /* CONFIG_USB_DEVICE_GS_USB_COMPATIBILITY_MODE */ - struct usb_ep_descriptor if0_out2_ep; -} __packed; - -struct gs_usb_channel_data { - const struct device *dev; - struct k_sem rx_overflows; - uint32_t features; - uint32_t mode; - uint16_t ch; - bool started; - bool busoff; -}; - -struct gs_usb_data { - struct usb_dev_data common; - struct gs_usb_channel_data channels[CONFIG_USB_DEVICE_GS_USB_MAX_CHANNELS]; - size_t nchannels; - struct gs_usb_ops ops; - void *user_data; - struct net_buf_pool *pool; - void *if0_str_desc; - -#ifdef CONFIG_USB_DEVICE_GS_USB_TIMESTAMP_SOF - uint32_t timestamp; - bool sof_seen; -#endif /* CONFIG_USB_DEVICE_GS_USB_TIMESTAMP_SOF */ - - struct k_fifo rx_fifo; - struct k_thread rx_thread; - -#ifdef CONFIG_USB_DEVICE_GS_USB_COMPATIBILITY_MODE - uint8_t tx_buffer1[GS_USB_HOST_FRAME_MAX_SIZE]; -#endif /* CONFIG_USB_DEVICE_GS_USB_COMPATIBILITY_MODE */ - uint8_t tx_buffer2[GS_USB_HOST_FRAME_MAX_SIZE]; - struct k_fifo tx_fifo; - struct k_thread tx_thread; - - K_KERNEL_STACK_MEMBER(rx_stack, CONFIG_USB_DEVICE_GS_USB_RX_THREAD_STACK_SIZE); - K_KERNEL_STACK_MEMBER(tx_stack, CONFIG_USB_DEVICE_GS_USB_TX_THREAD_STACK_SIZE); -}; - -static sys_slist_t gs_usb_data_devlist; -static gs_usb_vendorcode_callback_t vendorcode_callback; - -static void gs_usb_transfer_tx_prepare(const struct device *dev, uint8_t ep); -static int gs_usb_reset_channel(const struct device *dev, uint16_t ch); - -static int gs_usb_request_host_format(int32_t tlen, const uint8_t *tdata) -{ - struct gs_usb_host_config *hc = (struct gs_usb_host_config *)tdata; - uint32_t byte_order; - - if (tlen != sizeof(*hc)) { - LOG_ERR("invalid length for host format request (%d)", tlen); - return -EINVAL; - } - - byte_order = sys_le32_to_cpu(hc->byte_order); - - if (byte_order != GS_USB_HOST_FORMAT_LITTLE_ENDIAN) { - LOG_ERR("unsupported host byte order (0x%08x)", byte_order); - return -ENOTSUP; - } - - return 0; -} - -static int gs_usb_request_bt_const(const struct device *dev, uint16_t ch, int32_t *tlen, - uint8_t **tdata) -{ - struct gs_usb_device_bt_const *bt_const = (struct gs_usb_device_bt_const *)*tdata; - struct gs_usb_data *data = dev->data; - struct gs_usb_channel_data *channel; - const struct can_timing *min; - const struct can_timing *max; - uint32_t rate; - int err; - - if (ch >= data->nchannels) { - LOG_ERR("bt_const request for non-existing channel %u", ch); - return -EINVAL; - } - - channel = &data->channels[ch]; - - err = can_get_core_clock(channel->dev, &rate); - if (err != 0U) { - LOG_ERR("failed to get core clock for channel %u (err %d)", ch, err); - return err; - } - - min = can_get_timing_min(channel->dev); - max = can_get_timing_max(channel->dev); - - bt_const->feature = sys_cpu_to_le32(channel->features); - bt_const->fclk_can = sys_cpu_to_le32(rate); - bt_const->tseg1_min = sys_cpu_to_le32(min->prop_seg + min->phase_seg1); - bt_const->tseg1_max = sys_cpu_to_le32(max->prop_seg + max->phase_seg1); - bt_const->tseg2_min = sys_cpu_to_le32(min->phase_seg2); - bt_const->tseg2_max = sys_cpu_to_le32(max->phase_seg2); - bt_const->sjw_max = sys_cpu_to_le32(max->sjw); - bt_const->brp_min = sys_cpu_to_le32(min->prescaler); - bt_const->brp_max = sys_cpu_to_le32(max->prescaler); - bt_const->brp_inc = 1U; - - *tlen = sizeof(*bt_const); - - return 0; -} - -static int gs_usb_request_bt_const_ext(const struct device *dev, uint16_t ch, int32_t *tlen, - uint8_t **tdata) -{ -#ifdef CONFIG_CAN_FD_MODE - struct gs_usb_device_bt_const_ext *bt_const_ext = - (struct gs_usb_device_bt_const_ext *)*tdata; - struct gs_usb_data *data = dev->data; - struct gs_usb_channel_data *channel; - const struct can_timing *min; - const struct can_timing *max; - uint32_t rate; - int err; - - if (ch >= data->nchannels) { - LOG_ERR("bt_const_ext request for non-existing channel %u", ch); - return -EINVAL; - } - - channel = &data->channels[ch]; - - err = can_get_core_clock(channel->dev, &rate); - if (err != 0U) { - LOG_ERR("failed to get core clock for channel %u (err %d)", ch, err); - return err; - } - - min = can_get_timing_min(channel->dev); - max = can_get_timing_max(channel->dev); - - bt_const_ext->feature = sys_cpu_to_le32(channel->features); - bt_const_ext->fclk_can = sys_cpu_to_le32(rate); - - bt_const_ext->tseg1_min = sys_cpu_to_le32(min->prop_seg + min->phase_seg1); - bt_const_ext->tseg1_max = sys_cpu_to_le32(max->prop_seg + max->phase_seg1); - bt_const_ext->tseg2_min = sys_cpu_to_le32(min->phase_seg2); - bt_const_ext->tseg2_max = sys_cpu_to_le32(max->phase_seg2); - bt_const_ext->sjw_max = sys_cpu_to_le32(max->sjw); - bt_const_ext->brp_min = sys_cpu_to_le32(min->prescaler); - bt_const_ext->brp_max = sys_cpu_to_le32(max->prescaler); - bt_const_ext->brp_inc = 1U; - - min = can_get_timing_data_min(channel->dev); - max = can_get_timing_data_max(channel->dev); - - if (min == NULL || max == NULL) { - LOG_ERR("failed to get min/max data phase timing for channel %u", ch); - return -ENOTSUP; - }; - - bt_const_ext->dtseg1_min = sys_cpu_to_le32(min->prop_seg + min->phase_seg1); - bt_const_ext->dtseg1_max = sys_cpu_to_le32(max->prop_seg + max->phase_seg1); - bt_const_ext->dtseg2_min = sys_cpu_to_le32(min->phase_seg2); - bt_const_ext->dtseg2_max = sys_cpu_to_le32(max->phase_seg2); - bt_const_ext->dsjw_max = sys_cpu_to_le32(max->sjw); - bt_const_ext->dbrp_min = sys_cpu_to_le32(min->prescaler); - bt_const_ext->dbrp_max = sys_cpu_to_le32(max->prescaler); - bt_const_ext->dbrp_inc = 1U; - - *tlen = sizeof(*bt_const_ext); - - return 0; -#else /* CONFIG_CAN_FD_MODE */ - return -ENOTSUP; -#endif /* !CONFIG_CAN_FD_MODE */ -} - -static int gs_usb_request_get_termination(const struct device *dev, uint16_t ch, int32_t *tlen, - uint8_t **tdata) -{ -#ifdef CONFIG_USB_DEVICE_GS_USB_TERMINATION - struct gs_usb_device_termination_state *ts = - (struct gs_usb_device_termination_state *)*tdata; - struct gs_usb_data *data = dev->data; - bool terminated; - int err; - - if (ch >= data->nchannels) { - LOG_ERR("get_termination request for non-existing channel %u", ch); - return -EINVAL; - } - - if (data->ops.get_termination == NULL) { - LOG_ERR("get termination not supported"); - return -ENOTSUP; - } - - err = data->ops.get_termination(dev, ch, &terminated, data->user_data); - if (err != 0U) { - LOG_ERR("failed to get termination state for channel %u (err %d)", ch, err); - return err; - } - - if (terminated) { - ts->state = sys_cpu_to_le32(GS_USB_CHANNEL_TERMINATION_STATE_ON); - } else { - ts->state = sys_cpu_to_le32(GS_USB_CHANNEL_TERMINATION_STATE_OFF); - } - - *tlen = sizeof(*ts); - - return 0; -#else /* CONFIG_USB_DEVICE_GS_USB_TERMINATION */ - return -ENOTSUP; -#endif /* !CONFIG_USB_DEVICE_GS_USB_TERMINATION */ -} - -static int gs_usb_request_set_termination(const struct device *dev, uint16_t ch, int32_t tlen, - uint8_t *tdata) -{ -#ifdef CONFIG_USB_DEVICE_GS_USB_TERMINATION - struct gs_usb_device_termination_state *ts = - (struct gs_usb_device_termination_state *)tdata; - struct gs_usb_data *data = dev->data; - uint32_t state; - bool terminate; - - if (ch >= data->nchannels) { - LOG_ERR("set termination request for non-existing channel %u", ch); - return -EINVAL; - } - - if (data->ops.set_termination == NULL) { - LOG_ERR("set termination not supported"); - return -ENOTSUP; - } - - if (tlen != sizeof(*ts)) { - LOG_ERR("invalid length for set termination request (%d)", tlen); - return -EINVAL; - } - - state = sys_le32_to_cpu(ts->state); - - switch (state) { - case GS_USB_CHANNEL_TERMINATION_STATE_OFF: - terminate = false; - break; - case GS_USB_CHANNEL_TERMINATION_STATE_ON: - terminate = true; - break; - default: - LOG_ERR("unsupported set termination state %d for channel %u", state, ch); - return -ENOTSUP; - } - - return data->ops.set_termination(dev, ch, terminate, data->user_data); -#else /* CONFIG_USB_DEVICE_GS_USB_TERMINATION */ - return -ENOTSUP; -#endif /* !CONFIG_USB_DEVICE_GS_USB_TERMINATION */ -} - -static int gs_usb_request_get_state(const struct device *dev, uint16_t ch, int32_t *tlen, - uint8_t **tdata) -{ - struct gs_usb_device_state *ds = (struct gs_usb_device_state *)*tdata; - struct gs_usb_data *data = dev->data; - struct gs_usb_channel_data *channel; - struct can_bus_err_cnt err_cnt; - enum can_state state; - int err; - - if (ch >= data->nchannels) { - LOG_ERR("get_state request for non-existing channel %u", ch); - return -EINVAL; - } - - channel = &data->channels[ch]; - - err = can_get_state(channel->dev, &state, &err_cnt); - if (err != 0U) { - LOG_ERR("failed to get state for channel %u (err %d)", ch, err); - return err; - } - - ds->rxerr = sys_cpu_to_le32(err_cnt.rx_err_cnt); - ds->txerr = sys_cpu_to_le32(err_cnt.tx_err_cnt); - - switch (state) { - case CAN_STATE_ERROR_ACTIVE: - ds->state = sys_cpu_to_le32(GS_USB_CHANNEL_STATE_ERROR_ACTIVE); - break; - case CAN_STATE_ERROR_WARNING: - ds->state = sys_cpu_to_le32(GS_USB_CHANNEL_STATE_ERROR_WARNING); - break; - case CAN_STATE_ERROR_PASSIVE: - ds->state = sys_cpu_to_le32(GS_USB_CHANNEL_STATE_ERROR_PASSIVE); - break; - case CAN_STATE_BUS_OFF: - ds->state = sys_cpu_to_le32(GS_USB_CHANNEL_STATE_BUS_OFF); - break; - case CAN_STATE_STOPPED: - ds->state = sys_cpu_to_le32(GS_USB_CHANNEL_STATE_STOPPED); - break; - default: - LOG_ERR("unsupported state %d for channel %u", state, ch); - return -ENOTSUP; - } - - *tlen = sizeof(*ds); - - return 0; -} - -static void gs_usb_bittiming_to_can_timing(const struct gs_usb_device_bittiming *dbt, - const struct can_timing *min, - const struct can_timing *max, struct can_timing *result) -{ - memset(result, 0U, sizeof(*result)); - - result->sjw = dbt->sjw; - result->prop_seg = dbt->prop_seg; - result->phase_seg1 = dbt->phase_seg1; - result->phase_seg2 = dbt->phase_seg2; - result->prescaler = dbt->brp; - - if (result->prop_seg < min->prop_seg) { - /* Move TQs from phase segment 1 to propagation segment */ - result->phase_seg1 -= (min->prop_seg - result->prop_seg); - result->prop_seg = min->prop_seg; - } else if (result->prop_seg > max->prop_seg) { - /* Move TQs from propagation segment to phase segment 1 */ - result->phase_seg1 += result->prop_seg - max->prop_seg; - result->prop_seg = max->prop_seg; - } - - if (result->phase_seg1 < min->phase_seg1) { - /* Move TQs from propagation segment to phase segment 1 */ - result->prop_seg -= (min->phase_seg1 - result->phase_seg1); - result->phase_seg1 = min->phase_seg1; - } else if (result->phase_seg1 > max->phase_seg1) { - /* Move TQs from phase segment 1 to propagation segment */ - result->prop_seg += result->phase_seg1 - max->phase_seg1; - result->phase_seg1 = max->phase_seg1; - } - - LOG_DBG("request: prop_seg %u, phase_seg1 %u, phase_seq2 %u, sjw %u, brp %u", dbt->prop_seg, - dbt->phase_seg1, dbt->phase_seg2, dbt->sjw, dbt->brp); - LOG_DBG("result: prop_seg %u, phase_seg1 %u, phase_seq2 %u, sjw %u, brp %u", - result->prop_seg, result->phase_seg1, result->phase_seg2, result->sjw, - result->prescaler); -}; - -static int gs_usb_request_bittiming(const struct device *dev, uint16_t ch, int32_t tlen, - uint8_t *tdata) -{ - struct gs_usb_device_bittiming *dbtp = (struct gs_usb_device_bittiming *)tdata; - struct gs_usb_device_bittiming dbt; - struct gs_usb_data *data = dev->data; - struct gs_usb_channel_data *channel; - const struct can_timing *min; - const struct can_timing *max; - struct can_timing timing; - int err; - - if (ch >= data->nchannels) { - LOG_ERR("bittiming request for non-existing channel %u", ch); - return -EINVAL; - } - - channel = &data->channels[ch]; - - if (tlen != sizeof(*dbtp)) { - LOG_ERR("invalid length for bittiming request (%d)", tlen); - return -EINVAL; - } - - if (channel->started) { - LOG_WRN("cannot change timing for already started channel %u", ch); - return -EBUSY; - } - - dbt.prop_seg = sys_le32_to_cpu(dbtp->prop_seg); - dbt.phase_seg1 = sys_le32_to_cpu(dbtp->phase_seg1); - dbt.phase_seg2 = sys_le32_to_cpu(dbtp->phase_seg2); - dbt.sjw = sys_le32_to_cpu(dbtp->sjw); - dbt.brp = sys_le32_to_cpu(dbtp->brp); - - min = can_get_timing_min(channel->dev); - max = can_get_timing_max(channel->dev); - - gs_usb_bittiming_to_can_timing(dbtp, min, max, &timing); - - err = can_set_timing(channel->dev, &timing); - if (err != 0U) { - LOG_ERR("failed to set timing for channel %u (err %d)", ch, err); - return err; - } - - return 0; -} - -static int gs_usb_request_data_bittiming(const struct device *dev, uint16_t ch, int32_t tlen, - uint8_t *tdata) -{ -#ifdef CONFIG_CAN_FD_MODE - struct gs_usb_device_bittiming *dbtp = (struct gs_usb_device_bittiming *)tdata; - struct gs_usb_device_bittiming dbt; - struct gs_usb_data *data = dev->data; - struct gs_usb_channel_data *channel; - const struct can_timing *min; - const struct can_timing *max; - struct can_timing timing_data; - int err; - - if (ch >= data->nchannels) { - LOG_ERR("data_bittiming request for non-existing channel %u", ch); - return -EINVAL; - } - - channel = &data->channels[ch]; - - if (tlen != sizeof(*dbtp)) { - LOG_ERR("invalid length for data_bittiming request (%d)", tlen); - return -EINVAL; - } - - if (channel->started) { - LOG_WRN("cannot change data phase timing for already started channel %u", ch); - return -EBUSY; - } - - dbt.prop_seg = sys_le32_to_cpu(dbtp->prop_seg); - dbt.phase_seg1 = sys_le32_to_cpu(dbtp->phase_seg1); - dbt.phase_seg2 = sys_le32_to_cpu(dbtp->phase_seg2); - dbt.sjw = sys_le32_to_cpu(dbtp->sjw); - dbt.brp = sys_le32_to_cpu(dbtp->brp); - - min = can_get_timing_data_min(channel->dev); - max = can_get_timing_data_max(channel->dev); - - if (min == NULL || max == NULL) { - LOG_ERR("failed to get min/max data phase timing for channel %u", ch); - return -ENOTSUP; - }; - - gs_usb_bittiming_to_can_timing(&dbt, min, max, &timing_data); - - err = can_set_timing_data(channel->dev, &timing_data); - if (err != 0U) { - LOG_ERR("failed to set data phase timing for channel %u (err %d)", ch, err); - return err; - } - - return 0; -#else /* CONFIG_CAN_FD_MODE */ - return -ENOTSUP; -#endif /* !CONFIG_CAN_FD_MODE */ -} - -static int gs_usb_request_mode(const struct device *dev, uint16_t ch, int32_t tlen, uint8_t *tdata) -{ - struct gs_usb_device_mode *dm = (struct gs_usb_device_mode *)tdata; - struct gs_usb_data *data = dev->data; - struct gs_usb_channel_data *channel; - can_mode_t mode = CAN_MODE_NORMAL; - enum gs_usb_event event; - uint32_t flags; - int err; - - if (ch >= data->nchannels) { - LOG_ERR("mode request for non-existing channel %u", ch); - return -EINVAL; - } - - if (tlen != sizeof(*dm)) { - LOG_ERR("invalid length for mode request (%d)", tlen); - return -EINVAL; - } - - channel = &data->channels[ch]; - - switch (sys_le32_to_cpu(dm->mode)) { - case GS_USB_CHANNEL_MODE_RESET: - err = gs_usb_reset_channel(dev, ch); - if (err != 0) { - return err; - } - break; - case GS_USB_CHANNEL_MODE_START: - if (channel->started) { - LOG_WRN("channel %u already started", ch); - return -EALREADY; - } - - flags = sys_le32_to_cpu(dm->flags); - - if ((flags & ~(channel->features)) != 0U) { - LOG_ERR("unsupported flags 0x%08x for channel %u", flags, ch); - return -ENOTSUP; - } - - if ((flags & GS_USB_CAN_MODE_LISTEN_ONLY) != 0U) { - mode |= CAN_MODE_LISTENONLY; - } - - if ((flags & GS_USB_CAN_MODE_LOOP_BACK) != 0U) { - mode |= CAN_MODE_LOOPBACK; - } - - if ((flags & GS_USB_CAN_MODE_TRIPLE_SAMPLE) != 0U) { - mode |= CAN_MODE_3_SAMPLES; - } - - if ((flags & GS_USB_CAN_MODE_ONE_SHOT) != 0U) { - mode |= CAN_MODE_ONE_SHOT; - } - - if ((flags & GS_USB_CAN_MODE_FD) != 0U) { - mode |= CAN_MODE_FD; - } - - err = can_set_mode(channel->dev, mode); - if (err != 0U) { - LOG_ERR("failed to set channel %u mode 0x%08x (err %d)", ch, mode, err); - return err; - } - - err = can_start(channel->dev); - if (err != 0U) { - LOG_ERR("failed to start channel %u (err %d)", ch, err); - return err; - } - - channel->mode = flags; - channel->started = true; - break; - default: - LOG_ERR("unsupported mode %d requested for channel %u channel", - sys_le32_to_cpu(dm->mode), ch); - return -ENOTSUP; - } - - if (data->ops.event != NULL) { - event = channel->started ? GS_USB_EVENT_CHANNEL_STARTED : - GS_USB_EVENT_CHANNEL_STOPPED; - err = data->ops.event(dev, channel->ch, event, data->user_data); - if (err != 0) { - LOG_ERR("failed to report channel %u state change (err %d)", channel->ch, - err); - } - } - - return 0; -} - -static int gs_usb_request_identify(const struct device *dev, uint16_t ch, int32_t tlen, - uint8_t *tdata) -{ -#ifdef CONFIG_USB_DEVICE_GS_USB_IDENTIFICATION - struct gs_usb_identify_mode *im = (struct gs_usb_identify_mode *)tdata; - struct gs_usb_data *data = dev->data; - enum gs_usb_event event; - uint32_t mode; - - if (ch >= data->nchannels) { - LOG_ERR("identify request for non-existing channel %u", ch); - return -EINVAL; - } - - if (tlen != sizeof(*im)) { - LOG_ERR("invalid length for identify request (%d)", tlen); - return -EINVAL; - } - - mode = sys_le32_to_cpu(im->mode); - - switch (mode) { - case GS_USB_CHANNEL_IDENTIFY_MODE_OFF: - event = GS_USB_EVENT_CHANNEL_IDENTIFY_OFF; - break; - case GS_USB_CHANNEL_IDENTIFY_MODE_ON: - event = GS_USB_EVENT_CHANNEL_IDENTIFY_ON; - break; - default: - LOG_ERR("unsupported identify mode %d for channel %u", mode, ch); - return -ENOTSUP; - } - - return data->ops.event(dev, ch, event, data->user_data); -#else /* CONFIG_USB_DEVICE_GS_USB_IDENTIFICATION */ - return -ENOTSUP; -#endif /* !CONFIG_USB_DEVICE_GS_USB_IDENTIFICATION */ -} - -static int gs_usb_request_device_config(const struct device *dev, int32_t *tlen, uint8_t **tdata) -{ - struct gs_usb_device_config *dc = (struct gs_usb_device_config *)*tdata; - struct gs_usb_data *data = dev->data; - - memset(dc, 0, sizeof(*dc)); - dc->nchannels = data->nchannels - 1U; /* 8 bit representing 1 to 256 */ - dc->sw_version = sys_cpu_to_le32(GS_USB_SW_VERSION); - dc->hw_version = sys_cpu_to_le32(GS_USB_HW_VERSION); - - *tlen = sizeof(*dc); - - return 0; -} - -static int gs_usb_request_timestamp(const struct device *dev, int32_t *tlen, uint8_t **tdata) -{ -#ifdef CONFIG_USB_DEVICE_GS_USB_TIMESTAMP - uint32_t *ts = (uint32_t *)*tdata; - struct gs_usb_data *data = dev->data; - uint32_t timestamp; - int err; - - if (data->ops.timestamp == NULL) { - LOG_ERR("timestamp not supported"); - return -ENOTSUP; - } - -#ifdef CONFIG_USB_DEVICE_GS_USB_TIMESTAMP_SOF - if (data->sof_seen) { - timestamp = data->timestamp; - data->sof_seen = false; - } else { -#endif /* CONFIG_USB_DEVICE_GS_USB_TIMESTAMP_SOF */ - err = data->ops.timestamp(dev, ×tamp, data->user_data); - if (err != 0) { - LOG_ERR("failed to get current timestamp (err %d)", err); - return err; - } -#ifdef CONFIG_USB_DEVICE_GS_USB_TIMESTAMP_SOF - LOG_WRN_ONCE("USB SoF event not supported, timestamp will be less accurate"); - } -#endif /* CONFIG_USB_DEVICE_GS_USB_TIMESTAMP_SOF */ - - LOG_DBG("timestamp: 0x%08x", timestamp); - - *ts = sys_cpu_to_le32(timestamp); - *tlen = sizeof(timestamp); - - return 0; -#else /* CONFIG_USB_DEVICE_GS_USB_TIMESTAMP */ - return -ENOTSUP; -#endif /* !CONFIG_USB_DEVICE_GS_USB_TIMESTAMP */ -} - -void gs_usb_register_vendorcode_callback(gs_usb_vendorcode_callback_t callback) -{ - vendorcode_callback = callback; -} - -static int gs_usb_vendor_request_handler(struct usb_setup_packet *setup, int32_t *tlen, - uint8_t **tdata) -{ - struct usb_dev_data *common; - const struct device *dev; - uint16_t ch; - - switch (setup->RequestType.recipient) { - case USB_REQTYPE_RECIPIENT_DEVICE: - if (usb_reqtype_is_to_host(setup)) { - if (setup->bRequest == GS_USB_MS_VENDORCODE && - setup->wIndex == MS_OS_20_DESCRIPTOR_INDEX) { - if (vendorcode_callback != NULL) { - return vendorcode_callback(tlen, tdata); - } - - return -ENOTSUP; - } - } - break; - case USB_REQTYPE_RECIPIENT_INTERFACE: - common = usb_get_dev_data_by_iface(&gs_usb_data_devlist, (uint8_t)setup->wIndex); - if (common == NULL) { - LOG_ERR("device data not found for interface %u", setup->wIndex); - return -ENODEV; - } - - dev = common->dev; - ch = setup->wValue; - - if (usb_reqtype_is_to_host(setup)) { - /* Interface to host */ - switch (setup->bRequest) { - case GS_USB_REQUEST_BERR: - /* Not supported */ - break; - case GS_USB_REQUEST_BT_CONST: - return gs_usb_request_bt_const(dev, ch, tlen, tdata); - case GS_USB_REQUEST_DEVICE_CONFIG: - return gs_usb_request_device_config(dev, tlen, tdata); - case GS_USB_REQUEST_TIMESTAMP: - return gs_usb_request_timestamp(dev, tlen, tdata); - case GS_USB_REQUEST_GET_USER_ID: - /* Not supported */ - break; - case GS_USB_REQUEST_BT_CONST_EXT: - return gs_usb_request_bt_const_ext(dev, ch, tlen, tdata); - case GS_USB_REQUEST_GET_TERMINATION: - return gs_usb_request_get_termination(dev, ch, tlen, tdata); - case GS_USB_REQUEST_GET_STATE: - return gs_usb_request_get_state(dev, ch, tlen, tdata); - default: - break; - } - } else { - /* Host to interface */ - switch (setup->bRequest) { - case GS_USB_REQUEST_HOST_FORMAT: - return gs_usb_request_host_format(*tlen, *tdata); - case GS_USB_REQUEST_BITTIMING: - return gs_usb_request_bittiming(dev, ch, *tlen, *tdata); - case GS_USB_REQUEST_MODE: - return gs_usb_request_mode(dev, ch, *tlen, *tdata); - case GS_USB_REQUEST_IDENTIFY: - return gs_usb_request_identify(dev, ch, *tlen, *tdata); - case GS_USB_REQUEST_DATA_BITTIMING: - return gs_usb_request_data_bittiming(dev, ch, *tlen, *tdata); - case GS_USB_REQUEST_SET_USER_ID: - /* Not supported */ - break; - case GS_USB_REQUEST_SET_TERMINATION: - return gs_usb_request_set_termination(dev, ch, *tlen, *tdata); - default: - break; - } - } - break; - default: - break; - } - - LOG_ERR("bmRequestType 0x%02x bRequest 0x%02x not supported", setup->bmRequestType, - setup->bRequest); - - return -ENOTSUP; -} - -static void gs_usb_fill_echo_frame_hdr(struct net_buf *buf, uint32_t echo_id, uint8_t channel, - uint8_t flags) -{ - struct gs_usb_host_frame_hdr hdr = {0}; - - __ASSERT_NO_MSG(buf != NULL); - - hdr.echo_id = sys_cpu_to_le32(echo_id); - hdr.channel = channel; - hdr.flags = flags; - - net_buf_reset(buf); - net_buf_add_mem(buf, &hdr, sizeof(hdr)); -} - -static void gs_usb_can_state_change_callback(const struct device *can_dev, enum can_state state, - struct can_bus_err_cnt err_cnt, void *user_data) -{ - struct gs_usb_channel_data *channel = user_data; - struct gs_usb_data *data = CONTAINER_OF(channel, struct gs_usb_data, channels[channel->ch]); - uint32_t can_id = GS_USB_CAN_ID_FLAG_ERR; - struct gs_usb_host_frame_hdr hdr = {0}; - uint8_t payload[8] = {0}; - struct net_buf *buf; - int err; - - __ASSERT_NO_MSG(can_dev == channel->dev); - - buf = net_buf_alloc_fixed(data->pool, K_NO_WAIT); - if (buf == NULL) { - LOG_ERR("failed to allocate error frame for channel %u", channel->ch); - k_sem_give(&channel->rx_overflows); - return; - } - -#ifdef CONFIG_USB_DEVICE_GS_USB_TIMESTAMP - uint32_t timestamp = 0U; - - if ((channel->mode & GS_USB_CAN_MODE_HW_TIMESTAMP) != 0U) { - err = data->ops.timestamp(data->common.dev, ×tamp, data->user_data); - if (err != 0) { - LOG_ERR("failed to get RX timestamp (err %d)", err); - } - } -#endif /* CONFIG_USB_DEVICE_GS_USB_TIMESTAMP */ - - hdr.echo_id = GS_USB_HOST_FRAME_ECHO_ID_RX_FRAME; - hdr.can_dlc = can_bytes_to_dlc(sizeof(payload)); - hdr.channel = channel->ch; - - switch (state) { - case CAN_STATE_ERROR_ACTIVE: - can_id |= GS_USB_CAN_ID_FLAG_ERR_CRTL; - payload[1] |= GS_USB_CAN_ERR_CRTL_ACTIVE; - - if (channel->busoff) { - can_id |= GS_USB_CAN_ID_FLAG_ERR_RESTARTED; - } - break; - case CAN_STATE_ERROR_WARNING: - can_id |= GS_USB_CAN_ID_FLAG_ERR_CRTL; - payload[1] |= GS_USB_CAN_ERR_CRTL_TX_WARNING | GS_USB_CAN_ERR_CRTL_RX_WARNING; - break; - case CAN_STATE_ERROR_PASSIVE: - can_id |= GS_USB_CAN_ID_FLAG_ERR_CRTL; - payload[1] |= GS_USB_CAN_ERR_CRTL_TX_PASSIVE | GS_USB_CAN_ERR_CRTL_RX_PASSIVE; - break; - case CAN_STATE_BUS_OFF: - can_id |= GS_USB_CAN_ID_FLAG_ERR_BUSOFF; - break; - case CAN_STATE_STOPPED: - /* Not reported */ - return; - } - - channel->busoff = (state == CAN_STATE_BUS_OFF); - - can_id |= GS_USB_CAN_ID_FLAG_ERR_CNT; - payload[6] = err_cnt.tx_err_cnt; - payload[7] = err_cnt.rx_err_cnt; - - hdr.can_id = sys_cpu_to_le32(can_id); - net_buf_add_mem(buf, &hdr, sizeof(hdr)); - net_buf_add_mem(buf, &payload, can_dlc_to_bytes(hdr.can_dlc)); - -#ifdef CONFIG_USB_DEVICE_GS_USB_TIMESTAMP - if ((channel->mode & GS_USB_CAN_MODE_HW_TIMESTAMP) != 0U) { - net_buf_add_le32(buf, timestamp); - } -#endif /* CONFIG_USB_DEVICE_GS_USB_TIMESTAMP */ - - k_fifo_put(&data->rx_fifo, buf); - - if (data->ops.event != NULL) { - enum gs_usb_event event; - - if (state == CAN_STATE_ERROR_PASSIVE || state == CAN_STATE_BUS_OFF) { - event = GS_USB_EVENT_CHANNEL_ERROR_ON; - } else { - event = GS_USB_EVENT_CHANNEL_ERROR_OFF; - } - - err = data->ops.event(data->common.dev, channel->ch, event, data->user_data); - if (err != 0) { - LOG_ERR("state callback for channel %u failed (err %d)", channel->ch, err); - } - } -} - -static void gs_usb_can_rx_callback(const struct device *can_dev, struct can_frame *frame, - void *user_data) -{ - struct gs_usb_channel_data *channel = user_data; - struct gs_usb_data *data = CONTAINER_OF(channel, struct gs_usb_data, channels[channel->ch]); - struct gs_usb_host_frame_hdr hdr = {0}; - struct net_buf *buf; - - __ASSERT_NO_MSG(can_dev == channel->dev); - -#ifdef CONFIG_USB_DEVICE_GS_USB_TIMESTAMP - uint32_t timestamp = 0U; - int err; - - if ((channel->mode & GS_USB_CAN_MODE_HW_TIMESTAMP) != 0U) { - err = data->ops.timestamp(data->common.dev, ×tamp, data->user_data); - if (err != 0) { - LOG_ERR("failed to get RX timestamp (err %d)", err); - } - } -#endif /* CONFIG_USB_DEVICE_GS_USB_TIMESTAMP */ - - buf = net_buf_alloc_fixed(data->pool, K_NO_WAIT); - if (buf == NULL) { - LOG_ERR("failed to allocate RX host frame for channel %u", channel->ch); - k_sem_give(&channel->rx_overflows); - return; - } - - hdr.echo_id = GS_USB_HOST_FRAME_ECHO_ID_RX_FRAME; - hdr.can_id = sys_cpu_to_le32(frame->id); - hdr.can_dlc = frame->dlc; - hdr.channel = channel->ch; - - if ((frame->flags & CAN_FRAME_IDE) != 0U) { - hdr.can_id |= sys_cpu_to_le32(GS_USB_CAN_ID_FLAG_IDE); - } - - if ((frame->flags & CAN_FRAME_RTR) != 0U) { - hdr.can_id |= sys_cpu_to_le32(GS_USB_CAN_ID_FLAG_RTR); - } - - if (IS_ENABLED(CONFIG_CAN_FD_MODE)) { - if ((frame->flags & CAN_FRAME_FDF) != 0U) { - hdr.flags |= GS_USB_CAN_FLAG_FD; - - if ((frame->flags & CAN_FRAME_BRS) != 0U) { - hdr.flags |= GS_USB_CAN_FLAG_BRS; - } - - if ((frame->flags & CAN_FRAME_ESI) != 0U) { - hdr.flags |= GS_USB_CAN_FLAG_ESI; - } - } - } - - net_buf_add_mem(buf, &hdr, sizeof(hdr)); - - if (IS_ENABLED(CONFIG_CAN_FD_MODE) && ((frame->flags & CAN_FRAME_FDF) != 0U)) { - net_buf_add_mem(buf, &frame->data, can_dlc_to_bytes(CANFD_MAX_DLC)); - } else { - net_buf_add_mem(buf, &frame->data, can_dlc_to_bytes(CAN_MAX_DLC)); - } - -#ifdef CONFIG_USB_DEVICE_GS_USB_TIMESTAMP - if ((channel->mode & GS_USB_CAN_MODE_HW_TIMESTAMP) != 0U) { - net_buf_add_le32(buf, timestamp); - } -#endif /* CONFIG_USB_DEVICE_GS_USB_TIMESTAMP */ - - k_fifo_put(&data->rx_fifo, buf); -} - -static void gs_usb_rx_thread(void *p1, void *p2, void *p3) -{ - const struct device *dev = p1; - struct usb_cfg_data *cfg = (void *)dev->config; - struct gs_usb_data *data = dev->data; - struct gs_usb_channel_data *channel; - struct gs_usb_host_frame_hdr *hdr; - enum gs_usb_event event; - struct net_buf *buf; - uint32_t can_id; - uint16_t ch; - int err; - - ARG_UNUSED(p2); - ARG_UNUSED(p3); - - while (true) { - buf = k_fifo_get(&data->rx_fifo, K_FOREVER); - - hdr = (struct gs_usb_host_frame_hdr *)buf->data; - can_id = hdr->can_id; - ch = hdr->channel; - - if (hdr->echo_id == GS_USB_HOST_FRAME_ECHO_ID_RX_FRAME) { - event = GS_USB_EVENT_CHANNEL_ACTIVITY_RX; - } else { - event = GS_USB_EVENT_CHANNEL_ACTIVITY_TX; - } - - __ASSERT_NO_MSG(ch <= data->nchannels); - channel = &data->channels[ch]; - - if (k_sem_take(&channel->rx_overflows, K_NO_WAIT) == 0) { - hdr->flags |= GS_USB_CAN_FLAG_OVERFLOW; - } - - LOG_HEXDUMP_DBG(buf->data, buf->len, "RX host frame"); - - usb_transfer_sync(cfg->endpoint[GS_USB_IN_EP_IDX].ep_addr, buf->data, - buf->len, USB_TRANS_WRITE); - - net_buf_unref(buf); - - if ((can_id & GS_USB_CAN_ID_FLAG_ERR) != 0U) { - /* Only indicate actual RX/TX activity, not error frames */ - continue; - } - - if (data->ops.event != NULL) { - err = data->ops.event(dev, ch, event, data->user_data); - if (err != 0) { - LOG_ERR("activity callback for channel %u failed (err %d)", ch, - err); - } - } - } -} - -static void gs_usb_can_tx_callback(const struct device *can_dev, int error, void *user_data) -{ - struct net_buf *buf = user_data; - uintptr_t *pchannel = net_buf_remove_mem(buf, sizeof(uintptr_t)); - struct gs_usb_channel_data *channel = UINT_TO_POINTER(*pchannel); - struct gs_usb_data *data = CONTAINER_OF(channel, struct gs_usb_data, channels[channel->ch]); - struct gs_usb_host_frame_hdr *hdr = (struct gs_usb_host_frame_hdr *)buf->data; - size_t padding; - uint8_t *tail; - - if (error != 0) { - /* There is no way to report a dropped frame to the host driver */ - LOG_ERR("failed to send CAN frame (err %d)", error); - net_buf_unref(buf); - return; - } - -#ifdef CONFIG_USB_DEVICE_GS_USB_TIMESTAMP - uint32_t timestamp = 0U; - int err; - - if ((channel->mode & GS_USB_CAN_MODE_HW_TIMESTAMP) != 0U) { - err = data->ops.timestamp(data->common.dev, ×tamp, data->user_data); - if (err != 0) { - LOG_ERR("failed to get TX timestamp (err %d)", err); - } - } -#endif /* CONFIG_USB_DEVICE_GS_USB_TIMESTAMP */ - - if ((hdr->flags & GS_USB_CAN_FLAG_FD) != 0U) { - padding = sizeof(struct gs_usb_canfd_frame); - } else { - padding = sizeof(struct gs_usb_can_frame); - } - - tail = net_buf_add(buf, padding); - memset(tail, 0, padding); - -#ifdef CONFIG_USB_DEVICE_GS_USB_TIMESTAMP - if ((channel->mode & GS_USB_CAN_MODE_HW_TIMESTAMP) != 0U) { - net_buf_add_le32(buf, timestamp); - } -#endif /* CONFIG_USB_DEVICE_GS_USB_TIMESTAMP */ - - LOG_DBG("TX done"); - - k_fifo_put(&data->rx_fifo, buf); -} - -static void gs_usb_transfer_tx_callback(uint8_t ep, int tsize, void *priv) -{ - const struct device *dev = priv; - struct gs_usb_data *data = dev->data; - struct net_buf *buf; - - if (tsize > 0) { - buf = net_buf_alloc_len(data->pool, tsize, K_NO_WAIT); - if (buf == NULL) { - LOG_ERR("failed to allocate TX buffer"); - return; - } - -#ifdef CONFIG_USB_DEVICE_GS_USB_COMPATIBILITY_MODE - struct usb_cfg_data *cfg = (void *)dev->config; - - if (ep == cfg->endpoint[GS_USB_OUT1_EP_IDX].ep_addr) { - net_buf_add_mem(buf, data->tx_buffer1, tsize); - } else { -#endif /* CONFIG_USB_DEVICE_GS_USB_COMPATIBILITY_MODE */ - net_buf_add_mem(buf, data->tx_buffer2, tsize); -#ifdef CONFIG_USB_DEVICE_GS_USB_COMPATIBILITY_MODE - } -#endif /* CONFIG_USB_DEVICE_GS_USB_COMPATIBILITY_MODE */ - - k_fifo_put(&data->tx_fifo, buf); - } - - gs_usb_transfer_tx_prepare(dev, ep); -} - -static void gs_usb_transfer_tx_prepare(const struct device *dev, uint8_t ep) -{ - struct usb_cfg_data *cfg = (void *)dev->config; - struct gs_usb_data *data = dev->data; - -#ifdef CONFIG_USB_DEVICE_GS_USB_COMPATIBILITY_MODE - if (ep == cfg->endpoint[GS_USB_OUT1_EP_IDX].ep_addr) { - usb_transfer(cfg->endpoint[GS_USB_OUT1_EP_IDX].ep_addr, data->tx_buffer1, - sizeof(data->tx_buffer1), USB_TRANS_READ, gs_usb_transfer_tx_callback, - (void *)dev); - } else { -#endif /* CONFIG_USB_DEVICE_GS_USB_COMPATIBILITY_MODE */ - usb_transfer(cfg->endpoint[GS_USB_OUT2_EP_IDX].ep_addr, data->tx_buffer2, - sizeof(data->tx_buffer2), USB_TRANS_READ, gs_usb_transfer_tx_callback, - (void *)dev); -#ifdef CONFIG_USB_DEVICE_GS_USB_COMPATIBILITY_MODE - } -#endif /* CONFIG_USB_DEVICE_GS_USB_COMPATIBILITY_MODE */ -} - -static void gs_usb_tx_thread(void *p1, void *p2, void *p3) -{ - const struct device *dev = p1; - struct gs_usb_data *data = dev->data; - struct gs_usb_channel_data *channel; - struct gs_usb_host_frame_hdr *hdr; - struct can_frame frame; - struct net_buf *buf; - uintptr_t pchannel; - uint32_t can_id; - int err; - - ARG_UNUSED(p2); - ARG_UNUSED(p3); - - while (true) { - memset(&frame, 0, sizeof(frame)); - buf = k_fifo_get(&data->tx_fifo, K_FOREVER); - - LOG_HEXDUMP_DBG(buf->data, buf->len, "TX host frame"); - - if (buf->len < sizeof(*hdr)) { - LOG_ERR("TX host frame contains no header (%d < %d)", buf->len, - sizeof(*hdr)); - net_buf_unref(buf); - continue; - } - - hdr = net_buf_pull_mem(buf, sizeof(*hdr)); - - if (hdr->channel >= data->nchannels) { - LOG_ERR("TX host frame for non-existing channel %u", hdr->channel); - net_buf_unref(buf); - continue; - } - - channel = &data->channels[hdr->channel]; - if (!channel->started) { - LOG_ERR("channel %u not started, ignoring TX host frame", hdr->channel); - net_buf_unref(buf); - continue; - } - - can_id = sys_le32_to_cpu(hdr->can_id); - if ((can_id & GS_USB_CAN_ID_FLAG_IDE) != 0U) { - frame.flags |= CAN_FRAME_IDE; - frame.id = can_id & CAN_EXT_ID_MASK; - } else { - frame.id = hdr->can_id & CAN_STD_ID_MASK; - } - - if (IS_ENABLED(CONFIG_CAN_FD_MODE)) { - if ((hdr->flags & GS_USB_CAN_FLAG_FD) != 0U) { - frame.flags |= CAN_FRAME_FDF; - } - - if ((hdr->flags & GS_USB_CAN_FLAG_BRS) != 0U) { - frame.flags |= CAN_FRAME_BRS; - } - } - - frame.dlc = hdr->can_dlc; - - if ((can_id & GS_USB_CAN_ID_FLAG_RTR) != 0U) { - frame.flags |= CAN_FRAME_RTR; - } else if (hdr->can_dlc != 0U) { - if (can_dlc_to_bytes(frame.dlc) > buf->len) { - LOG_ERR("TX host frame DLC exceeds buffer length (%d > %d)", - can_dlc_to_bytes(frame.dlc), buf->len); - net_buf_unref(buf); - continue; - } - - memcpy(&frame.data, buf->data, can_dlc_to_bytes(frame.dlc)); - } - - gs_usb_fill_echo_frame_hdr(buf, sys_le32_to_cpu(hdr->echo_id), hdr->channel, - hdr->flags); - - pchannel = POINTER_TO_UINT(channel); - net_buf_add_mem(buf, &pchannel, sizeof(pchannel)); - - err = can_send(channel->dev, &frame, K_FOREVER, gs_usb_can_tx_callback, buf); - if (err != 0) { - /* There is no way to report a dropped frame to the host driver */ - LOG_ERR("failed to enqueue CAN frame for TX (err %d)", err); - net_buf_unref(buf); - } - } -} - -static uint32_t gs_usb_features_from_ops(struct gs_usb_ops *ops) -{ - uint32_t features = 0U; - - if (UTIL_AND(IS_ENABLED(CONFIG_USB_DEVICE_GS_USB_TIMESTAMP), ops->timestamp != NULL)) { - features |= GS_USB_CAN_FEATURE_HW_TIMESTAMP; - } - - if (UTIL_AND(IS_ENABLED(CONFIG_USB_DEVICE_GS_USB_IDENTIFICATION), ops->event != NULL)) { - features |= GS_USB_CAN_FEATURE_IDENTIFY; - } - - if (UTIL_AND(IS_ENABLED(CONFIG_USB_DEVICE_GS_USB_TERMINATION), - ops->set_termination != NULL && ops->get_termination != NULL)) { - features |= GS_USB_CAN_FEATURE_TERMINATION; - } - - return features; -} - -static uint32_t gs_usb_features_from_capabilities(can_mode_t caps) -{ - uint32_t features = 0U; - - if ((caps & CAN_MODE_LOOPBACK) != 0U) { - features |= GS_USB_CAN_FEATURE_LOOP_BACK; - } - - if ((caps & CAN_MODE_LISTENONLY) != 0U) { - features |= GS_USB_CAN_FEATURE_LISTEN_ONLY; - } - - if ((caps & CAN_MODE_FD) != 0U) { - features |= GS_USB_CAN_FEATURE_FD; - features |= GS_USB_CAN_FEATURE_BT_CONST_EXT; - } - - if ((caps & CAN_MODE_ONE_SHOT) != 0U) { - features |= GS_USB_CAN_FEATURE_ONE_SHOT; - } - - if ((caps & CAN_MODE_3_SAMPLES) != 0U) { - features |= GS_USB_CAN_FEATURE_TRIPLE_SAMPLE; - } - - return features; -} - -static int gs_usb_reset_channel(const struct device *dev, uint16_t ch) -{ - struct gs_usb_data *data = dev->data; - struct gs_usb_channel_data *channel; - int err; - - if (ch >= data->nchannels) { - LOG_ERR("attempt to reset non-existing channel %u", ch); - return -EINVAL; - } - - channel = &data->channels[ch]; - channel->mode = GS_USB_CAN_MODE_NORMAL; - channel->started = false; - channel->busoff = false; - k_sem_reset(&channel->rx_overflows); - - err = can_stop(channel->dev); - if (err != 0 && err != -EALREADY) { - LOG_ERR("failed to stop channel %u (err %d)", ch, err); - return err; - } - - return 0; -} - -static int gs_usb_register_channel(struct gs_usb_channel_data *channel, uint16_t ch, - const struct device *can_dev, uint32_t common_features) -{ - const struct can_filter filters[] = { - { - .id = 0U, - .mask = 0U, - .flags = 0U, - }, - { - .id = 0U, - .mask = 0U, - .flags = CAN_FILTER_IDE, - }, - }; - can_mode_t caps; - int err; - int i; - - k_sem_init(&channel->rx_overflows, 0U, K_SEM_MAX_LIMIT); - - if (!device_is_ready(can_dev)) { - LOG_ERR("channel %d CAN device not ready", ch); - return -ENODEV; - } - - err = can_get_capabilities(can_dev, &caps); - if (err != 0U) { - LOG_ERR("failed to get capabilities for channel %u (err %d)", ch, err); - return err; - } - - for (i = 0; i < ARRAY_SIZE(filters); i++) { - err = can_add_rx_filter(can_dev, gs_usb_can_rx_callback, channel, &filters[i]); - if (err < 0U) { - LOG_ERR("failed to add filter %d to channel %d (err %d)", i, ch, err); - return err; - } - } - - can_set_state_change_callback(can_dev, gs_usb_can_state_change_callback, channel); - - channel->ch = ch; - channel->dev = can_dev; - channel->features = common_features; - channel->features |= gs_usb_features_from_capabilities(caps); - - LOG_DBG("channel %d features = 0x%08x", ch, channel->features); - - return 0; -} - -int gs_usb_register(const struct device *dev, const struct device **channels, size_t nchannels, - const struct gs_usb_ops *ops, void *user_data) -{ - struct gs_usb_data *data = dev->data; - uint32_t common_features = GS_USB_CAN_FEATURE_GET_STATE; - int err; - int ch; - - if (nchannels < 1U || nchannels > ARRAY_SIZE(data->channels)) { - LOG_ERR("unsupported number of CAN channels %u", nchannels); - return -ENOTSUP; - } - - if (ops != NULL) { - data->ops = *ops; - } - - data->nchannels = nchannels; - data->user_data = user_data; - - common_features |= gs_usb_features_from_ops(&data->ops); - - for (ch = 0; ch < nchannels; ch++) { - err = gs_usb_register_channel(&data->channels[ch], ch, channels[ch], - common_features); - if (err != 0U) { - LOG_ERR("failed to register channel %d (err %d)", ch, err); - return err; - } - } - - sys_slist_append(&gs_usb_data_devlist, &data->common.node); - - return 0; -} - -static void gs_usb_status_callback(struct usb_cfg_data *cfg, enum usb_dc_status_code status, - const uint8_t *param) -{ - struct usb_dev_data *common; - struct gs_usb_data *data; - int ch; - - common = usb_get_dev_data_by_cfg(&gs_usb_data_devlist, cfg); - if (common == NULL) { - LOG_ERR("device data not found for cfg %p", cfg); - return; - } - - data = CONTAINER_OF(common, struct gs_usb_data, common); - - switch (status) { - case USB_DC_ERROR: - LOG_DBG("USB device error"); - break; - case USB_DC_RESET: - LOG_DBG("USB device reset"); - break; - case USB_DC_CONNECTED: - LOG_DBG("USB device connected"); - break; - case USB_DC_CONFIGURED: - LOG_DBG("USB device configured"); - LOG_DBG("EP IN addr = 0x%02x", cfg->endpoint[GS_USB_IN_EP_IDX].ep_addr); -#ifdef CONFIG_USB_DEVICE_GS_USB_COMPATIBILITY_MODE - LOG_DBG("EP OUT1 addr = 0x%02x", cfg->endpoint[GS_USB_OUT1_EP_IDX].ep_addr); - gs_usb_transfer_tx_prepare(common->dev, cfg->endpoint[GS_USB_OUT1_EP_IDX].ep_addr); -#endif /* CONFIG_USB_DEVICE_GS_USB_COMPATIBILITY_MODE */ - LOG_DBG("EP OUT2 addr = 0x%02x", cfg->endpoint[GS_USB_OUT2_EP_IDX].ep_addr); - gs_usb_transfer_tx_prepare(common->dev, cfg->endpoint[GS_USB_OUT2_EP_IDX].ep_addr); - break; - case USB_DC_DISCONNECTED: - LOG_DBG("USB device disconnected"); - for (ch = 0; ch < data->nchannels; ch++) { - (void)gs_usb_reset_channel(common->dev, ch); - } - - usb_cancel_transfer(cfg->endpoint[GS_USB_IN_EP_IDX].ep_addr); -#ifdef CONFIG_USB_DEVICE_GS_USB_COMPATIBILITY_MODE - usb_cancel_transfer(cfg->endpoint[GS_USB_OUT1_EP_IDX].ep_addr); -#endif /* CONFIG_USB_DEVICE_GS_USB_COMPATIBILITY_MODE */ - usb_cancel_transfer(cfg->endpoint[GS_USB_OUT2_EP_IDX].ep_addr); - break; - case USB_DC_SUSPEND: - LOG_DBG("USB device suspend"); - break; - case USB_DC_RESUME: - LOG_DBG("USB device resume"); - break; - case USB_DC_INTERFACE: - LOG_DBG("USB device interface selected"); - break; - case USB_DC_SET_HALT: - LOG_DBG("USB device set halt"); - break; - case USB_DC_CLEAR_HALT: - LOG_DBG("USB device clear halt"); - break; - case USB_DC_SOF: -#ifdef CONFIG_USB_DEVICE_GS_USB_TIMESTAMP_SOF - int err; - - if (data->ops.timestamp != NULL) { - err = data->ops.timestamp(common->dev, &data->timestamp, data->user_data); - if (err != 0) { - LOG_ERR("failed to get current timestamp (err %d)", err); - break; - } - - /* Not all USB device controller drivers support SoF events */ - data->sof_seen = true; - } -#endif /* CONFIG_USB_DEVICE_GS_USB_TIMESTAMP_SOF */ - break; - case USB_DC_UNKNOWN: - __fallthrough; - default: - LOG_ERR("USB device unknown state"); - break; - } -} - -static void gs_usb_interface_config(struct usb_desc_header *head, uint8_t bInterfaceNumber) -{ - struct usb_if_descriptor *if_desc = (struct usb_if_descriptor *)head; - struct gs_usb_config *desc = CONTAINER_OF(if_desc, struct gs_usb_config, if0); - struct usb_dev_data *common; - struct gs_usb_data *data; - int idx; - - LOG_DBG("bInterfaceNumber = %u", bInterfaceNumber); - - common = usb_get_dev_data_by_iface(&gs_usb_data_devlist, bInterfaceNumber); - if (common == NULL) { - LOG_ERR("device data not found for interface %u", bInterfaceNumber); - return; - } - - data = CONTAINER_OF(common, struct gs_usb_data, common); - - desc->if0.bInterfaceNumber = bInterfaceNumber; - - if (data->if0_str_desc != NULL) { - idx = usb_get_str_descriptor_idx(data->if0_str_desc); - desc->if0.iInterface = idx; - } -} - -static int gs_usb_init(const struct device *dev) -{ - struct gs_usb_data *data = dev->data; - - data->common.dev = dev; - - k_fifo_init(&data->rx_fifo); - k_fifo_init(&data->tx_fifo); - - k_thread_create(&data->rx_thread, data->rx_stack, K_KERNEL_STACK_SIZEOF(data->rx_stack), - gs_usb_rx_thread, (void *)dev, NULL, NULL, - CONFIG_USB_DEVICE_GS_USB_RX_THREAD_PRIO, 0, K_NO_WAIT); - k_thread_name_set(&data->rx_thread, "gs_usb_rx"); - - k_thread_create(&data->tx_thread, data->tx_stack, K_KERNEL_STACK_SIZEOF(data->tx_stack), - gs_usb_tx_thread, (void *)dev, NULL, NULL, - CONFIG_USB_DEVICE_GS_USB_TX_THREAD_PRIO, 0, K_NO_WAIT); - k_thread_name_set(&data->tx_thread, "gs_usb_tx"); - - return 0; -} - -#define INITIALIZER_IF \ - { \ - .bLength = sizeof(struct usb_if_descriptor), \ - .bDescriptorType = USB_DESC_INTERFACE, \ - .bInterfaceNumber = 0, \ - .bAlternateSetting = 0, \ - .bNumEndpoints = \ - COND_CODE_1(CONFIG_USB_DEVICE_GS_USB_COMPATIBILITY_MODE, (3), (2)), \ - .bInterfaceClass = USB_BCC_VENDOR, \ - .bInterfaceSubClass = 0, \ - .bInterfaceProtocol = 0, \ - .iInterface = 0, \ - } - -#define INITIALIZER_IF_EP(addr) \ - { \ - .bLength = sizeof(struct usb_ep_descriptor), \ - .bDescriptorType = USB_DESC_ENDPOINT, \ - .bEndpointAddress = addr, \ - .bmAttributes = USB_DC_EP_BULK, \ - .wMaxPacketSize = sys_cpu_to_le16(CONFIG_USB_DEVICE_GS_USB_MAX_PACKET_SIZE), \ - .bInterval = 0x01, \ - } - -#define GS_USB_DEVICE_DEFINE(inst) \ - NET_BUF_POOL_FIXED_DEFINE(gs_usb_pool_##inst, CONFIG_USB_DEVICE_GS_USB_POOL_SIZE, \ - GS_USB_HOST_FRAME_MAX_SIZE, 0, NULL); \ - \ - IF_ENABLED(DT_INST_NODE_HAS_PROP(inst, label), ( \ - struct gs_usb_if0_str_desc_##inst { \ - uint8_t bLength; \ - uint8_t bDescriptorType; \ - uint8_t bString[USB_BSTRING_LENGTH(DT_INST_PROP(inst, label))]; \ - } __packed; \ - \ - USBD_STRING_DESCR_USER_DEFINE(primary) \ - struct gs_usb_if0_str_desc_##inst gs_usb_if0_str_desc_##inst = { \ - .bLength = USB_STRING_DESCRIPTOR_LENGTH(DT_INST_PROP(inst, label)), \ - .bDescriptorType = USB_DESC_STRING, \ - .bString = DT_INST_PROP(inst, label), \ - };)) \ - \ - USBD_CLASS_DESCR_DEFINE(primary, 0) \ - struct gs_usb_config gs_usb_config_##inst = { \ - .if0 = INITIALIZER_IF, \ - .if0_in_ep = INITIALIZER_IF_EP(GS_USB_IN_EP_ADDR), \ - IF_ENABLED(CONFIG_USB_DEVICE_GS_USB_COMPATIBILITY_MODE, \ - (.if0_out1_ep = INITIALIZER_IF_EP(GS_USB_OUT1_EP_ADDR),)) \ - .if0_out2_ep = INITIALIZER_IF_EP(GS_USB_OUT2_EP_ADDR), \ - }; \ - \ - static struct usb_ep_cfg_data gs_usb_ep_cfg_data_##inst[] = { \ - { \ - .ep_cb = usb_transfer_ep_callback, \ - .ep_addr = GS_USB_IN_EP_ADDR, \ - }, \ - IF_ENABLED(CONFIG_USB_DEVICE_GS_USB_COMPATIBILITY_MODE, ( \ - { \ - .ep_cb = usb_transfer_ep_callback, \ - .ep_addr = GS_USB_OUT1_EP_ADDR, \ - },)) \ - { \ - .ep_cb = usb_transfer_ep_callback, \ - .ep_addr = GS_USB_OUT2_EP_ADDR, \ - }, \ - }; \ - \ - USBD_DEFINE_CFG_DATA(gs_usb_cfg_##inst) = { \ - .usb_device_description = NULL, \ - .interface_config = gs_usb_interface_config, \ - .interface_descriptor = &gs_usb_config_##inst.if0, \ - .cb_usb_status = gs_usb_status_callback, \ - .interface = { \ - .class_handler = NULL, \ - .custom_handler = NULL, \ - .vendor_handler = gs_usb_vendor_request_handler, \ - }, \ - .num_endpoints = ARRAY_SIZE(gs_usb_ep_cfg_data_##inst), \ - .endpoint = gs_usb_ep_cfg_data_##inst, \ - }; \ - \ - static struct gs_usb_data gs_usb_data_##inst = { \ - .pool = &gs_usb_pool_##inst, \ - IF_ENABLED(DT_INST_NODE_HAS_PROP(inst, label), \ - (.if0_str_desc = &gs_usb_if0_str_desc_##inst,)) \ - }; \ - \ - DEVICE_DT_INST_DEFINE(inst, gs_usb_init, NULL, &gs_usb_data_##inst, &gs_usb_cfg_##inst, \ - POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, NULL); - -DT_INST_FOREACH_STATUS_OKAY(GS_USB_DEVICE_DEFINE); diff --git a/tests/subsys/usb/gs_usb/host/Kconfig b/tests/subsys/usb/gs_usb/host/Kconfig index f6d6c78..1f1f6e7 100644 --- a/tests/subsys/usb/gs_usb/host/Kconfig +++ b/tests/subsys/usb/gs_usb/host/Kconfig @@ -35,25 +35,6 @@ config TEST_USB_MAX_POWER USB maximum current draw in milliampere (mA) divided by 2. A value of 125 results in a maximum current draw value of 250 mA. -if USB_DEVICE_STACK - -configdefault USB_DEVICE_MANUFACTURER - default TEST_USB_MANUFACTURER - -configdefault USB_DEVICE_PRODUCT - default TEST_USB_PRODUCT - -configdefault USB_DEVICE_VID - default TEST_USB_VID - -configdefault USB_DEVICE_PID - default TEST_USB_PID - -configdefault USB_MAX_POWER - default TEST_USB_MAX_POWER - -endif # USB_DEVICE_STACK - endmenu source "Kconfig.zephyr" diff --git a/tests/subsys/usb/gs_usb/host/prj_legacy.conf b/tests/subsys/usb/gs_usb/host/prj_legacy.conf deleted file mode 100644 index b089c0a..0000000 --- a/tests/subsys/usb/gs_usb/host/prj_legacy.conf +++ /dev/null @@ -1,23 +0,0 @@ -# This is using the deprecated USB device stack -CONFIG_DEPRECATION_TEST=y - -CONFIG_TEST=y - -CONFIG_LOG=y -CONFIG_USB_DRIVER_LOG_LEVEL_ERR=y -CONFIG_USB_DEVICE_LOG_LEVEL_ERR=y -CONFIG_USB_DEVICE_GS_USB_LOG_LEVEL_DBG=y - -CONFIG_SHELL=y - -CONFIG_USB_DEVICE_STACK=y -CONFIG_USB_DEVICE_BOS=y -CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n - -CONFIG_CAN=y -CONFIG_CAN_FD_MODE=y - -CONFIG_USB_DEVICE_GS_USB_MAX_CHANNELS=4 -CONFIG_USB_DEVICE_GS_USB_IDENTIFICATION=y -CONFIG_USB_DEVICE_GS_USB_TIMESTAMP=y -CONFIG_USB_DEVICE_GS_USB_TERMINATION=y diff --git a/tests/subsys/usb/gs_usb/host/src/usb.c b/tests/subsys/usb/gs_usb/host/src/usb.c index c20e330..bc8d291 100644 --- a/tests/subsys/usb/gs_usb/host/src/usb.c +++ b/tests/subsys/usb/gs_usb/host/src/usb.c @@ -6,13 +6,7 @@ #include #include - -#ifdef CONFIG_USB_DEVICE_STACK_NEXT #include -#else /* CONFIG_USB_DEVICE_STACK_NEXT */ -#include -#include -#endif /* !CONFIG_USB_DEVICE_STACK_NEXT*/ #include "test.h" @@ -20,21 +14,13 @@ LOG_MODULE_REGISTER(usb, LOG_LEVEL_DBG); #define GS_USB_CLASS_INSTANCE_NAME "gs_usb_0" -#ifdef CONFIG_USB_DEVICE_STACK_NEXT -#define TEST_BOS_DESC_DEFINE_CAP static -#else /* CONFIG_USB_DEVICE_STACK_NEXT */ -#define TEST_BOS_DESC_DEFINE_CAP USB_DEVICE_BOS_DESC_DEFINE_CAP -#endif /* !CONFIG_USB_DEVICE_STACK_NEXT */ - -TEST_BOS_DESC_DEFINE_CAP const struct usb_bos_capability_lpm bos_cap_lpm = { +static const struct usb_bos_capability_lpm bos_cap_lpm = { .bLength = sizeof(struct usb_bos_capability_lpm), .bDescriptorType = USB_DESC_DEVICE_CAPABILITY, .bDevCapabilityType = USB_BOS_CAPABILITY_EXTENSION, .bmAttributes = 0UL, }; -#ifdef CONFIG_USB_DEVICE_STACK_NEXT - USBD_DEVICE_DEFINE(usbd, DEVICE_DT_GET(DT_NODELABEL(zephyr_udc0)), CONFIG_TEST_USB_VID, CONFIG_TEST_USB_PID); @@ -50,7 +36,7 @@ USBD_CONFIGURATION_DEFINE(hs_config, 0U, CONFIG_TEST_USB_MAX_POWER, &hs_config_d USBD_DESC_BOS_DEFINE(usbext, sizeof(bos_cap_lpm), &bos_cap_lpm); -static int test_usb_init_usbd(void) +int test_usb_init(void) { int err; @@ -148,15 +134,3 @@ static int test_usb_init_usbd(void) return 0; } -#endif /* !CONFIG_USB_DEVICE_STACK_NEXT */ - -int test_usb_init(void) -{ -#ifdef CONFIG_USB_DEVICE_STACK_NEXT - return test_usb_init_usbd(); -#else /* CONFIG_USB_DEVICE_STACK_NEXT */ - usb_bos_register_cap((void *)&bos_cap_lpm); - - return usb_enable(NULL); -#endif /* !CONFIG_USB_DEVICE_STACK_NEXT */ -} diff --git a/tests/subsys/usb/gs_usb/host/testcase.yaml b/tests/subsys/usb/gs_usb/host/testcase.yaml index 040484b..7cc2559 100644 --- a/tests/subsys/usb/gs_usb/host/testcase.yaml +++ b/tests/subsys/usb/gs_usb/host/testcase.yaml @@ -10,14 +10,6 @@ common: pytest_dut_scope: session fixture: usb tests: - usb.gs_usb.legacy.host: - depends_on: - - usb_device - - can - integration_platforms: - - frdm_k64f/mk64f12 - extra_args: - - FILE_SUFFIX=legacy usb.gs_usb.host: depends_on: - usbd