Skip to content

Commit 430784b

Browse files
author
Paul Thompson
committed
Initial work was for unsigned-signed comparison fix. Current work fixes negative number issues
Compile: stm32f7xx_hal_pcd.c ../targets/TARGET_STM/TARGET_STM32F7/device/stm32f7xx_hal_pcd.c: In function 'PCD_WriteEmptyTxFifo': ../targets/TARGET_STM/TARGET_STM32F7/device/stm32f7xx_hal_pcd.c:1310:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] if (len > ep->maxpacket) ^ ../targets/TARGET_STM/TARGET_STM32F7/device/stm32f7xx_hal_pcd.c:1325:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] if (len > ep->maxpacket) ^
1 parent a463b07 commit 430784b

File tree

1 file changed

+42
-36
lines changed

1 file changed

+42
-36
lines changed

targets/TARGET_STM/TARGET_STM32F7/device/stm32f7xx_hal_pcd.c

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ HAL_StatusTypeDef HAL_PCD_Init(PCD_HandleTypeDef *hpcd)
145145

146146
// MBED: added
147147
if(hpcd->State == HAL_PCD_STATE_RESET)
148-
{
148+
{
149149
/* Allocate lock resource and initialize it */
150150
hpcd->Lock = HAL_UNLOCKED;
151151
for (i = 0; i < hpcd->Init.dev_endpoints ; i++)
@@ -1298,50 +1298,56 @@ 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-
int32_t len = 0;
1304-
uint32_t len32b;
1305-
uint32_t fifoemptymsk = 0;
1306-
1307-
ep = &hpcd->IN_ep[epnum];
1308-
len = ep->xfer_len - ep->xfer_count;
1309-
1310-
if (len > ep->maxpacket)
1311-
{
1312-
len = ep->maxpacket;
1313-
}
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;
13141306

1307+
ep = &hpcd->IN_ep[epnum];
13151308

1316-
len32b = (len + 3) / 4;
1309+
if (ep->xfer_len >= ep->xfer_count)
1310+
{
1311+
len = ep->xfer_len - ep->xfer_count;
13171312

1318-
while ( (USBx_INEP(epnum)->DTXFSTS & USB_OTG_DTXFSTS_INEPTFSAV) > len32b &&
1319-
ep->xfer_count < ep->xfer_len &&
1320-
ep->xfer_len != 0)
1321-
{
1322-
/* Write the FIFO */
1323-
len = ep->xfer_len - ep->xfer_count;
1313+
if (len > ep->maxpacket)
1314+
{
1315+
len = ep->maxpacket;
1316+
}
13241317

1325-
if (len > ep->maxpacket)
1326-
{
1327-
len = ep->maxpacket;
1328-
}
1329-
len32b = (len + 3) / 4;
1318+
len32b = (len + 3U) / 4U;
13301319

1331-
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 != 0U))
1323+
{
1324+
/* Write the FIFO */
1325+
if (ep->xfer_len >= ep->xfer_count)
1326+
{
1327+
len = ep->xfer_len - ep->xfer_count;
13321328

1333-
ep->xfer_buff += len;
1334-
ep->xfer_count += len;
1335-
}
1329+
if (len > ep->maxpacket)
1330+
{
1331+
len = ep->maxpacket;
1332+
}
1333+
len32b = (len + 3U) / 4U;
13361334

1337-
if(len <= 0)
1338-
{
1339-
fifoemptymsk = 0x1 << epnum;
1340-
atomic_clr_u32(&USBx_DEVICE->DIEPEMPMSK, fifoemptymsk); // MBED: changed
1335+
USB_WritePacket(USBx, ep->xfer_buff, epnum, len, hpcd->Init.dma_enable);
13411336

1342-
}
1337+
ep->xfer_buff += len;
1338+
ep->xfer_count += len;
1339+
}
1340+
}
1341+
}
1342+
else
1343+
{
1344+
fifoemptymsk = 0x1U << epnum;
1345+
/* MBED */
1346+
atomic_clr_u32(&USBx_DEVICE->DIEPEMPMSK, fifoemptymsk);
1347+
/* MBED */
1348+
}
13431349

1344-
return HAL_OK;
1350+
return HAL_OK;
13451351
}
13461352

13471353
/**

0 commit comments

Comments
 (0)