drv_usbd.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  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. * 2020-3-25 Egbert First version
  10. *
  11. ******************************************************************************/
  12. #include <rtconfig.h>
  13. #ifdef BSP_USING_USBD
  14. #include <rtthread.h>
  15. #include <rtdevice.h>
  16. #include <string.h>
  17. #include "NuMicro.h"
  18. #define LOG_TAG "drv.usbd"
  19. #define DBG_ENABLE
  20. #define DBG_SECTION_NAME "drv.usbd"
  21. #define DBG_LEVEL DBG_ERROR
  22. #define DBG_COLOR
  23. #include <rtdbg.h>
  24. /* Private define ---------------------------------------------------------------*/
  25. /* Define EP maximum packet size */
  26. #define EP0_MAX_PKT_SIZE 64
  27. #define EP1_MAX_PKT_SIZE EP0_MAX_PKT_SIZE /* EP0 and EP1 are assigned the same size for control endpoint */
  28. #define EP2_MAX_PKT_SIZE 64
  29. #define EP3_MAX_PKT_SIZE 64
  30. #define EP4_MAX_PKT_SIZE 64
  31. #define EP5_MAX_PKT_SIZE 64
  32. #define EP6_MAX_PKT_SIZE 64
  33. #define EP7_MAX_PKT_SIZE 64
  34. #define EP8_MAX_PKT_SIZE 64
  35. #define EP9_MAX_PKT_SIZE 64
  36. #define SETUP_BUF_BASE 0
  37. #define SETUP_BUF_LEN 8
  38. #define EP0_BUF_BASE (SETUP_BUF_BASE + SETUP_BUF_LEN)
  39. #define EP0_BUF_LEN EP0_MAX_PKT_SIZE
  40. #define EP1_BUF_BASE (SETUP_BUF_BASE + SETUP_BUF_LEN)
  41. #define EP1_BUF_LEN EP1_MAX_PKT_SIZE
  42. #define EP2_BUF_BASE (EP1_BUF_BASE + EP1_BUF_LEN)
  43. #define EP2_BUF_LEN EP2_MAX_PKT_SIZE
  44. #define EP3_BUF_BASE (EP2_BUF_BASE + EP2_BUF_LEN)
  45. #define EP3_BUF_LEN EP3_MAX_PKT_SIZE
  46. #define EP4_BUF_BASE (EP3_BUF_BASE + EP3_BUF_LEN)
  47. #define EP4_BUF_LEN EP4_MAX_PKT_SIZE
  48. #define EP5_BUF_BASE (EP4_BUF_BASE + EP4_BUF_LEN)
  49. #define EP5_BUF_LEN EP5_MAX_PKT_SIZE
  50. #define EP6_BUF_BASE (EP5_BUF_BASE + EP5_BUF_LEN)
  51. #define EP6_BUF_LEN EP6_MAX_PKT_SIZE
  52. #define EP7_BUF_BASE (EP6_BUF_BASE + EP6_BUF_LEN)
  53. #define EP7_BUF_LEN EP7_MAX_PKT_SIZE
  54. #define EP8_BUF_BASE (EP7_BUF_BASE + EP7_BUF_LEN)
  55. #define EP8_BUF_LEN EP8_MAX_PKT_SIZE
  56. #define EP9_BUF_BASE (EP8_BUF_BASE + EP8_BUF_LEN)
  57. #define EP9_BUF_LEN EP9_MAX_PKT_SIZE
  58. #define EPADR_SW2HW(address) ((((address & USB_EPNO_MASK) * 2) + (!(address & USB_DIR_IN))))
  59. #define EPADR_HW2SW(address) ((address & USB_EPNO_MASK) / 2)
  60. /* Private typedef --------------------------------------------------------------*/
  61. typedef struct _nu_usbd_t
  62. {
  63. USBD_T *Instance; /* REG base */
  64. uint8_t address_tmp; /* Keep assigned address for flow control */
  65. } nu_usbd_t;
  66. /* Private variables ------------------------------------------------------------*/
  67. static nu_usbd_t nu_usbd =
  68. {
  69. .Instance = USBD,
  70. .address_tmp = 0,
  71. };
  72. static struct udcd _rt_obj_udc;
  73. static struct ep_id _ep_pool[] =
  74. {
  75. {EPADR_HW2SW(EP0), USB_EP_ATTR_CONTROL, USB_DIR_INOUT, EP0_MAX_PKT_SIZE, ID_ASSIGNED },
  76. {EPADR_HW2SW(EP2), USB_EP_ATTR_BULK, USB_DIR_IN, EP2_MAX_PKT_SIZE, ID_UNASSIGNED},
  77. {EPADR_HW2SW(EP3), USB_EP_ATTR_BULK, USB_DIR_OUT, EP3_MAX_PKT_SIZE, ID_UNASSIGNED},
  78. {EPADR_HW2SW(EP4), USB_EP_ATTR_INT, USB_DIR_IN, EP4_MAX_PKT_SIZE, ID_UNASSIGNED},
  79. {EPADR_HW2SW(EP5), USB_EP_ATTR_INT, USB_DIR_OUT, EP5_MAX_PKT_SIZE, ID_UNASSIGNED},
  80. {EPADR_HW2SW(EP6), USB_EP_ATTR_BULK, USB_DIR_IN, EP6_MAX_PKT_SIZE, ID_UNASSIGNED},
  81. {EPADR_HW2SW(EP7), USB_EP_ATTR_BULK, USB_DIR_OUT, EP7_MAX_PKT_SIZE, ID_UNASSIGNED},
  82. {EPADR_HW2SW(EP8), USB_EP_ATTR_INT, USB_DIR_IN, EP8_MAX_PKT_SIZE, ID_UNASSIGNED},
  83. {EPADR_HW2SW(EP9), USB_EP_ATTR_INT, USB_DIR_OUT, EP9_MAX_PKT_SIZE, ID_UNASSIGNED},
  84. {0xFF, USB_EP_ATTR_TYPE_MASK, USB_DIR_MASK, 0, ID_ASSIGNED },
  85. };
  86. static void _nu_ep_partition(void)
  87. {
  88. /* Init setup packet buffer */
  89. /* Buffer range for setup packet -> [0 ~ 0x7] */
  90. USBD->STBUFSEG = SETUP_BUF_BASE;
  91. /*****************************************************/
  92. /* EP0 ==> control IN endpoint, address 0 */
  93. USBD_CONFIG_EP(EP0, USBD_CFG_CSTALL | USBD_CFG_EPMODE_IN | EPADR_HW2SW(EP0));
  94. /* Buffer range for EP0 */
  95. USBD_SET_EP_BUF_ADDR(EP0, EP0_BUF_BASE);
  96. /* EP1 ==> control OUT endpoint, address 0 */
  97. USBD_CONFIG_EP(EP1, USBD_CFG_CSTALL | USBD_CFG_EPMODE_OUT | EPADR_HW2SW(EP1));
  98. /* Buffer range for EP1 */
  99. USBD_SET_EP_BUF_ADDR(EP1, EP1_BUF_BASE);
  100. /*****************************************************/
  101. /* EP2 ==> Bulk IN endpoint, address 1 */
  102. USBD_CONFIG_EP(EP2, USBD_CFG_EPMODE_IN | EPADR_HW2SW(EP2));
  103. /* Buffer range for EP2 */
  104. USBD_SET_EP_BUF_ADDR(EP2, EP2_BUF_BASE);
  105. /* EP3 ==> Bulk OUT endpoint, address 1 */
  106. USBD_CONFIG_EP(EP3, USBD_CFG_EPMODE_OUT | EPADR_HW2SW(EP3));
  107. /* Buffer range for EP3 */
  108. USBD_SET_EP_BUF_ADDR(EP3, EP3_BUF_BASE);
  109. /*****************************************************/
  110. /* EP4 ==> Interrupt IN endpoint, address 2 */
  111. USBD_CONFIG_EP(EP4, USBD_CFG_EPMODE_IN | EPADR_HW2SW(EP4));
  112. /* Buffer range for EP4 */
  113. USBD_SET_EP_BUF_ADDR(EP4, EP4_BUF_BASE);
  114. /* EP5 ==> Interrupt Out endpoint, address 2 */
  115. USBD_CONFIG_EP(EP5, USBD_CFG_EPMODE_OUT | EPADR_HW2SW(EP5));
  116. /* Buffer range for EP5 */
  117. USBD_SET_EP_BUF_ADDR(EP5, EP5_BUF_BASE);
  118. /*****************************************************/
  119. /* EP6 ==> Bulk IN endpoint, address 3 */
  120. USBD_CONFIG_EP(EP6, USBD_CFG_EPMODE_IN | EPADR_HW2SW(EP6));
  121. /* Buffer range for EP4 */
  122. USBD_SET_EP_BUF_ADDR(EP6, EP6_BUF_BASE);
  123. /* EP7 ==> Bulk Out endpoint, address 3 */
  124. USBD_CONFIG_EP(EP7, USBD_CFG_EPMODE_OUT | EPADR_HW2SW(EP7));
  125. /* Buffer range for EP5 */
  126. USBD_SET_EP_BUF_ADDR(EP7, EP7_BUF_BASE);
  127. /*****************************************************/
  128. /* EP8 ==> Interrupt IN endpoint, address 4 */
  129. USBD_CONFIG_EP(EP8, USBD_CFG_EPMODE_IN | EPADR_HW2SW(EP8));
  130. /* Buffer range for EP4 */
  131. USBD_SET_EP_BUF_ADDR(EP8, EP8_BUF_BASE);
  132. /* EP9 ==> Interrupt Out endpoint, address 4 */
  133. USBD_CONFIG_EP(EP9, USBD_CFG_EPMODE_OUT | EPADR_HW2SW(EP9));
  134. /* Buffer range for EP9 */
  135. USBD_SET_EP_BUF_ADDR(EP9, EP9_BUF_BASE);
  136. }
  137. static rt_err_t _ep_set_stall(rt_uint8_t address)
  138. {
  139. USBD_SET_EP_STALL(EPADR_SW2HW(address));
  140. return RT_EOK;
  141. }
  142. static rt_err_t _ep_clear_stall(rt_uint8_t address)
  143. {
  144. USBD_ClearStall(EPADR_SW2HW(address));
  145. return RT_EOK;
  146. }
  147. static rt_err_t _set_address(rt_uint8_t address)
  148. {
  149. if (0 != address)
  150. {
  151. nu_usbd.address_tmp = address;
  152. }
  153. return RT_EOK;
  154. }
  155. static rt_err_t _set_config(rt_uint8_t address)
  156. {
  157. return RT_EOK;
  158. }
  159. static rt_err_t _ep_enable(uep_t ep)
  160. {
  161. RT_ASSERT(ep != RT_NULL);
  162. RT_ASSERT(ep->ep_desc != RT_NULL);
  163. USBD_CONFIG_EP(EPADR_SW2HW(EP_ADDRESS(ep)),
  164. USBD_CFG_CSTALL
  165. | ((EP_ADDRESS(ep) & USB_DIR_IN) ? USBD_CFG_EPMODE_IN : USBD_CFG_EPMODE_OUT)
  166. | (EP_ADDRESS(ep) & USB_EPNO_MASK));
  167. return RT_EOK;
  168. }
  169. static rt_err_t _ep_disable(uep_t ep)
  170. {
  171. RT_ASSERT(ep != RT_NULL);
  172. RT_ASSERT(ep->ep_desc != RT_NULL);
  173. USBD_CONFIG_EP(EPADR_SW2HW(EP_ADDRESS(ep)), USBD_CFG_EPMODE_DISABLE);
  174. return RT_EOK;
  175. }
  176. static rt_size_t _ep_read(rt_uint8_t address, void *buffer)
  177. {
  178. rt_size_t size = 0;
  179. rt_uint8_t *buf;
  180. rt_uint32_t hw_ep_num = EPADR_SW2HW(address);
  181. RT_ASSERT(!(address & USB_DIR_IN));
  182. RT_ASSERT(buffer != RT_NULL);
  183. size = USBD_GET_PAYLOAD_LEN(hw_ep_num);
  184. buf = (uint8_t *)(USBD_BUF_BASE + USBD_GET_EP_BUF_ADDR(hw_ep_num));
  185. USBD_MemCopy(buffer, (uint8_t *)buf, size);
  186. return size;
  187. }
  188. static rt_size_t _ep_read_prepare(rt_uint8_t address, void *buffer, rt_size_t size)
  189. {
  190. RT_ASSERT(!(address & USB_DIR_IN));
  191. USBD_SET_PAYLOAD_LEN(EPADR_SW2HW(address), size);
  192. return size;
  193. }
  194. static rt_size_t _ep_write(rt_uint8_t address, void *buffer, rt_size_t size)
  195. {
  196. RT_ASSERT((address & USB_DIR_IN));
  197. /* even number is for IN endpoint */
  198. rt_uint32_t hw_ep_num = EPADR_SW2HW(address);
  199. uint8_t *buf;
  200. buf = (uint8_t *)(USBD_BUF_BASE + USBD_GET_EP_BUF_ADDR(hw_ep_num));
  201. USBD_MemCopy(buf, (uint8_t *)buffer, size);
  202. USBD_SET_PAYLOAD_LEN(hw_ep_num, size);
  203. return size;
  204. }
  205. static rt_err_t _ep0_send_status(void)
  206. {
  207. /* Status stage */
  208. USBD_SET_DATA1(EP0);
  209. USBD_SET_PAYLOAD_LEN(EP0, 0);
  210. return RT_EOK;
  211. }
  212. static rt_err_t _suspend(void)
  213. {
  214. return RT_EOK;
  215. }
  216. static rt_err_t _wakeup(void)
  217. {
  218. return RT_EOK;
  219. }
  220. __STATIC_INLINE void _USBD_IRQHandler(void)
  221. {
  222. rt_uint32_t u32IntSts = USBD_GET_INT_FLAG();
  223. rt_uint32_t u32State = USBD_GET_BUS_STATE();
  224. //------------------------------------------------------------------
  225. if (u32IntSts & USBD_INTSTS_VBDETIF_Msk)
  226. {
  227. // Floating detect
  228. USBD_CLR_INT_FLAG(USBD_INTSTS_VBDETIF_Msk);
  229. if (USBD_IS_ATTACHED())
  230. {
  231. /* USB Plug In */
  232. USBD_ENABLE_USB();
  233. rt_usbd_connect_handler(&_rt_obj_udc);
  234. }
  235. else
  236. {
  237. /* USB Unplug */
  238. USBD_DISABLE_USB();
  239. rt_usbd_disconnect_handler(&_rt_obj_udc);
  240. }
  241. }
  242. if (u32IntSts & USBD_INTSTS_SOFIF_Msk)
  243. {
  244. USBD_CLR_INT_FLAG(USBD_INTSTS_SOFIF_Msk);
  245. rt_usbd_sof_handler(&_rt_obj_udc);
  246. }
  247. //------------------------------------------------------------------
  248. if (u32IntSts & USBD_INTSTS_BUSIF_Msk)
  249. {
  250. /* Clear event flag */
  251. USBD_CLR_INT_FLAG(USBD_INTSTS_BUSIF_Msk);
  252. if (u32State & USBD_ATTR_USBRST_Msk)
  253. {
  254. USBD_ENABLE_USB();
  255. /* Reset PID DATA0 */
  256. for (rt_uint32_t i = 0ul; i < USBD_MAX_EP; i++)
  257. {
  258. nu_usbd.Instance->EP[i].CFG &= ~USBD_CFG_DSQSYNC_Msk;
  259. }
  260. /* Reset USB device address */
  261. USBD_SET_ADDR(0ul);
  262. /* Bus reset */
  263. rt_usbd_reset_handler(&_rt_obj_udc);
  264. }
  265. if (u32State & USBD_ATTR_SUSPEND_Msk)
  266. {
  267. /* Enable USB but disable PHY */
  268. USBD_DISABLE_PHY();
  269. }
  270. if (u32State & USBD_ATTR_RESUME_Msk)
  271. {
  272. /* Enable USB and enable PHY */
  273. USBD_ENABLE_USB();
  274. }
  275. }
  276. //------------------------------------------------------------------
  277. if (u32IntSts & USBD_INTSTS_WAKEUP)
  278. {
  279. /* Clear event flag */
  280. USBD_CLR_INT_FLAG(USBD_INTSTS_WAKEUP);
  281. USBD_ENABLE_USB();
  282. }
  283. if (u32IntSts & USBD_INTSTS_USBIF_Msk)
  284. {
  285. // USB event
  286. if (u32IntSts & USBD_INTSTS_SETUP_Msk)
  287. {
  288. // Setup packet
  289. /* Clear event flag */
  290. USBD_CLR_INT_FLAG(USBD_INTSTS_SETUP_Msk);
  291. /* Clear the data IN/OUT ready flag of control end-points */
  292. USBD_STOP_TRANSACTION(EP0);
  293. USBD_STOP_TRANSACTION(EP1);
  294. USBD_SET_DATA1(EP0);
  295. rt_usbd_ep0_setup_handler(&_rt_obj_udc, (struct urequest *)USBD_BUF_BASE);
  296. }
  297. // EP events
  298. if (u32IntSts & USBD_INTSTS_EP0)
  299. {
  300. /* Clear event flag */
  301. USBD_CLR_INT_FLAG(USBD_INTSTS_EP0);
  302. if ((USBD_GET_ADDR() == 0)
  303. && (nu_usbd.address_tmp)
  304. )
  305. {
  306. USBD_SET_ADDR(nu_usbd.address_tmp);
  307. LOG_I("SET ADDR: 0x%02x", nu_usbd.address_tmp);
  308. nu_usbd.address_tmp = 0;
  309. }
  310. rt_usbd_ep0_in_handler(&_rt_obj_udc);
  311. }
  312. if (u32IntSts & USBD_INTSTS_EP1)
  313. {
  314. /* Clear event flag */
  315. USBD_CLR_INT_FLAG(USBD_INTSTS_EP1);
  316. rt_usbd_ep0_out_handler(&_rt_obj_udc, 0);
  317. }
  318. if (u32IntSts & USBD_INTSTS_EP2)
  319. {
  320. /* Clear event flag */
  321. USBD_CLR_INT_FLAG(USBD_INTSTS_EP2);
  322. rt_usbd_ep_in_handler(&_rt_obj_udc, USB_DIR_IN | EPADR_HW2SW(EP2), 0);
  323. }
  324. if (u32IntSts & USBD_INTSTS_EP3)
  325. {
  326. /* Clear event flag */
  327. USBD_CLR_INT_FLAG(USBD_INTSTS_EP3);
  328. rt_usbd_ep_out_handler(&_rt_obj_udc, USB_DIR_OUT | EPADR_HW2SW(EP3), 0);
  329. }
  330. if (u32IntSts & USBD_INTSTS_EP4)
  331. {
  332. /* Clear event flag */
  333. USBD_CLR_INT_FLAG(USBD_INTSTS_EP4);
  334. rt_usbd_ep_in_handler(&_rt_obj_udc, USB_DIR_IN | EPADR_HW2SW(EP4), 0);
  335. }
  336. if (u32IntSts & USBD_INTSTS_EP5)
  337. {
  338. /* Clear event flag */
  339. USBD_CLR_INT_FLAG(USBD_INTSTS_EP5);
  340. rt_usbd_ep_out_handler(&_rt_obj_udc, USB_DIR_OUT | EPADR_HW2SW(EP5), 0);
  341. }
  342. if (u32IntSts & USBD_INTSTS_EP6)
  343. {
  344. /* Clear event flag */
  345. USBD_CLR_INT_FLAG(USBD_INTSTS_EP6);
  346. rt_usbd_ep_in_handler(&_rt_obj_udc, USB_DIR_IN | EPADR_HW2SW(EP6), 0);
  347. }
  348. if (u32IntSts & USBD_INTSTS_EP7)
  349. {
  350. /* Clear event flag */
  351. USBD_CLR_INT_FLAG(USBD_INTSTS_EP7);
  352. rt_usbd_ep_out_handler(&_rt_obj_udc, USB_DIR_OUT | EPADR_HW2SW(EP7), 0);
  353. }
  354. if (u32IntSts & USBD_INTSTS_EP8)
  355. {
  356. /* Clear event flag */
  357. USBD_CLR_INT_FLAG(USBD_INTSTS_EP8);
  358. rt_usbd_ep_in_handler(&_rt_obj_udc, USB_DIR_IN | EPADR_HW2SW(EP8), 0);
  359. }
  360. if (u32IntSts & USBD_INTSTS_EP9)
  361. {
  362. /* Clear event flag */
  363. USBD_CLR_INT_FLAG(USBD_INTSTS_EP9);
  364. rt_usbd_ep_out_handler(&_rt_obj_udc, USB_DIR_OUT | EPADR_HW2SW(EP9), 0);
  365. }
  366. }
  367. }
  368. void USBD_IRQHandler(void)
  369. {
  370. rt_interrupt_enter();
  371. _USBD_IRQHandler();
  372. rt_interrupt_leave();
  373. }
  374. static rt_err_t _init(rt_device_t device)
  375. {
  376. nu_usbd_t *nu_usbd = (nu_usbd_t *)device->user_data;
  377. /* Initialize USB PHY */
  378. SYS_UnlockReg();
  379. /* Select USBD */
  380. SYS->USBPHY = (SYS->USBPHY & ~SYS_USBPHY_USBROLE_Msk) | SYS_USBPHY_USBEN_Msk | SYS_USBPHY_SBO_Msk;
  381. SYS_ResetModule(USBD_RST);
  382. SYS_LockReg();
  383. _nu_ep_partition();
  384. /* Initial USB engine */
  385. nu_usbd->Instance->ATTR = 0x6D0ul;
  386. /* Force SE0 */
  387. USBD_SET_SE0();
  388. NVIC_EnableIRQ(USBD_IRQn);
  389. USBD_Start();
  390. return RT_EOK;
  391. }
  392. const static struct udcd_ops _udc_ops =
  393. {
  394. _set_address,
  395. _set_config,
  396. _ep_set_stall,
  397. _ep_clear_stall,
  398. _ep_enable,
  399. _ep_disable,
  400. _ep_read_prepare,
  401. _ep_read,
  402. _ep_write,
  403. _ep0_send_status,
  404. _suspend,
  405. _wakeup,
  406. };
  407. #ifdef RT_USING_DEVICE_OPS
  408. const static struct rt_device_ops _ops =
  409. {
  410. _init,
  411. RT_NULL,
  412. RT_NULL,
  413. RT_NULL,
  414. RT_NULL,
  415. RT_NULL,
  416. };
  417. #endif
  418. int nu_usbd_register(void)
  419. {
  420. if (RT_NULL != rt_device_find("usbd"))
  421. {
  422. LOG_E("\nUSBD Register failed. Another USBD device registered\n");
  423. return -RT_ERROR;
  424. }
  425. rt_memset((void *)&_rt_obj_udc, 0, sizeof(struct udcd));
  426. _rt_obj_udc.parent.type = RT_Device_Class_USBDevice;
  427. #ifdef RT_USING_DEVICE_OPS
  428. _rt_obj_udc.parent.ops = &_ops;
  429. #else
  430. _rt_obj_udc.parent.init = _init;
  431. #endif
  432. _rt_obj_udc.parent.user_data = &nu_usbd;
  433. _rt_obj_udc.ops = &_udc_ops;
  434. /* Register endpoint information */
  435. _rt_obj_udc.ep_pool = _ep_pool;
  436. _rt_obj_udc.ep0.id = &_ep_pool[0];
  437. _rt_obj_udc.device_is_hs = RT_FALSE; /* Support Full-Speed only */
  438. rt_device_register((rt_device_t)&_rt_obj_udc, "usbd", 0);
  439. rt_usb_device_init();
  440. return RT_EOK;
  441. }
  442. INIT_DEVICE_EXPORT(nu_usbd_register);
  443. #endif