From 8d7561837ca61cc3c56d365241070da35c77633b Mon Sep 17 00:00:00 2001 From: Furkan Akkiz Date: Mon, 16 Dec 2024 14:06:57 +0300 Subject: [PATCH 1/3] ci(workflow): Copy related MAXUSB files to hal_adi This commit adds some of MAXUSB files to hal_adi to enable USB support for Zephyr. Zephyr has its own USB stack because of that not included stack related files only included core related files to hal_adi. Signed-off-by: Furkan Akkiz --- .github/workflows/scripts/zephyr-hal.sh | 10 ++++++++++ 1 file changed, 10 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} From 6f6882766275024ab6f3f7178caa2a5217c639d6 Mon Sep 17 00:00:00 2001 From: Furkan Akkiz Date: Mon, 16 Dec 2024 10:10:46 +0300 Subject: [PATCH 2/3] Add MAXUSB to Zephyr directories This commit adds some parts of MAXUSB library to Zephyr directories if Zephyr USB stack is used. Signed-off-by: Furkan Akkiz --- Libraries/zephyr/MAX/CMakeLists.txt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Libraries/zephyr/MAX/CMakeLists.txt b/Libraries/zephyr/MAX/CMakeLists.txt index 717feffc14..28be8dfc31 100644 --- a/Libraries/zephyr/MAX/CMakeLists.txt +++ b/Libraries/zephyr/MAX/CMakeLists.txt @@ -46,6 +46,20 @@ zephyr_include_directories( ${MSDK_PERIPH_INC_DIR} ) +if (CONFIG_UDC_MAX32) + 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) From 4f8d65e024074aefe35e5df619fdd5a8f9671da7 Mon Sep 17 00:00:00 2001 From: Furkan Akkiz Date: Mon, 16 Dec 2024 10:23:44 +0300 Subject: [PATCH 3/3] Add 'USE_ZEPHYR_USB_STACK' flag This commit adds 'USE_ZEPHYR_USB_STACK' flag to handle differences between MSDK USB and Zephyr USB. Disabled given line in 'usb.c' file with using 'USE_ZEPHYR_USB_STACK' flag for Zephyr USB stack because this line causes a race condition for Zephyr USB. I added this line to 'udc_max32.c' file of Zephyr repo to handle race condition problem. Disabled given line in 'usb_protocol.h' file because this line causes a 'redefined' warning for Zephyr USB stack. Signed-off-by: Furkan Akkiz --- Libraries/MAXUSB/include/core/usb_protocol.h | 3 +++ Libraries/MAXUSB/src/core/musbhsfc/usb.c | 2 ++ Libraries/zephyr/MAX/CMakeLists.txt | 4 ++++ 3 files changed, 9 insertions(+) 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 28be8dfc31..4c00577044 100644 --- a/Libraries/zephyr/MAX/CMakeLists.txt +++ b/Libraries/zephyr/MAX/CMakeLists.txt @@ -47,6 +47,10 @@ zephyr_include_directories( ) if (CONFIG_UDC_MAX32) + zephyr_compile_definitions( + -DUSE_ZEPHYR_USB_STACK=1 + ) + set(MSDK_MAXUSB_DIR ${MSDK_LIBRARY_DIR}/MAXUSB) zephyr_include_directories(