Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat(Other): Enable USB support for Zephyr by adding MAXUSB #1299

Merged
merged 3 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/scripts/zephyr-hal.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}
Expand Down
3 changes: 3 additions & 0 deletions Libraries/MAXUSB/include/core/usb_protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 2 additions & 0 deletions Libraries/MAXUSB/src/core/musbhsfc/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 18 additions & 0 deletions Libraries/zephyr/MAX/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading