summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsakumisu <[email protected]>2022-08-21 13:03:26 +0800
committersakumisu <[email protected]>2022-08-21 13:03:26 +0800
commit7391b7a5b914d26e24e652dbe94944cfc6a03d6b (patch)
tree4a442d15e3ef3a246475dedb6930de296bec9d70
parent1e80e240e2ebe1eae047340f10bf4225e9dfd7e2 (diff)
update dwc2 iso transfer
-rw-r--r--demo/audio_v1_mic_multichan_template.c10
-rw-r--r--demo/audio_v1_mic_speaker_multichan_template.c21
-rw-r--r--demo/video_static_mjpeg_template.c9
-rw-r--r--port/dwc2/usb_dc_dwc2.c18
4 files changed, 52 insertions, 6 deletions
diff --git a/demo/audio_v1_mic_multichan_template.c b/demo/audio_v1_mic_multichan_template.c
index 4a99e28f..7d077a3b 100644
--- a/demo/audio_v1_mic_multichan_template.c
+++ b/demo/audio_v1_mic_multichan_template.c
@@ -149,6 +149,7 @@ void usbd_configure_done_callback(void)
}
volatile bool tx_flag = 0;
+volatile bool ep_tx_busy_flag = false;
void usbd_audio_open(uint8_t intf)
{
@@ -163,6 +164,8 @@ void usbd_audio_close(uint8_t intf)
void usbd_audio_iso_callback(uint8_t ep, uint32_t nbytes)
{
+ USB_LOG_RAW("actual in len:%d\r\n", nbytes);
+ ep_tx_busy_flag = false;
}
static struct usbd_endpoint audio_in_ep = {
@@ -182,10 +185,17 @@ void audio_init()
usbd_initialize();
}
+USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t write_buffer[2048];
+
void audio_test()
{
while (1) {
if (tx_flag) {
+ memset(write_buffer, 'a', 2048);
+ ep_tx_busy_flag = true;
+ usbd_ep_start_write(AUDIO_IN_EP, write_buffer, 2048);
+ while (ep_tx_busy_flag) {
+ }
}
}
}
diff --git a/demo/audio_v1_mic_speaker_multichan_template.c b/demo/audio_v1_mic_speaker_multichan_template.c
index 87dd3895..48047ac8 100644
--- a/demo/audio_v1_mic_speaker_multichan_template.c
+++ b/demo/audio_v1_mic_speaker_multichan_template.c
@@ -160,21 +160,27 @@ void usbd_audio_close(uint8_t intf)
#define AUDIO_OUT_EP_MPS 64
#endif
-USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t out_buffer[AUDIO_OUT_EP_MPS];
+USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t write_buffer[2048];
+USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t out_buffer[AUDIO_OUT_PACKET];
+
+volatile bool ep_tx_busy_flag = false;
void usbd_configure_done_callback(void)
{
/* setup first out ep read transfer */
- usbd_ep_start_read(AUDIO_OUT_EP, out_buffer, AUDIO_OUT_EP_MPS);
+ usbd_ep_start_read(AUDIO_OUT_EP, out_buffer, AUDIO_OUT_PACKET);
}
-void usbd_audio_out_callback(uint8_t ep, uint32_t bytes)
+void usbd_audio_out_callback(uint8_t ep, uint32_t nbytes)
{
-
+ USB_LOG_RAW("actual out len:%d\r\n", nbytes);
+ usbd_ep_start_read(AUDIO_OUT_EP, out_buffer, AUDIO_OUT_PACKET);
}
-void usbd_audio_in_callback(uint8_t ep, uint32_t bytes)
+void usbd_audio_in_callback(uint8_t ep, uint32_t nbytes)
{
+ USB_LOG_RAW("actual in len:%d\r\n", nbytes);
+ ep_tx_busy_flag = false;
}
static struct usbd_endpoint audio_in_ep = {
@@ -206,6 +212,11 @@ void audio_test()
{
while (1) {
if (tx_flag) {
+// memset(write_buffer, 'a', 2048);
+// ep_tx_busy_flag = true;
+// usbd_ep_start_write(AUDIO_IN_EP, write_buffer, 2048);
+// while (ep_tx_busy_flag) {
+// }
}
}
}
diff --git a/demo/video_static_mjpeg_template.c b/demo/video_static_mjpeg_template.c
index 8b25e119..77360fff 100644
--- a/demo/video_static_mjpeg_template.c
+++ b/demo/video_static_mjpeg_template.c
@@ -141,6 +141,11 @@ const uint8_t video_descriptor[] = {
0x00
};
+void usbd_configure_done_callback(void)
+{
+ /* no out ep, so do nothing */
+}
+
volatile bool tx_flag = 0;
void usbd_video_open(uint8_t intf)
@@ -158,6 +163,7 @@ volatile bool iso_tx_busy = false;
void usbd_video_iso_callback(uint8_t ep, uint32_t nbytes)
{
+ USB_LOG_RAW("actual in len:%d\r\n", nbytes);
iso_tx_busy = false;
}
@@ -170,6 +176,7 @@ void video_init()
{
usbd_desc_register(video_descriptor);
usbd_add_interface(usbd_video_alloc_intf(CAM_FPS, MAX_FRAME_SIZE, MAX_PAYLOAD_SIZE));
+ usbd_add_interface(usbd_video_alloc_intf(CAM_FPS, MAX_FRAME_SIZE, MAX_PAYLOAD_SIZE));
usbd_add_endpoint(&video_in_ep);
usbd_initialize();
@@ -198,7 +205,7 @@ void video_test()
}
} else {
iso_tx_busy = true;
- usbd_ep_start_write(VIDEO_IN_EP, &packet_buffer[i * MAX_PAYLOAD_SIZE], MAX_PAYLOAD_SIZE, NULL);
+ usbd_ep_start_write(VIDEO_IN_EP, &packet_buffer[i * MAX_PAYLOAD_SIZE], MAX_PAYLOAD_SIZE);
while (iso_tx_busy) {
}
}
diff --git a/port/dwc2/usb_dc_dwc2.c b/port/dwc2/usb_dc_dwc2.c
index 7ddb6625..26135833 100644
--- a/port/dwc2/usb_dc_dwc2.c
+++ b/port/dwc2/usb_dc_dwc2.c
@@ -841,6 +841,16 @@ int usbd_ep_start_write(const uint8_t ep, const uint8_t *data, uint32_t data_len
#ifdef CONFIG_USB_DWC2_DMA_ENABLE
usb_dwc2_dcache_clean((uintptr_t)data, data_len);
USB_OTG_INEP(ep_idx)->DIEPDMA = (uint32_t)data;
+
+ if (g_dwc2_udc.in_ep[ep_idx].ep_type == 0x01) {
+ if ((USB_OTG_DEV->DSTS & (1U << 8)) == 0U) {
+ USB_OTG_INEP(ep_idx)->DIEPCTL |= USB_OTG_DIEPCTL_SODDFRM;
+ } else {
+ USB_OTG_INEP(ep_idx)->DIEPCTL |= USB_OTG_DIEPCTL_SD0PID_SEVNFRM;
+ }
+ USB_OTG_INEP(ep_idx)->DIEPTSIZ &= ~(USB_OTG_DIEPTSIZ_MULCNT);
+ USB_OTG_INEP(ep_idx)->DIEPTSIZ |= (USB_OTG_DIEPTSIZ_MULCNT & (1U << 29));
+ }
USB_OTG_INEP(ep_idx)->DIEPCTL |= (USB_OTG_DIEPCTL_CNAK | USB_OTG_DIEPCTL_EPENA);
#else
USB_OTG_INEP(ep_idx)->DIEPCTL |= (USB_OTG_DIEPCTL_CNAK | USB_OTG_DIEPCTL_EPENA);
@@ -911,6 +921,14 @@ int usbd_ep_start_read(const uint8_t ep, uint8_t *data, uint32_t data_len)
#ifdef CONFIG_USB_DWC2_DMA_ENABLE
USB_OTG_OUTEP(ep_idx)->DOEPDMA = (uint32_t)data;
+
+ if (g_dwc2_udc.out_ep[ep_idx].ep_type == 0x01) {
+ if ((USB_OTG_DEV->DSTS & (1U << 8)) == 0U) {
+ USB_OTG_OUTEP(ep_idx)->DOEPCTL |= USB_OTG_DIEPCTL_SODDFRM;
+ } else {
+ USB_OTG_OUTEP(ep_idx)->DOEPCTL |= USB_OTG_DIEPCTL_SD0PID_SEVNFRM;
+ }
+ }
#endif
USB_OTG_OUTEP(ep_idx)->DOEPCTL |= (USB_OTG_DOEPCTL_CNAK | USB_OTG_DOEPCTL_EPENA);