Skip to content

Commit d6b6122

Browse files
skuepHiFiPhile
authored andcommitted
Fixed bug where with some devices, the TU_ASSERT inserted with this commit gets triggered for ISOCHRONOUS endpoints. It is necessary for those endpoints to set the NUM_BLOCK and BLSIZE for the receiving buffer in both, USB_COUNTn_TX and USB_COUNTn_RX. Despite the datasheet showing those fields only for the USB_COUNTn_RX register
1 parent 69475cd commit d6b6122

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,8 @@ static void dcd_ep_ctr_rx_handler(uint32_t wIstr)
562562
count = pcd_get_ep_rx_cnt(USB, EPindex);
563563
}
564564

565+
TU_ASSERT(count <= xfer->max_packet_size, /**/);
566+
565567
// Clear RX CTR interrupt flag
566568
if(ep_addr != 0u)
567569
{
@@ -599,7 +601,12 @@ static void dcd_ep_ctr_rx_handler(uint32_t wIstr)
599601
} else {
600602
pcd_set_ep_rx_bufsize(USB, EPindex,remaining);
601603
}
602-
pcd_set_ep_rx_status(USB, EPindex, USB_EP_RX_VALID);
604+
605+
if (!((wEPRegVal & USB_EP_TYPE_MASK) == USB_EP_ISOCHRONOUS)) {
606+
/* Set endpoint active again for receiving more data.
607+
* Note that isochronous endpoints stay active always */
608+
pcd_set_ep_rx_status(USB, EPindex, USB_EP_RX_VALID);
609+
}
603610
}
604611
}
605612

@@ -881,7 +888,8 @@ bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc
881888
(void)rhport;
882889
uint8_t const epnum = dcd_ep_alloc(p_endpoint_desc->bEndpointAddress, p_endpoint_desc->bmAttributes.xfer);
883890
uint8_t const dir = tu_edpt_dir(p_endpoint_desc->bEndpointAddress);
884-
const uint16_t buffer_size = pcd_aligned_buffer_size(tu_edpt_packet_size(p_endpoint_desc));
891+
const uint16_t packet_size = tu_edpt_packet_size(p_endpoint_desc);
892+
const uint16_t buffer_size = pcd_aligned_buffer_size(packet_size);
885893
uint16_t pma_addr;
886894
uint32_t wType;
887895

@@ -921,6 +929,7 @@ bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc
921929
if( (dir == TUSB_DIR_IN) || (wType == USB_EP_ISOCHRONOUS) )
922930
{
923931
*pcd_ep_tx_address_ptr(USB, epnum) = pma_addr;
932+
pcd_set_ep_tx_bufsize(USB, epnum, buffer_size);
924933
pcd_clear_tx_dtog(USB, epnum);
925934
}
926935

@@ -948,7 +957,7 @@ bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc
948957
}
949958
}
950959

951-
xfer_ctl_ptr(p_endpoint_desc->bEndpointAddress)->max_packet_size = buffer_size;
960+
xfer_ctl_ptr(p_endpoint_desc->bEndpointAddress)->max_packet_size = packet_size;
952961
xfer_ctl_ptr(p_endpoint_desc->bEndpointAddress)->epnum = epnum;
953962

954963
return true;

src/portable/st/stm32_fsdev/dcd_stm32_fsdev_pvt_st.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,13 @@ TU_ATTR_ALWAYS_INLINE static inline void pcd_set_ep_rx_cnt(USB_TypeDef * USBx,
281281
*reg = (uint16_t) (*reg & (uint16_t) ~0x3FFU) | (wCount & 0x3FFU);
282282
}
283283

284+
TU_ATTR_ALWAYS_INLINE static inline void pcd_set_ep_tx_bufsize(USB_TypeDef * USBx, uint32_t bEpNum, uint32_t wCount)
285+
{
286+
__IO uint16_t *pdwReg = pcd_ep_tx_cnt_ptr((USBx),(bEpNum));
287+
wCount = pcd_aligned_buffer_size(wCount);
288+
pcd_set_ep_cnt_reg(pdwReg, wCount);
289+
}
290+
284291
TU_ATTR_ALWAYS_INLINE static inline void pcd_set_ep_rx_bufsize(USB_TypeDef * USBx, uint32_t bEpNum, uint32_t wCount)
285292
{
286293
__IO uint16_t *pdwReg = pcd_ep_rx_cnt_ptr((USBx),(bEpNum));
@@ -310,6 +317,7 @@ TU_ATTR_ALWAYS_INLINE static inline void pcd_set_ep_tx_status(USB_TypeDef * USBx
310317
{
311318
regVal ^= USB_EPTX_DTOG2;
312319
}
320+
313321
regVal |= USB_EP_CTR_RX|USB_EP_CTR_TX;
314322
pcd_set_endpoint(USBx, bEpNum, regVal);
315323
} /* pcd_set_ep_tx_status */
@@ -337,6 +345,7 @@ TU_ATTR_ALWAYS_INLINE static inline void pcd_set_ep_rx_status(USB_TypeDef * USBx
337345
{
338346
regVal ^= USB_EPRX_DTOG2;
339347
}
348+
340349
regVal |= USB_EP_CTR_RX|USB_EP_CTR_TX;
341350
pcd_set_endpoint(USBx, bEpNum, regVal);
342351
} /* pcd_set_ep_rx_status */

0 commit comments

Comments
 (0)