usb_glue_ma35d0.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /**************************************************************************/ /**
  2. *
  3. * @copyright (C) 2020 Nuvoton Technology Corp. All rights reserved.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0
  6. *
  7. * Change Logs:
  8. * Date Author Notes
  9. * 2023-8-8 Wayne First version
  10. *
  11. ******************************************************************************/
  12. #include "rtthread.h"
  13. #include "NuMicro.h"
  14. #include "rthw.h"
  15. #include "drv_sys.h"
  16. #define LOG_TAG "drv.cherry"
  17. #define DBG_ENABLE
  18. #define DBG_SECTION_NAME LOG_TAG
  19. #define DBG_LEVEL DBG_LOG
  20. #define DBG_COLOR
  21. #include <rtdbg.h>
  22. #if defined(PKG_CHERRYUSB_HOST)
  23. #include "usbh_core.h"
  24. static void nu_echi_isr(int vector, void *param)
  25. {
  26. uint8_t busid = (uint8_t)param;
  27. extern void USBH_IRQHandler(uint8_t busid);
  28. USBH_IRQHandler(busid);
  29. }
  30. static void nu_ochi_isr(int vector, void *param)
  31. {
  32. }
  33. void usb_hc_low_level_init(struct usbh_bus *bus)
  34. {
  35. int timeout = 100;
  36. if (bus->hcd.reg_base == HSUSBH0_BASE) {
  37. /* Enable USBH clock */
  38. CLK_EnableModuleClock(HUSBH0_MODULE);
  39. SYS_ResetModule(HSUSBH0_RST);
  40. /* Clock engine clock Configuration */
  41. SYS->USBPMISCR &= ~(SYS_USBPMISCR_PHY0POR_Msk | SYS_USBPMISCR_PHY0COMN_Msk);
  42. rt_thread_mdelay(20);
  43. SYS->USBPMISCR |= SYS_USBPMISCR_PHY0SUSPEND_Msk | SYS_USBPMISCR_PHY0COMN_Msk;
  44. /* set UHOVRCURH(SYS_MISCFCR0[12]) 1 => USBH Host over-current detect is high-active */
  45. /* 0 => USBH Host over-current detect is low-active */
  46. //SYS->MISCFCR0 |= SYS_MISCFCR0_UHOVRCURH_Msk;
  47. SYS->MISCFCR0 &= ~SYS_MISCFCR0_UHOVRCURH_Msk;
  48. while (1) {
  49. rt_thread_mdelay(1);
  50. if ((SYS->USBPMISCR & SYS_USBPMISCR_PHY0HSTCKSTB_Msk) &&)
  51. break; /* both USB PHY0 and PHY1 clock 60MHz UTMI clock stable */
  52. timeout--;
  53. if (timeout == 0) {
  54. rt_kprintf("USB PHY reset failed. USBPMISCR = 0x%08x\n", SYS->USBPMISCR);
  55. return;
  56. }
  57. }
  58. /* Register interrupt service routine. */
  59. rt_hw_interrupt_install(HSUSBH0_IRQn, nu_echi_isr, (void *)bus->hcd.hcd_id, "ehci0");
  60. /* Enable interrupt */
  61. rt_hw_interrupt_umask(HSUSBH0_IRQn);
  62. } else if (bus->hcd.reg_base == HSUSBH1_BASE) {
  63. /* Enable USBH clock */
  64. CLK_EnableModuleClock(HUSBH1_MODULE);
  65. SYS_ResetModule(HSUSBH1_RST);
  66. /* Clock engine clock Configuration */
  67. SYS->USBPMISCR &= ~(SYS_USBPMISCR_PHY1POR_Msk | SYS_USBPMISCR_PHY1COMN_Msk);
  68. rt_thread_mdelay(20);
  69. SYS->USBPMISCR |= SYS_USBPMISCR_PHY1SUSPEND_Msk | SYS_USBPMISCR_PHY1COMN_Msk;
  70. /* set UHOVRCURH(SYS_MISCFCR0[12]) 1 => USBH Host over-current detect is high-active */
  71. /* 0 => USBH Host over-current detect is low-active */
  72. //SYS->MISCFCR0 |= SYS_MISCFCR0_UHOVRCURH_Msk;
  73. SYS->MISCFCR0 &= ~SYS_MISCFCR0_UHOVRCURH_Msk;
  74. while (1) {
  75. rt_thread_mdelay(1);
  76. if ((SYS->USBPMISCR & SYS_USBPMISCR_PHY1HSTCKSTB_Msk))
  77. break; /* both USB PHY0 and PHY1 clock 60MHz UTMI clock stable */
  78. timeout--;
  79. if (timeout == 0) {
  80. rt_kprintf("USB PHY reset failed. USBPMISCR = 0x%08x\n", SYS->USBPMISCR);
  81. return;
  82. }
  83. }
  84. /* Register interrupt service routine. */
  85. rt_hw_interrupt_install(HSUSBH1_IRQn, nu_echi_isr, (void *)bus->hcd.hcd_id, "ehci1");
  86. /* Enable interrupt */
  87. rt_hw_interrupt_umask(HSUSBH1_IRQn);
  88. }
  89. }
  90. void usb_hc_low_level2_init(struct usbh_bus *bus)
  91. {
  92. }
  93. uint8_t usbh_get_port_speed(struct usbh_bus *bus, const uint8_t port)
  94. {
  95. return USB_SPEED_HIGH;
  96. }
  97. #endif