usb_glue_gd.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Copyright (c) 2024, sakumisu
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include "usb_config.h"
  7. #include "stdint.h"
  8. #include "usb_dwc2_reg.h"
  9. #if 1
  10. #error you need to modify some usb register values then use this chip
  11. #endif
  12. #if CONFIG_USBDEV_EP_NUM != 4 && CONFIG_USBDEV_EP_NUM != 6
  13. #error "gd32 only has 4 endpoints for pa11/pa12 and 6 endpoints for pb14/pb15"
  14. #endif
  15. /* you can find this config in function:usb_core_init, file:drv_usb_core.c, for example:
  16. *
  17. * usb_regs->gr->GCCFG |= GCCFG_PWRON | GCCFG_VBUSACEN | GCCFG_VBUSBCEN;
  18. *
  19. */
  20. uint32_t usbd_get_dwc2_gccfg_conf(uint32_t reg_base)
  21. {
  22. #ifdef CONFIG_USB_HS
  23. return 0;
  24. #else
  25. return ((1 << 16) | (1 << 18) | (1 << 19) | (1 << 21));
  26. #endif
  27. }
  28. uint32_t usbh_get_dwc2_gccfg_conf(uint32_t reg_base)
  29. {
  30. #ifdef CONFIG_USB_HS
  31. return 0;
  32. #else
  33. return ((1 << 16) | (1 << 18) | (1 << 19) | (1 << 21));
  34. #endif
  35. }
  36. extern uint32_t SystemCoreClock;
  37. void usbd_dwc2_delay_ms(uint8_t ms)
  38. {
  39. uint32_t count = SystemCoreClock / 1000 * ms;
  40. while (count--) {
  41. __asm volatile("nop");
  42. }
  43. }