summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhihong Chen <[email protected]>2025-05-16 18:08:04 +0800
committersakumisu <[email protected]>2025-05-19 14:56:39 +0800
commit7465a59eaa980545701d32ef7f1bf09f76b7f4ce (patch)
treec34f4f048f6161ac4189f23cece163c843d56d60
parente301e1f0a961a00495519ceee8d0b3ec2ba1e77d (diff)
[update] port: hpmicro: update port files
Signed-off-by: Zhihong Chen <[email protected]>
-rw-r--r--cherryusb.cmake2
-rw-r--r--port/ehci/usb_hc_ehci.c4
-rw-r--r--port/hpmicro/README.md2
-rw-r--r--port/hpmicro/usb_dc_hpm.c34
-rw-r--r--port/hpmicro/usb_glue_hpm.c36
-rw-r--r--port/hpmicro/usb_glue_hpm.h19
-rw-r--r--port/hpmicro/usb_hc_hpm.c22
7 files changed, 84 insertions, 35 deletions
diff --git a/cherryusb.cmake b/cherryusb.cmake
index 31153a52..15e040e4 100644
--- a/cherryusb.cmake
+++ b/cherryusb.cmake
@@ -135,6 +135,7 @@ if(CONFIG_CHERRYUSB_DEVICE)
elseif(CONFIG_CHERRYUSB_DEVICE_HPM)
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)
+ list(APPEND cherryusb_incs ${CMAKE_CURRENT_LIST_DIR}/port/hpmicro)
elseif(CONFIG_CHERRYUSB_DEVICE_BL)
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/bouffalolab/usb_dc_bl.c)
elseif(CONFIG_CHERRYUSB_DEVICE_AIC)
@@ -269,6 +270,7 @@ if(CONFIG_CHERRYUSB_HOST)
# list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/ehci/usb_hc_ehci_iso.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/hpmicro)
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/usb_hc_ehci.c b/port/ehci/usb_hc_ehci.c
index 3fee1c3f..2b61812e 100644
--- a/port/ehci/usb_hc_ehci.c
+++ b/port/ehci/usb_hc_ehci.c
@@ -852,11 +852,11 @@ int usb_hc_init(struct usbh_bus *bus)
}
}
- usb_hc_low_level2_init(bus);
-
EHCI_HCOR->usbintr = 0;
EHCI_HCOR->usbsts = EHCI_HCOR->usbsts;
+ usb_hc_low_level2_init(bus);
+
/* Set the Current Asynchronous List Address. */
EHCI_HCOR->asynclistaddr = EHCI_PTR2ADDR(&g_async_qh_head[bus->hcd.hcd_id]);
/* Set the Periodic Frame List Base Address. */
diff --git a/port/hpmicro/README.md b/port/hpmicro/README.md
index ec159f2a..558074dd 100644
--- a/port/hpmicro/README.md
+++ b/port/hpmicro/README.md
@@ -2,4 +2,4 @@
## Support Chip List
-- HPM all series (hpmicro + EHCI)
+- HPM all series (HPMicro + EHCI)
diff --git a/port/hpmicro/usb_dc_hpm.c b/port/hpmicro/usb_dc_hpm.c
index 0c6c143d..6432e2e2 100644
--- a/port/hpmicro/usb_dc_hpm.c
+++ b/port/hpmicro/usb_dc_hpm.c
@@ -6,6 +6,7 @@
*/
#include "usbd_core.h"
#include "hpm_usb_device.h"
+#include "usb_glue_hpm.h"
#ifndef USB_NUM_BIDIR_ENDPOINTS
#define USB_NUM_BIDIR_ENDPOINTS CONFIG_USBDEV_EP_NUM
@@ -48,47 +49,39 @@ 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];
-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)
{
return ep_idx / 2 + ((ep_idx % 2) ? 16 : 0);
}
-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);
-}
-
-void usb_dc_low_level_init(uint8_t busid)
+static void usb_dc_isr_connect(uint8_t busid)
{
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);
+ hpm_usb_isr_enable(HPM_USB0_BASE);
} else {
#ifdef HPM_USB1_BASE
g_usb_hpm_busid[1] = busid;
g_usb_hpm_irq[1] = USBD_IRQHandler;
- intc_m_enable_irq(IRQn_USB1);
+ hpm_usb_isr_enable(HPM_USB1_BASE);
#endif
}
}
-void usb_dc_low_level_deinit(uint8_t busid)
+static void usb_dc_isr_disconnect(uint8_t busid)
{
if (g_usbdev_bus[busid].reg_base == HPM_USB0_BASE) {
- intc_m_disable_irq(IRQn_USB0);
+ hpm_usb_isr_disable(HPM_USB0_BASE);
g_usb_hpm_busid[0] = 0;
g_usb_hpm_irq[0] = NULL;
} else {
#ifdef HPM_USB1_BASE
- intc_m_disable_irq(IRQn_USB1);
+ hpm_usb_isr_disable(HPM_USB1_BASE);
g_usb_hpm_busid[1] = 0;
g_usb_hpm_irq[1] = NULL;
@@ -98,8 +91,6 @@ void usb_dc_low_level_deinit(uint8_t busid)
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;
@@ -113,13 +104,17 @@ int usb_dc_init(uint8_t busid)
#endif
usb_device_init(g_hpm_udc[busid].handle, int_mask);
+
+ usb_dc_isr_connect(busid);
+
return 0;
}
int usb_dc_deinit(uint8_t busid)
{
+ usb_dc_isr_disconnect(busid);
+
usb_device_deinit(g_hpm_udc[busid].handle);
- usb_dc_low_level_deinit(busid);
return 0;
}
@@ -146,6 +141,11 @@ int usbd_set_remote_wakeup(uint8_t busid)
return 0;
}
+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);
+}
+
uint8_t usbd_get_port_speed(uint8_t busid)
{
uint8_t speed;
diff --git a/port/hpmicro/usb_glue_hpm.c b/port/hpmicro/usb_glue_hpm.c
index 5605eb13..29d6b6fe 100644
--- a/port/hpmicro/usb_glue_hpm.c
+++ b/port/hpmicro/usb_glue_hpm.c
@@ -8,17 +8,43 @@
#include "hpm_soc.h"
void (*g_usb_hpm_irq[2])(uint8_t busid);
-uint8_t g_usb_hpm_busid[2] = { 0, 0 };
+uint8_t g_usb_hpm_busid[2];
-SDK_DECLARE_EXT_ISR_M(IRQn_USB0, isr_usbh0)
-void isr_usbh0(void)
+ATTR_WEAK void hpm_usb_isr_enable(uint32_t base)
+{
+ if (base == HPM_USB0_BASE) {
+ intc_m_enable_irq(IRQn_USB0);
+ } else {
+#ifdef HPM_USB1_BASE
+ intc_m_enable_irq(IRQn_USB1);
+#endif
+ }
+}
+
+ATTR_WEAK void hpm_usb_isr_disable(uint32_t base)
+{
+ if (base == HPM_USB0_BASE) {
+ intc_m_disable_irq(IRQn_USB0);
+ } else {
+#ifdef HPM_USB1_BASE
+ intc_m_disable_irq(IRQn_USB1);
+#endif
+ }
+}
+
+#ifndef CONFIG_CHERRYUSB_CUSTOM_IRQ_HANDLER
+SDK_DECLARE_EXT_ISR_M(IRQn_USB0, hpm_isr_usb0)
+#endif
+void hpm_isr_usb0(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)
+#ifndef CONFIG_CHERRYUSB_CUSTOM_IRQ_HANDLER
+SDK_DECLARE_EXT_ISR_M(IRQn_USB1, hpm_isr_usb1)
+#endif
+void hpm_isr_usb1(void)
{
g_usb_hpm_irq[1](g_usb_hpm_busid[1]);
}
diff --git a/port/hpmicro/usb_glue_hpm.h b/port/hpmicro/usb_glue_hpm.h
new file mode 100644
index 00000000..dea2dd0b
--- /dev/null
+++ b/port/hpmicro/usb_glue_hpm.h
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2022-2025 HPMicro
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#ifndef _HPM_USB_GLUE_HPM_H_
+#define _HPM_USB_GLUE_HPM_H_
+
+extern void (*g_usb_hpm_irq[2])(uint8_t busid);
+extern uint8_t g_usb_hpm_busid[2];
+
+void hpm_usb_isr_enable(uint32_t base);
+void hpm_usb_isr_disable(uint32_t base);
+void hpm_isr_usb0(void);
+void hpm_isr_usb1(void);
+
+#endif /* _HPM_USB_GLUE_HPM_H_ */ \ No newline at end of file
diff --git a/port/hpmicro/usb_hc_hpm.c b/port/hpmicro/usb_hc_hpm.c
index 94515fb7..9ee51500 100644
--- a/port/hpmicro/usb_hc_hpm.c
+++ b/port/hpmicro/usb_hc_hpm.c
@@ -8,6 +8,7 @@
#include "hpm_common.h"
#include "hpm_soc.h"
#include "hpm_usb_drv.h"
+#include "usb_glue_hpm.h"
#if !defined(CONFIG_USB_EHCI_HPMICRO) || !CONFIG_USB_EHCI_HPMICRO
#error "hpm ehci must set CONFIG_USB_EHCI_HPMICRO=1"
@@ -46,25 +47,26 @@ static void usb_host_mode_init(USB_Type *ptr)
void usb_hc_low_level_init(struct usbh_bus *bus)
{
+ usb_phy_init((USB_Type *)(bus->hcd.reg_base), true);
+}
+
+void usb_hc_low_level2_init(struct usbh_bus *bus)
+{
+ usb_host_mode_init((USB_Type *)(bus->hcd.reg_base));
+
if (bus->hcd.reg_base == HPM_USB0_BASE) {
g_usb_hpm_busid[0] = bus->hcd.hcd_id;
g_usb_hpm_irq[0] = USBH_IRQHandler;
- intc_m_enable_irq(IRQn_USB0);
+ hpm_usb_isr_enable(HPM_USB0_BASE);
} else {
#ifdef HPM_USB1_BASE
g_usb_hpm_busid[1] = bus->hcd.hcd_id;
g_usb_hpm_irq[1] = USBH_IRQHandler;
- intc_m_enable_irq(IRQn_USB1);
+ hpm_usb_isr_enable(HPM_USB1_BASE);
#endif
}
- usb_phy_init((USB_Type *)(bus->hcd.reg_base), true);
-}
-
-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)
@@ -72,13 +74,13 @@ 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);
+ hpm_usb_isr_disable(HPM_USB0_BASE);
g_usb_hpm_busid[0] = 0;
g_usb_hpm_irq[0] = NULL;
} else {
#ifdef HPM_USB1_BASE
- intc_m_disable_irq(IRQn_USB1);
+ hpm_usb_isr_disable(HPM_USB1_BASE);
g_usb_hpm_busid[1] = 0;
g_usb_hpm_irq[1] = NULL;