From 1b95c3c0d3cedfa086518f2c628723007cac838d Mon Sep 17 00:00:00 2001 From: Furkan AKKIZ <94184469+hfakkiz@users.noreply.github.com> Date: Tue, 17 Dec 2024 01:58:41 +0300 Subject: [PATCH] feat(Other): Enable USB support for Zephyr by adding MAXUSB (#1299) Signed-off-by: Furkan Akkiz --- .github/workflows/scripts/zephyr-hal.sh | 10 ++++++++++ Libraries/MAXUSB/include/core/usb_protocol.h | 3 +++ Libraries/MAXUSB/src/core/musbhsfc/usb.c | 2 ++ Libraries/zephyr/MAX/CMakeLists.txt | 18 ++++++++++++++++++ 4 files changed, 33 insertions(+) diff --git a/.github/workflows/scripts/zephyr-hal.sh b/.github/workflows/scripts/zephyr-hal.sh index 42b212ab5b..8e37ec2282 100644 --- a/.github/workflows/scripts/zephyr-hal.sh +++ b/.github/workflows/scripts/zephyr-hal.sh @@ -25,6 +25,8 @@ rm -rf ${hal_adi}/MAX/ # Create parent folder mkdir -p ${hal_adi}/MAX/Libraries/CMSIS +mkdir -p ${hal_adi}/MAX/Libraries/MAXUSB/include +mkdir -p ${hal_adi}/MAX/Libraries/MAXUSB/src mkdir -p ${hal_adi}/MAX/Libraries/PeriphDrivers # Copy zephyr wrappers, system files and cmakefiles @@ -38,11 +40,19 @@ cp -rf ${msdk}/Libraries/CMSIS/Include ${hal_adi}/MAX/Libraries/CMSIS/ cp -rf ${msdk}/Libraries/PeriphDrivers/Include ${hal_adi}/MAX/Libraries/PeriphDrivers/ cp -rf ${msdk}/Libraries/PeriphDrivers/Source ${hal_adi}/MAX/Libraries/PeriphDrivers/ +# Copy MAXUSB folder +cp -rf ${msdk}/Libraries/MAXUSB/include/core ${hal_adi}/MAX/Libraries/MAXUSB/include/ +cp -rf ${msdk}/Libraries/MAXUSB/src/core ${hal_adi}/MAX/Libraries/MAXUSB/src/ + # Remove unneeded files rm -rf ${hal_adi}/MAX/Libraries/CMSIS/Device/Maxim/GCC rm -rf ${hal_adi}/MAX/Libraries/CMSIS/Device/Maxim/MAX*/Source/IAR rm -rf ${hal_adi}/MAX/Libraries/CMSIS/Device/Maxim/MAX*/Source/GCC rm -rf ${hal_adi}/MAX/Libraries/CMSIS/Device/Maxim/MAX*/Source/ARM +rm -rf ${hal_adi}/MAX/Libraries/MAXUSB/include/core/arm +rm -rf ${hal_adi}/MAX/Libraries/MAXUSB/include/core/maxq +rm -rf ${hal_adi}/MAX/Libraries/MAXUSB/src/core/arm +rm -rf ${hal_adi}/MAX/Libraries/MAXUSB/src/core/maxq # Check either dirty or clean cd ${hal_adi} diff --git a/Libraries/MAXUSB/include/core/usb_protocol.h b/Libraries/MAXUSB/include/core/usb_protocol.h index 58fd33c89b..d1533d2689 100644 --- a/Libraries/MAXUSB/include/core/usb_protocol.h +++ b/Libraries/MAXUSB/include/core/usb_protocol.h @@ -149,7 +149,10 @@ typedef __packed struct { } MXC_USB_interface_descriptor_t; #define USB_EP_NUM_MASK 0x0F + +#ifndef USE_ZEPHYR_USB_STACK #define USB_EP_DIR_MASK 0x80 +#endif #if defined(__GNUC__) typedef struct __attribute__((packed)) { diff --git a/Libraries/MAXUSB/src/core/musbhsfc/usb.c b/Libraries/MAXUSB/src/core/musbhsfc/usb.c index e61a4b687d..ef6b099b4f 100644 --- a/Libraries/MAXUSB/src/core/musbhsfc/usb.c +++ b/Libraries/MAXUSB/src/core/musbhsfc/usb.c @@ -941,7 +941,9 @@ int MXC_USB_GetSetup(MXC_USB_SetupPkt *sud) /* Check for follow-on data and advance state machine */ if (sud->wLength > 0) { +#ifndef USE_ZEPHYR_USB_STACK MXC_USBHS->csr0 |= MXC_F_USBHS_CSR0_SERV_OUTPKTRDY; +#endif /* Determine if IN or OUT data follows */ if (sud->bmRequestType & RT_DEV_TO_HOST) { setup_phase = SETUP_DATA_IN; diff --git a/Libraries/zephyr/MAX/CMakeLists.txt b/Libraries/zephyr/MAX/CMakeLists.txt index 717feffc14..4c00577044 100644 --- a/Libraries/zephyr/MAX/CMakeLists.txt +++ b/Libraries/zephyr/MAX/CMakeLists.txt @@ -46,6 +46,24 @@ zephyr_include_directories( ${MSDK_PERIPH_INC_DIR} ) +if (CONFIG_UDC_MAX32) + zephyr_compile_definitions( + -DUSE_ZEPHYR_USB_STACK=1 + ) + + set(MSDK_MAXUSB_DIR ${MSDK_LIBRARY_DIR}/MAXUSB) + + zephyr_include_directories( + ${MSDK_MAXUSB_DIR}/include/core + ${MSDK_MAXUSB_DIR}/include/core/musbhsfc + ) + + zephyr_library_sources( + ${MSDK_MAXUSB_DIR}/src/core/usb_event.c + ${MSDK_MAXUSB_DIR}/src/core/musbhsfc/usb.c + ) +endif() + add_subdirectory_ifdef(CONFIG_SOC_MAX32520 Source/MAX32520) add_subdirectory_ifdef(CONFIG_SOC_MAX32570 Source/MAX32570) add_subdirectory_ifdef(CONFIG_SOC_MAX32572 Source/MAX32572)