drv_tinyusb.c 1000 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2021-10-20 tfx2001 first version
  9. */
  10. #ifdef PKG_USING_TINYUSB
  11. #include <tusb.h>
  12. #include <drv_config.h>
  13. int tusb_board_init(void)
  14. {
  15. PCD_HandleTypeDef hpcd;
  16. memset(&hpcd, 0, sizeof(hpcd));
  17. /* Set LL Driver parameters */
  18. hpcd.Instance = USBD_INSTANCE;
  19. hpcd.Init.dev_endpoints = 8;
  20. hpcd.Init.speed = USBD_PCD_SPEED;
  21. #if defined(SOC_SERIES_STM32F3) || defined(SOC_SERIES_STM32F4)
  22. hpcd.Init.ep0_mps = EP_MPS_64;
  23. #else
  24. hpcd.Init.ep0_mps = DEP0CTL_MPS_64;
  25. #endif
  26. #if !defined(SOC_SERIES_STM32F1)
  27. hpcd.Init.phy_itface = USBD_PCD_PHY_MODULE;
  28. #endif
  29. /* Initialize LL Driver */
  30. HAL_PCD_Init(&hpcd);
  31. /* USB interrupt Init */
  32. HAL_NVIC_SetPriority(USBD_IRQ_TYPE, 2, 0);
  33. HAL_NVIC_EnableIRQ(USBD_IRQ_TYPE);
  34. return 0;
  35. }
  36. void USBD_IRQ_HANDLER(void)
  37. {
  38. tud_int_handler(0);
  39. }
  40. #endif