Skip to content

Commit 8f4a5e2

Browse files
author
Paul Thompson
committed
Revert to original fix concentrating on type correctness
1 parent 430784b commit 8f4a5e2

File tree

1 file changed

+38
-41
lines changed

1 file changed

+38
-41
lines changed

targets/TARGET_STM/TARGET_STM32F7/device/stm32f7xx_hal_pcd.c

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,56 +1298,53 @@ PCD_StateTypeDef HAL_PCD_GetState(PCD_HandleTypeDef *hpcd)
12981298
*/
12991299
static HAL_StatusTypeDef PCD_WriteEmptyTxFifo(PCD_HandleTypeDef *hpcd, uint32_t epnum)
13001300
{
1301-
USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
1302-
USB_OTG_EPTypeDef *ep;
1303-
uint32_t len;
1304-
uint32_t len32b;
1305-
uint32_t fifoemptymsk = 0U;
1306-
1307-
ep = &hpcd->IN_ep[epnum];
1308-
1309-
if (ep->xfer_len >= ep->xfer_count)
1310-
{
1311-
len = ep->xfer_len - ep->xfer_count;
1301+
USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
1302+
USB_OTG_EPTypeDef *ep;
1303+
uint32_t len;
1304+
int32_t ilen;
1305+
uint32_t len32b;
1306+
uint32_t fifoemptymsk = 0;
13121307

1313-
if (len > ep->maxpacket)
1314-
{
1315-
len = ep->maxpacket;
1316-
}
1308+
ep = &hpcd->IN_ep[epnum];
1309+
ilen = ep->xfer_len - ep->xfer_count;
1310+
len = ilen;
13171311

1318-
len32b = (len + 3U) / 4U;
1312+
if ((ilen > 0) && (len > ep->maxpacket))
1313+
{
1314+
len = ep->maxpacket;
1315+
}
13191316

1320-
while (((USBx_INEP(epnum)->DTXFSTS & USB_OTG_DTXFSTS_INEPTFSAV) > len32b) &&
1321-
(ep->xfer_count < ep->xfer_len) &&
1322-
(ep->xfer_len != 0U))
1323-
{
1324-
/* Write the FIFO */
1325-
if (ep->xfer_len >= ep->xfer_count)
1326-
{
1327-
len = ep->xfer_len - ep->xfer_count;
13281317

1329-
if (len > ep->maxpacket)
1330-
{
1331-
len = ep->maxpacket;
1332-
}
1333-
len32b = (len + 3U) / 4U;
1318+
len32b = (len + 3) / 4;
13341319

1335-
USB_WritePacket(USBx, ep->xfer_buff, epnum, len, hpcd->Init.dma_enable);
1320+
while ( (USBx_INEP(epnum)->DTXFSTS & USB_OTG_DTXFSTS_INEPTFSAV) > len32b &&
1321+
ep->xfer_count < ep->xfer_len &&
1322+
ep->xfer_len != 0)
1323+
{
1324+
/* Write the FIFO */
1325+
ilen = ep->xfer_len - ep->xfer_count;
1326+
len = ilen;
13361327

1337-
ep->xfer_buff += len;
1338-
ep->xfer_count += len;
1339-
}
1340-
}
1341-
}
1342-
else
1328+
if ((ilen > 0) && (len > ep->maxpacket))
13431329
{
1344-
fifoemptymsk = 0x1U << epnum;
1345-
/* MBED */
1346-
atomic_clr_u32(&USBx_DEVICE->DIEPEMPMSK, fifoemptymsk);
1347-
/* MBED */
1330+
len = ep->maxpacket;
13481331
}
1332+
len32b = (len + 3) / 4;
1333+
1334+
USB_WritePacket(USBx, ep->xfer_buff, epnum, len, hpcd->Init.dma_enable);
1335+
1336+
ep->xfer_buff += len;
1337+
ep->xfer_count += len;
1338+
}
13491339

1350-
return HAL_OK;
1340+
if(ilen <= 0)
1341+
{
1342+
fifoemptymsk = 0x1 << epnum;
1343+
atomic_clr_u32(&USBx_DEVICE->DIEPEMPMSK, fifoemptymsk); // MBED: changed
1344+
1345+
}
1346+
1347+
return HAL_OK;
13511348
}
13521349

13531350
/**

0 commit comments

Comments
 (0)