summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsakumisu <[email protected]>2025-05-15 16:08:25 +0800
committersakumisu <[email protected]>2025-05-15 17:23:35 +0800
commiteadcf7530b66262c62cb8a3867ff582587ddfbb0 (patch)
tree7f329c1b7d9e56c6dab8a8633dcae56335b488e0
parent43692c0ba20ae62948da8cb438a3c64aa57ce31c (diff)
refacor(port/hpmicro): move hpmicro glue into hpmicro directory
Signed-off-by: sakumisu <[email protected]>
-rw-r--r--CMakeLists.txt16
-rw-r--r--SConscript6
-rw-r--r--cherryusb.cmake6
-rw-r--r--port/ehci/README.md8
-rw-r--r--port/hpmicro/README.md5
-rw-r--r--port/hpmicro/usb_dc_hpm.c (renamed from port/hpm/usb_dc_hpm.c)76
-rw-r--r--port/hpmicro/usb_glue_hpm.c25
-rw-r--r--port/hpmicro/usb_hc_hpm.c (renamed from port/ehci/usb_glue_hpm.c)63
8 files changed, 129 insertions, 76 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9bad52e6..a181def9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3,6 +3,8 @@ cmake_minimum_required(VERSION 3.15)
if(CONFIG_CHERRYUSB)
if(BL_SDK_BASE)
+ message(STATUS "enable cherryusb in bouffalo_sdk")
+
set(CONFIG_CHERRYUSB_DEVICE_CDC_ACM 1)
set(CONFIG_CHERRYUSB_DEVICE_HID 1)
set(CONFIG_CHERRYUSB_DEVICE_MSC 1)
@@ -30,16 +32,22 @@ if(BL_SDK_BASE)
set(CONFIG_CHERRYUSB_OSAL "freertos")
include(${CMAKE_CURRENT_LIST_DIR}/cherryusb.cmake)
+ list(REMOVE_DUPLICATES cherryusb_srcs)
+ list(REMOVE_DUPLICATES cherryusb_incs)
sdk_generate_library(cherryusb)
sdk_add_include_directories(${cherryusb_incs})
sdk_library_add_sources(${cherryusb_srcs})
elseif(ESP_PLATFORM)
+ message(STATUS "enable cherryusb in esp-idf")
+
set(CONFIG_CHERRYUSB_DEVICE_DWC2_ESP 1)
set(CONFIG_CHERRYUSB_HOST_DWC2_ESP 1)
set(CONFIG_CHERRYUSB_OSAL "idf")
include(${CMAKE_CURRENT_LIST_DIR}/cherryusb.cmake)
+ list(REMOVE_DUPLICATES cherryusb_srcs)
+ list(REMOVE_DUPLICATES cherryusb_incs)
set(ldfragments "osal/idf/linker.lf")
@@ -130,8 +138,12 @@ elseif(ESP_PLATFORM)
set_source_files_properties("class/audio/usbd_audio.c" PROPERTIES COMPILE_FLAGS -Wno-maybe-uninitialized)
endif()
elseif(ZEPHYR_BASE)
+ message(STATUS "enable cherryusb in zephyr")
+
set(CONFIG_CHERRYUSB_OSAL "zephyr")
include(${CMAKE_CURRENT_LIST_DIR}/cherryusb.cmake)
+ list(REMOVE_DUPLICATES cherryusb_srcs)
+ list(REMOVE_DUPLICATES cherryusb_incs)
if (CONFIG_SHELL)
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/platform/zephyr/usb_cmd.c)
@@ -149,6 +161,8 @@ elseif(ZEPHYR_BASE)
zephyr_linker_sources(SECTIONS zephyr/usbh_class_info.ld)
endif()
elseif(HPM_SDK_BASE)
+ message(STATUS "enable cherryusb in hpm_sdk")
+
set(CONFIG_CHERRYUSB_DEVICE_CDC_ACM 1)
set(CONFIG_CHERRYUSB_DEVICE_HID 1)
set(CONFIG_CHERRYUSB_DEVICE_MSC 1)
@@ -177,6 +191,8 @@ elseif(HPM_SDK_BASE)
set(CONFIG_CHERRYUSB_OSAL "freertos")
include(${CMAKE_CURRENT_LIST_DIR}/cherryusb.cmake)
+ list(REMOVE_DUPLICATES cherryusb_srcs)
+ list(REMOVE_DUPLICATES cherryusb_incs)
sdk_inc(${cherryusb_incs})
sdk_src(${cherryusb_srcs})
diff --git a/SConscript b/SConscript
index 93730091..ff70d0e5 100644
--- a/SConscript
+++ b/SConscript
@@ -85,7 +85,8 @@ if GetDepend(['PKG_CHERRYUSB_DEVICE']):
if GetDepend(['PKG_CHERRYUSB_DEVICE_BL']):
src += Glob('port/bouffalolab/usb_dc_bl.c')
if GetDepend(['PKG_CHERRYUSB_DEVICE_HPM']):
- src += Glob('port/hpm/usb_dc_hpm.c')
+ src += Glob('port/hpmicro/usb_dc_hpm.c')
+ src += Glob('port/hpmicro/usb_glue_hpm.c')
if GetDepend(['PKG_CHERRYUSB_DEVICE_AIC']):
src += Glob('port/aic/usb_dc_aic.c')
src += Glob('port/aic/usb_dc_aic_ll.c')
@@ -169,7 +170,8 @@ if GetDepend(['PKG_CHERRYUSB_HOST']):
src += Glob('port/ehci/usb_glue_bouffalo.c')
if GetDepend(['PKG_CHERRYUSB_HOST_EHCI_HPM']):
src += Glob('port/ehci/usb_hc_ehci.c')
- src += Glob('port/ehci/usb_glue_hpm.c')
+ src += Glob('port/hpmicro/usb_hc_hpm.c')
+ src += Glob('port/hpmicro/usb_glue_hpm.c')
if GetDepend(['PKG_CHERRYUSB_HOST_EHCI_AIC']):
path += [cwd + '/port/ehci']
path += [cwd + '/port/ohci']
diff --git a/cherryusb.cmake b/cherryusb.cmake
index 443aed95..bc4e96b0 100644
--- a/cherryusb.cmake
+++ b/cherryusb.cmake
@@ -131,7 +131,8 @@ if(CONFIG_CHERRYUSB_DEVICE)
elseif(CONFIG_CHERRYUSB_DEVICE_CHIPIDEA_CUSTOM)
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/chipidea/usb_dc_chipidea.c)
elseif(CONFIG_CHERRYUSB_DEVICE_HPM)
- list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/hpm/usb_dc_hpm.c)
+ list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/hpmicro/usb_dc_hpm.c)
+ list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/hpmicro/usb_glue_hpm.c)
elseif(CONFIG_CHERRYUSB_DEVICE_BL)
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/bouffalolab/usb_dc_bl.c)
elseif(CONFIG_CHERRYUSB_DEVICE_AIC)
@@ -264,7 +265,8 @@ if(CONFIG_CHERRYUSB_HOST)
elseif(CONFIG_CHERRYUSB_HOST_EHCI_HPM)
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/ehci/usb_hc_ehci.c)
# list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/ehci/usb_hc_ehci_iso.c)
- list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/ehci/usb_glue_hpm.c)
+ list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/hpmicro/usb_hc_hpm.c)
+ list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/hpmicro/usb_glue_hpm.c)
list(APPEND cherryusb_incs ${CMAKE_CURRENT_LIST_DIR}/port/ehci)
elseif(CONFIG_CHERRYUSB_HOST_EHCI_AIC)
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/ehci/usb_hc_ehci.c)
diff --git a/port/ehci/README.md b/port/ehci/README.md
index ede4cab8..753fc446 100644
--- a/port/ehci/README.md
+++ b/port/ehci/README.md
@@ -4,11 +4,11 @@
### BouffaloLab
-- BouffaloLab BL616/BL808
+- BouffaloLab BL616/BL808 (bouffalolab + EHCI)
### HPMicro
-- HPM all series
+- HPM all series (hpmicro + EHCI)
### AllwinnerTech
@@ -30,8 +30,8 @@ Modify USB_NOCACHE_RAM_SECTION
#define USB_NOCACHE_RAM_SECTION __attribute__((section(".NonCacheable")))
```
-- IMRT10XX/IMRT11XX
-- MCXN9XX/MCXN236
+- IMRT10XX/IMRT11XX (chipidea + EHCI)
+- MCXN9XX/MCXN236 (chipidea + EHCI)
### Intel
diff --git a/port/hpmicro/README.md b/port/hpmicro/README.md
new file mode 100644
index 00000000..ec159f2a
--- /dev/null
+++ b/port/hpmicro/README.md
@@ -0,0 +1,5 @@
+# Note
+
+## Support Chip List
+
+- HPM all series (hpmicro + EHCI)
diff --git a/port/hpm/usb_dc_hpm.c b/port/hpmicro/usb_dc_hpm.c
index 011e193c..0c6c143d 100644
--- a/port/hpm/usb_dc_hpm.c
+++ b/port/hpmicro/usb_dc_hpm.c
@@ -47,8 +47,9 @@ struct hpm_udc {
static USB_NOCACHE_RAM_SECTION ATTR_ALIGN(USB_SOC_DCD_DATA_RAM_ADDRESS_ALIGNMENT)
uint8_t _dcd_data[CONFIG_USBDEV_MAX_BUS][HPM_ALIGN_UP(sizeof(dcd_data_t), USB_SOC_DCD_DATA_RAM_ADDRESS_ALIGNMENT)];
static USB_NOCACHE_RAM_SECTION usb_device_handle_t usb_device_handle[CONFIG_USBDEV_MAX_BUS];
-static uint32_t _dcd_irqnum[CONFIG_USBDEV_MAX_BUS];
-static uint8_t _dcd_busid[CONFIG_USBDEV_MAX_BUS];
+
+extern void (*g_usb_hpm_irq[2])(uint8_t busid);
+extern uint8_t g_usb_hpm_busid[2];
/* Index to bit position in register */
static inline uint8_t ep_idx2bit(uint8_t ep_idx)
@@ -61,24 +62,48 @@ void usbd_execute_test_mode(uint8_t busid, uint8_t test_mode)
usb_set_port_test_mode(g_hpm_udc[busid].handle->regs, test_mode);
}
-int usb_dc_init(uint8_t busid)
+void usb_dc_low_level_init(uint8_t busid)
{
- memset(&g_hpm_udc[busid], 0, sizeof(struct hpm_udc));
- g_hpm_udc[busid].handle = &usb_device_handle[busid];
- g_hpm_udc[busid].handle->regs = (USB_Type *)g_usbdev_bus[busid].reg_base;
- g_hpm_udc[busid].handle->dcd_data = (dcd_data_t *)&_dcd_data[busid][0];
+ if (g_usbdev_bus[busid].reg_base == HPM_USB0_BASE) {
+ g_usb_hpm_busid[0] = busid;
+ g_usb_hpm_irq[0] = USBD_IRQHandler;
+ intc_m_enable_irq(IRQn_USB0);
+ } else {
+#ifdef HPM_USB1_BASE
+ g_usb_hpm_busid[1] = busid;
+ g_usb_hpm_irq[1] = USBD_IRQHandler;
+
+ intc_m_enable_irq(IRQn_USB1);
+#endif
+ }
+}
+
+void usb_dc_low_level_deinit(uint8_t busid)
+{
if (g_usbdev_bus[busid].reg_base == HPM_USB0_BASE) {
- _dcd_irqnum[busid] = IRQn_USB0;
- _dcd_busid[0] = busid;
+ intc_m_disable_irq(IRQn_USB0);
+
+ g_usb_hpm_busid[0] = 0;
+ g_usb_hpm_irq[0] = NULL;
} else {
#ifdef HPM_USB1_BASE
- if (g_usbdev_bus[busid].reg_base == HPM_USB1_BASE) {
- _dcd_irqnum[busid] = IRQn_USB1;
- _dcd_busid[1] = busid;
- }
+ intc_m_disable_irq(IRQn_USB1);
+
+ g_usb_hpm_busid[1] = 0;
+ g_usb_hpm_irq[1] = NULL;
#endif
}
+}
+
+int usb_dc_init(uint8_t busid)
+{
+ usb_dc_low_level_init(busid);
+
+ memset(&g_hpm_udc[busid], 0, sizeof(struct hpm_udc));
+ g_hpm_udc[busid].handle = &usb_device_handle[busid];
+ g_hpm_udc[busid].handle->regs = (USB_Type *)g_usbdev_bus[busid].reg_base;
+ g_hpm_udc[busid].handle->dcd_data = (dcd_data_t *)&_dcd_data[busid][0];
uint32_t int_mask;
int_mask = (intr_usb | intr_error |intr_port_change | intr_reset | intr_suspend);
@@ -88,16 +113,13 @@ int usb_dc_init(uint8_t busid)
#endif
usb_device_init(g_hpm_udc[busid].handle, int_mask);
-
- intc_m_enable_irq(_dcd_irqnum[busid]);
return 0;
}
int usb_dc_deinit(uint8_t busid)
{
- intc_m_disable_irq(_dcd_irqnum[busid]);
-
usb_device_deinit(g_hpm_udc[busid].handle);
+ usb_dc_low_level_deinit(busid);
return 0;
}
@@ -356,22 +378,4 @@ void USBD_IRQHandler(uint8_t busid)
usbd_event_ep0_setup_complete_handler(busid, (uint8_t *)&qhd0->setup_request);
}
}
-}
-
-#if !defined(USBD_USE_CUSTOM_ISR) || !USBD_USE_CUSTOM_ISR
-
-SDK_DECLARE_EXT_ISR_M(IRQn_USB0, isr_usbd0)
-void isr_usbd0(void)
-{
- USBD_IRQHandler(_dcd_busid[0]);
-}
-
-#ifdef HPM_USB1_BASE
-SDK_DECLARE_EXT_ISR_M(IRQn_USB1, isr_usbd1)
-void isr_usbd1(void)
-{
- USBD_IRQHandler(_dcd_busid[1]);
-}
-#endif
-
-#endif
+} \ No newline at end of file
diff --git a/port/hpmicro/usb_glue_hpm.c b/port/hpmicro/usb_glue_hpm.c
new file mode 100644
index 00000000..5605eb13
--- /dev/null
+++ b/port/hpmicro/usb_glue_hpm.c
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2022-2025 HPMicro
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+#include "hpm_common.h"
+#include "hpm_soc.h"
+
+void (*g_usb_hpm_irq[2])(uint8_t busid);
+uint8_t g_usb_hpm_busid[2] = { 0, 0 };
+
+SDK_DECLARE_EXT_ISR_M(IRQn_USB0, isr_usbh0)
+void isr_usbh0(void)
+{
+ g_usb_hpm_irq[0](g_usb_hpm_busid[0]);
+}
+
+#ifdef HPM_USB1_BASE
+SDK_DECLARE_EXT_ISR_M(IRQn_USB1, isr_usbh1)
+void isr_usbh1(void)
+{
+ g_usb_hpm_irq[1](g_usb_hpm_busid[1]);
+}
+#endif \ No newline at end of file
diff --git a/port/ehci/usb_glue_hpm.c b/port/hpmicro/usb_hc_hpm.c
index 40105a94..94515fb7 100644
--- a/port/ehci/usb_glue_hpm.c
+++ b/port/hpmicro/usb_hc_hpm.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022-2024 HPMicro
+ * Copyright (c) 2022-2025 HPMicro
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -17,8 +17,8 @@
#error "hpm ehci must config CONFIG_USB_EHCI_HCCR_OFFSET to 0x100"
#endif
-static uint32_t _hcd_irqnum[CONFIG_USBHOST_MAX_BUS];
-static uint8_t _hcd_busid[CONFIG_USBHOST_MAX_BUS];
+extern void (*g_usb_hpm_irq[2])(uint8_t busid);
+extern uint8_t g_usb_hpm_busid[2];
static void usb_host_mode_init(USB_Type *ptr)
{
@@ -47,19 +47,19 @@ static void usb_host_mode_init(USB_Type *ptr)
void usb_hc_low_level_init(struct usbh_bus *bus)
{
if (bus->hcd.reg_base == HPM_USB0_BASE) {
- _hcd_irqnum[bus->hcd.hcd_id] = IRQn_USB0;
- _hcd_busid[0] = bus->hcd.hcd_id;
+ g_usb_hpm_busid[0] = bus->hcd.hcd_id;
+ g_usb_hpm_irq[0] = USBH_IRQHandler;
+
+ intc_m_enable_irq(IRQn_USB0);
} else {
#ifdef HPM_USB1_BASE
- if (bus->hcd.reg_base == HPM_USB1_BASE) {
- _hcd_irqnum[bus->hcd.hcd_id] = IRQn_USB1;
- _hcd_busid[1] = bus->hcd.hcd_id;
- }
+ g_usb_hpm_busid[1] = bus->hcd.hcd_id;
+ g_usb_hpm_irq[1] = USBH_IRQHandler;
+
+ intc_m_enable_irq(IRQn_USB1);
#endif
}
-
usb_phy_init((USB_Type *)(bus->hcd.reg_base), true);
- intc_m_enable_irq(_hcd_irqnum[bus->hcd.hcd_id]);
}
void usb_hc_low_level2_init(struct usbh_bus *bus)
@@ -67,6 +67,25 @@ void usb_hc_low_level2_init(struct usbh_bus *bus)
usb_host_mode_init((USB_Type *)(bus->hcd.reg_base));
}
+void usb_hc_low_level_deinit(struct usbh_bus *bus)
+{
+ usb_phy_deinit((USB_Type *)(bus->hcd.reg_base));
+
+ if (bus->hcd.reg_base == HPM_USB0_BASE) {
+ intc_m_disable_irq(IRQn_USB0);
+
+ g_usb_hpm_busid[0] = 0;
+ g_usb_hpm_irq[0] = NULL;
+ } else {
+#ifdef HPM_USB1_BASE
+ intc_m_disable_irq(IRQn_USB1);
+
+ g_usb_hpm_busid[1] = 0;
+ g_usb_hpm_irq[1] = NULL;
+#endif
+ }
+}
+
uint8_t usbh_get_port_speed(struct usbh_bus *bus, const uint8_t port)
{
(void)port;
@@ -85,24 +104,4 @@ uint8_t usbh_get_port_speed(struct usbh_bus *bus, const uint8_t port)
}
return 0;
-}
-
-#if !defined(USBH_USE_CUSTOM_ISR) || !USBH_USE_CUSTOM_ISR
-
-extern void USBH_IRQHandler(uint8_t busid);
-
-SDK_DECLARE_EXT_ISR_M(IRQn_USB0, isr_usbh0)
-void isr_usbh0(void)
-{
- USBH_IRQHandler(_hcd_busid[0]);
-}
-
-#ifdef HPM_USB1_BASE
-SDK_DECLARE_EXT_ISR_M(IRQn_USB1, isr_usbh1)
-void isr_usbh1(void)
-{
- USBH_IRQHandler(_hcd_busid[1]);
-}
-#endif
-
-#endif
+} \ No newline at end of file