Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions components/drivers/usb/cherryusb/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ if RT_USING_CHERRYUSB
bool "CUSTOM (Implement it yourself)"
config RT_CHERRYUSB_DEVICE_FSDEV_ST
bool "fsdev_st"
config RT_CHERRYUSB_DEVICE_FSDEV_NATION
bool "fsdev_nation"
config RT_CHERRYUSB_DEVICE_FSDEV_CUSTOM
bool "fsdev_custom"
config RT_CHERRYUSB_DEVICE_DWC2_ST
Expand Down
3 changes: 3 additions & 0 deletions components/drivers/usb/cherryusb/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ if GetDepend(['RT_CHERRYUSB_DEVICE']):
if GetDepend(['RT_CHERRYUSB_DEVICE_FSDEV_ST']):
src += Glob('port/fsdev/usb_dc_fsdev.c')
src += Glob('port/fsdev/usb_glue_st.c')
if GetDepend(['RT_CHERRYUSB_DEVICE_FSDEV_NATION']):
src += Glob('port/fsdev/usb_dc_fsdev.c')
src += Glob('port/fsdev/usb_glue_nation.c')
if GetDepend(['RT_CHERRYUSB_DEVICE_FSDEV_CUSTOM']):
src += Glob('port/fsdev/usb_dc_fsdev.c')
if GetDepend(['RT_CHERRYUSB_DEVICE_DWC2_ST']):
Expand Down
8 changes: 8 additions & 0 deletions components/drivers/usb/cherryusb/port/fsdev/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,11 @@
## CH32

- CH32F10x、CH32V10x

## N32

- N32H473、N32H474、N32H475、N32H481、N32H482、N32H480、N32H487、N32H488

- N32H49X


36 changes: 36 additions & 0 deletions components/drivers/usb/cherryusb/port/fsdev/usb_dc_fsdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,30 @@ __WEAK void usb_dc_low_level_deinit(void)
{
}

/**
* @brief Initialize the USB device controller.
* @param busid USB bus index (fsdev supports a single instance, bus 0).
* @retval 0 on success.
*/
int usb_dc_init(uint8_t busid)
{
usb_dc_low_level_init();

#if defined(N32H4X_FSDEV)
/* N32H4x power-on sequence: the USB_CTRL reset value is 0x0300
* -- PD(bit9, power-down) and FRST(bit8, force-reset) are both set.
* 1. Clear PD, wait for the internal analog voltage reference to settle.
* 2. Clear FRST.
* 3. Clear the STS register to drop pending interrupts. */
USB->CNTR &= (uint32_t)~USB_CNTR_PDWN; /* exit power-down */

/* Wait for the internal reference voltage to stabilise. */
for (volatile uint32_t i = 0U; i < 1000U; i++) {
}

USB->CNTR &= (uint32_t)~USB_CNTR_FRES; /* clear force-reset flag */
USB->ISTR = 0U; /* clear pending interrupts */
#else
/* Init Device */
/* CNTR_FRES = 1 */
USB->CNTR = (uint16_t)USB_CNTR_FRES;
Expand All @@ -73,6 +93,7 @@ int usb_dc_init(uint8_t busid)

/* Clear pending interrupts */
USB->ISTR = 0U;
#endif

/*Set Btable Address*/
USB->BTABLE = BTABLE_ADDRESS;
Expand All @@ -91,8 +112,13 @@ int usb_dc_init(uint8_t busid)
/* Set interrupt mask */
USB->CNTR = (uint16_t)winterruptmask;

#if defined(N32H4X_FSDEV)
/* Enabling DP Pull-UP through USB_CTRL.PU */
USB->CNTR |= (uint32_t)USB_CNTR_PU;
#else
/* Enabling DP Pull-UP bit to Connect internal PU resistor on USB DP line */
USB->BCDR |= (uint16_t)USB_BCDR_DPPU;
#endif

return 0;
}
Expand Down Expand Up @@ -325,6 +351,10 @@ int usbd_ep_start_read(uint8_t busid, const uint8_t ep, uint8_t *data, uint32_t
return 0;
}

/**
* @brief USB FS device interrupt handler: dispatches ISTR events.
* @param busid USB bus index (fsdev supports a single instance, bus 0).
*/
void USBD_IRQHandler(uint8_t busid)
{
uint16_t wIstr, wEPVal;
Expand All @@ -339,7 +369,13 @@ void USBD_IRQHandler(uint8_t busid)
wIstr = USB->ISTR;

/* extract highest priority endpoint number */
#if defined(N32H4X_FSDEV)
/* EP_ID is at STS bits [11:8] */
ep_idx = (uint8_t)((wIstr & USB_ISTR_EP_ID) >> USB_ISTR_EP_ID_Pos);
#else
/* ST: EP_ID is at ISTR bits [3:0] */
ep_idx = (uint8_t)(wIstr & USB_ISTR_EP_ID);
#endif

if (ep_idx == 0U) {
if ((wIstr & USB_ISTR_DIR) == 0U) {
Expand Down
Loading
Loading