Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STM32 PCD negative numbers issue #6609

Merged
merged 5 commits into from Apr 16, 2018
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions targets/TARGET_STM/TARGET_STM32F7/device/stm32f7xx_hal_pcd.c
Expand Up @@ -145,7 +145,7 @@ HAL_StatusTypeDef HAL_PCD_Init(PCD_HandleTypeDef *hpcd)

// MBED: added
if(hpcd->State == HAL_PCD_STATE_RESET)
{
{
/* Allocate lock resource and initialize it */
hpcd->Lock = HAL_UNLOCKED;
for (i = 0; i < hpcd->Init.dev_endpoints ; i++)
Expand Down Expand Up @@ -1300,14 +1300,14 @@ static HAL_StatusTypeDef PCD_WriteEmptyTxFifo(PCD_HandleTypeDef *hpcd, uint32_t
{
USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
USB_OTG_EPTypeDef *ep;
int32_t len = 0;
uint32_t len;
uint32_t len32b;
uint32_t fifoemptymsk = 0;

ep = &hpcd->IN_ep[epnum];
len = ep->xfer_len - ep->xfer_count;

if (len > ep->maxpacket)
if (((int32_t)len > 0) && (len > ep->maxpacket))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep original code

{
len = ep->maxpacket;
}
Expand All @@ -1322,7 +1322,7 @@ static HAL_StatusTypeDef PCD_WriteEmptyTxFifo(PCD_HandleTypeDef *hpcd, uint32_t
/* Write the FIFO */
len = ep->xfer_len - ep->xfer_count;

if (len > ep->maxpacket)
if (((int32_t)len > 0) && (len > ep->maxpacket))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep original code

{
len = ep->maxpacket;
}
Expand All @@ -1334,7 +1334,7 @@ static HAL_StatusTypeDef PCD_WriteEmptyTxFifo(PCD_HandleTypeDef *hpcd, uint32_t
ep->xfer_count += len;
}

if(len <= 0)
if ((int32_t)len <= 0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep original code

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeromecoutant No, I don't think that'll work.

Since len is an uint32_t now, it cannot be less than zero.

That is why I added checks for (int32_t)len > 0) because if ep->xfer_count is greater than ep->xfer_len then len would have its high bit set, and enters the scope that sets len = ep->maxpacket; which is incorrect. The high bit should be preserved so that atomic_clr_u32 is called as expected.

If I make those changes as you suggest, that would change the behavior of the code.

Is my understanding/interpretation wrong?

{
fifoemptymsk = 0x1 << epnum;
atomic_clr_u32(&USBx_DEVICE->DIEPEMPMSK, fifoemptymsk); // MBED: changed
Expand Down