From 21bdafcfef4cfdbd77277da1717c8a33544b8721 Mon Sep 17 00:00:00 2001 From: Mengsk Date: Fri, 30 Dec 2022 01:05:12 +0100 Subject: Add ISO buffer allocation. --- src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c | 37 ++++++++++++++++++--------- 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'src/portable') diff --git a/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c b/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c index d462fc649..a428d546d 100644 --- a/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c +++ b/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c @@ -812,6 +812,13 @@ static uint8_t dcd_ep_alloc(uint8_t ep_addr, uint8_t ep_type) for(uint8_t i = 0; i < STFSDEV_EP_COUNT; i++) { + // Check if already allocated + if(ep_alloc_status[i].allocated[dir] && + ep_alloc_status[i].ep_type == ep_type && + ep_alloc_status[i].ep_num == epnum) + { + return i; + } // If EP of current direction is not allocated // Except for ISO endpoint, both direction should be free if(!ep_alloc_status[i].allocated[dir] && @@ -971,7 +978,7 @@ void dcd_edpt_close (uint8_t rhport, uint8_t ep_addr) if(dir == TUSB_DIR_IN) { - pcd_set_ep_tx_status(USB,epnum, USB_EP_TX_DIS); + pcd_set_ep_tx_status(USB, epnum, USB_EP_TX_DIS); } else { @@ -994,10 +1001,15 @@ bool dcd_edpt_iso_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t largest_packet /* Create a packet memory buffer area. For isochronous endpoints, * use the same buffer as the double buffer, essentially disabling double buffering */ - dcd_pma_alloc(ep_addr, buffer_size); + uint16_t pma_addr = dcd_pma_alloc(ep_addr, buffer_size); xfer_ctl_ptr(ep_addr)->epnum = epnum; + pcd_set_eptype(USB, epnum, USB_EP_ISOCHRONOUS); + + *pcd_ep_tx_address_ptr(USB, epnum) = pma_addr; + *pcd_ep_rx_address_ptr(USB, epnum) = pma_addr; + return true; } @@ -1005,25 +1017,26 @@ bool dcd_edpt_iso_activate(uint8_t rhport, tusb_desc_endpoint_t const * p_endpo { (void)rhport; uint8_t const epnum = xfer_ctl_ptr(p_endpoint_desc->bEndpointAddress)->epnum; - const uint16_t packet_size = tu_edpt_packet_size(p_endpoint_desc); - uint16_t pma_addr; + uint8_t const dir = tu_edpt_dir(p_endpoint_desc->bEndpointAddress); + const uint16_t packet_size = pcd_aligned_buffer_size(tu_edpt_packet_size(p_endpoint_desc)); /* Disable endpoint */ - pcd_set_ep_tx_status(USB, epnum, USB_EP_TX_DIS); - pcd_set_ep_rx_status(USB, epnum, USB_EP_RX_DIS); - - pcd_set_eptype(USB, epnum, USB_EP_ISOCHRONOUS); + if(dir == TUSB_DIR_IN) + { + pcd_set_ep_tx_status(USB, epnum, USB_EP_TX_DIS); + } + else + { + pcd_set_ep_rx_status(USB, epnum, USB_EP_RX_DIS); + } + pcd_set_ep_address(USB, epnum, 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); - pma_addr = xfer_ctl_ptr(p_endpoint_desc->bEndpointAddress)->pma_ptr; - - *pcd_ep_tx_address_ptr(USB, epnum) = pma_addr; pcd_clear_tx_dtog(USB, epnum); - *pcd_ep_rx_address_ptr(USB, epnum) = pma_addr; pcd_set_ep_rx_bufsize(USB, epnum, packet_size); pcd_clear_rx_dtog(USB, epnum); -- cgit v1.3.1