F7_HAL/pcd: Optimise writing to USB FIFO to fill it as much as possible.
The existing HAL code had two issues: - It used < instead of <= to compare INEPTFSAV with len32b, which meant that data would not be written to the FIFO if there was exactly enough room for the packet (it would require enough room plus one additional FIFO slot). So for IN endpoints that had a FIFO size the same as the maximum packet size, packets of maximum size could never be written. - If the write loop went around again it would use the old len32b to check if there was enough space, thereby missing some opportunities to write packets that were smaller than the previous len32b. This patch fixes these two issues.
This commit is contained in:
parent
fdb18f4f2e
commit
d27bef17c2
@ -1256,6 +1256,7 @@ static HAL_StatusTypeDef PCD_WriteEmptyTxFifo(PCD_HandleTypeDef *hpcd, uint32_t
|
||||
uint32_t fifoemptymsk = 0;
|
||||
|
||||
ep = &hpcd->IN_ep[epnum];
|
||||
#if 0
|
||||
len = ep->xfer_len - ep->xfer_count;
|
||||
|
||||
if (len > ep->maxpacket)
|
||||
@ -1285,6 +1286,37 @@ static HAL_StatusTypeDef PCD_WriteEmptyTxFifo(PCD_HandleTypeDef *hpcd, uint32_t
|
||||
ep->xfer_count += len;
|
||||
}
|
||||
|
||||
#else
|
||||
/* dpgeorge: modified above loop to:
|
||||
* - allow to write the packet in the case it exactly fills the FIFO
|
||||
* - recompute len32b before each check of this value against FIFO free space
|
||||
*/
|
||||
for (;;)
|
||||
{
|
||||
len = ep->xfer_len - ep->xfer_count;
|
||||
if (len <= 0U)
|
||||
{
|
||||
/* Finished sending all data */
|
||||
break;
|
||||
}
|
||||
if (len > ep->maxpacket)
|
||||
{
|
||||
len = ep->maxpacket;
|
||||
}
|
||||
|
||||
len32b = (len + 3U) / 4U;
|
||||
if (len32b > (USBx_INEP(epnum)->DTXFSTS & USB_OTG_DTXFSTS_INEPTFSAV))
|
||||
{
|
||||
/* No room left in FIFO */
|
||||
break;
|
||||
}
|
||||
|
||||
USB_WritePacket(USBx, ep->xfer_buff, epnum, len, hpcd->Init.dma_enable);
|
||||
ep->xfer_buff += len;
|
||||
ep->xfer_count += len;
|
||||
}
|
||||
#endif
|
||||
|
||||
if(len <= 0)
|
||||
{
|
||||
fifoemptymsk = 0x1 << epnum;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user