Skip to content

Commit

Permalink
Correctly use single buffering for ISO.
Browse files Browse the repository at this point in the history
  • Loading branch information
HiFiPhile committed Apr 5, 2024
1 parent eeaf626 commit d5a9b84
Showing 1 changed file with 28 additions and 25 deletions.
53 changes: 28 additions & 25 deletions src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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, /**/);

Expand Down Expand Up @@ -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;

Expand All @@ -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,
Expand All @@ -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;
}
Expand All @@ -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;

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit d5a9b84

Please sign in to comment.