From d5a9b84809870a39f991b6e2492ae5424773e7a0 Mon Sep 17 00:00:00 2001 From: HiFiPhile Date: Fri, 5 Apr 2024 13:15:19 +0200 Subject: [PATCH] Correctly use single buffering for ISO. --- src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c | 53 ++++++++++--------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c b/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c index 6f0742c7c0..08d792bfa5 100644 --- a/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c +++ b/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c @@ -518,6 +518,11 @@ static void dcd_ep_ctr_tx_handler(uint32_t wIstr) pcd_clear_tx_ep_ctr(USB, EPindex); xfer_ctl_t * xfer = xfer_ctl_ptr(ep_addr); + + if ((wEPRegVal & USB_EP_TYPE_MASK) == USB_EP_ISOCHRONOUS) { + pcd_set_ep_tx_cnt(USB, EPindex, 0); + } + if((xfer->total_len != xfer->queued_len)) /* TX not complete */ { dcd_transmit_packet(xfer, EPindex); @@ -587,12 +592,7 @@ static void dcd_ep_ctr_rx_handler(uint32_t wIstr) { else { uint32_t count; - /* Read from correct register when ISOCHRONOUS (double buffered) */ - if ( (wEPRegVal & USB_EP_DTOG_RX) && ( (wEPRegVal & USB_EP_TYPE_MASK) == USB_EP_ISOCHRONOUS) ) { - count = pcd_get_ep_tx_cnt(USB, EPindex); - } else { - count = pcd_get_ep_rx_cnt(USB, EPindex); - } + count = pcd_get_ep_rx_cnt(USB, EPindex); TU_ASSERT(count <= xfer->max_packet_size, /**/); @@ -935,7 +935,7 @@ void dcd_edpt_close_all (uint8_t rhport) * * This also clears transfers in progress, should there be any. */ -void dcd_edpt_close (uint8_t rhport, uint8_t ep_addr) +void dcd_edpt_close(uint8_t rhport, uint8_t ep_addr) { (void)rhport; @@ -957,9 +957,11 @@ bool dcd_edpt_iso_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t largest_packet { (void)rhport; - TU_ASSERT(largest_packet_size <= 1024); + // Long packet is not supported + TU_ASSERT(largest_packet_size < 512); uint8_t const ep_idx = dcd_ep_alloc(ep_addr, TUSB_XFER_ISOCHRONOUS); + uint8_t const dir = tu_edpt_dir(ep_addr); const uint16_t buffer_size = pcd_aligned_buffer_size(largest_packet_size); /* Create a packet memory buffer area. For isochronous endpoints, @@ -970,8 +972,18 @@ bool dcd_edpt_iso_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t largest_packet pcd_set_eptype(USB, ep_idx, USB_EP_ISOCHRONOUS); - pcd_set_ep_tx_address(USB, ep_idx, pma_addr); - pcd_set_ep_rx_address(USB, ep_idx, pma_addr); + // Disable double buffering + pcd_set_ep_kind(USB, ep_idx); + + if(dir == TUSB_DIR_IN) + { + pcd_set_ep_tx_address(USB, ep_idx, pma_addr); + } + + if(dir == TUSB_DIR_OUT) + { + pcd_set_ep_rx_address(USB, ep_idx, pma_addr); + } return true; } @@ -988,21 +1000,17 @@ bool dcd_edpt_iso_activate(uint8_t rhport, tusb_desc_endpoint_t const * p_endpo if(dir == TUSB_DIR_IN) { pcd_set_ep_tx_status(USB, ep_idx, USB_EP_TX_DIS); + pcd_set_ep_tx_bufsize(USB, ep_idx, buffer_size); + pcd_clear_tx_dtog(USB, ep_idx); } else { pcd_set_ep_rx_status(USB, ep_idx, USB_EP_RX_DIS); + pcd_set_ep_rx_bufsize(USB, ep_idx, buffer_size); + pcd_clear_rx_dtog(USB, ep_idx); } pcd_set_ep_address(USB, ep_idx, tu_edpt_number(p_endpoint_desc->bEndpointAddress)); - // Be normal, for now, instead of only accepting zero-byte packets (on control endpoint) - // or being double-buffered (bulk endpoints) - pcd_clear_ep_kind(USB,0); - - pcd_set_ep_tx_bufsize(USB, ep_idx, buffer_size); - pcd_set_ep_rx_bufsize(USB, ep_idx, buffer_size); - pcd_clear_tx_dtog(USB, ep_idx); - pcd_clear_rx_dtog(USB, ep_idx); xfer_ctl_ptr(p_endpoint_desc->bEndpointAddress)->max_packet_size = packet_size; @@ -1033,14 +1041,9 @@ static void dcd_transmit_packet(xfer_ctl_t * xfer, uint16_t ep_ix) } xfer->queued_len = (uint16_t)(xfer->queued_len + len); - /* Write into correct register when ISOCHRONOUS (double buffered) */ - if ( (ep_reg & USB_EP_DTOG_TX) && ( (ep_reg & USB_EP_TYPE_MASK) == USB_EP_ISOCHRONOUS) ) { - pcd_set_ep_rx_cnt(USB, ep_ix, len); - } else { - pcd_set_ep_tx_cnt(USB, ep_ix, len); - } - + pcd_set_ep_tx_cnt(USB, ep_ix, len); pcd_set_ep_tx_status(USB, ep_ix, USB_EP_TX_VALID); + } bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes)