Skip to content

STM32 USB fixes #7322

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

Merged
merged 5 commits into from
Jul 2, 2018
Merged

Conversation

c1728p9
Copy link
Contributor

@c1728p9 c1728p9 commented Jun 26, 2018

Description

This PR addresses issues found by upcoming USB tests in #6880. It contains a working implementation of endpoint abort along with other fixes.

Pull request type

[x] Fix
[ ] Refactor
[ ] New target
[ ] Feature
[ ] Breaking change

Revert the patch "Create HAL_PCD_EP_Abort" in preparation for an
alternate fix.
@c1728p9
Copy link
Contributor Author

c1728p9 commented Jun 26, 2018

The commit 6ab466e contains the ST cube changes that this PR requires.

The commit 0967bb2 also contains ST cube changes for a problem I noticed, but was not causing test failures and is not needed to pass testing.

@c1728p9 c1728p9 requested review from jeromecoutant, fkjagodzinski and bruman01 and removed request for bruman01 June 26, 2018 00:07
@jeromecoutant
Copy link
Collaborator

@bcostm @jamike

Copy link
Contributor

@bcostm bcostm left a comment

Choose a reason for hiding this comment

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

Thanks for all these changes 👍

}

/* stop the transfer */
while (count++ < 200000U)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you use a #define for this value ? And also add a comment explaining the approx timeout delay if you know it ?

Why you didn't use the same timeout method as done in other ST HAL files (i.e. using HAL_GetTick) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add a comment here. In theory this loop should should execute at most once and that is when a setup packet is received. After the setup packet has been received the data (or status) phase of the control transfer can be will be naked which prevents further packet reception. Maybe its best to update this to remove the loop entirely.

I used a while loop with a count rather than HAL_GetTick to keep consistent with the other USB code (see snippit below). I can update this to use HAL_GetTick if you would like.

do
{
if (++count > 200000U)
{
return HAL_TIMEOUT;
}
}
while ((USBx->GRSTCTL & USB_OTG_GRSTCTL_TXFFLSH) == USB_OTG_GRSTCTL_TXFFLSH);

Copy link
Contributor

Choose a reason for hiding this comment

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

No that's ok. Since the RTC issues due to the HAL_GetTick function, I am not very confident to use it...

if (endpoint & 0x80) {
HAL_PCDEx_SetTxFiFo(&hpcd, endpoint & 0x7f, (max_packet / 4) + 1);
HAL_PCDEx_SetTxFiFo(&hpcd, endpoint & 0x7f, 17);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add the comment you put in the commit message here also ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do

c1728p9 added 4 commits June 26, 2018 15:19
Update the patch "Create HAL_PCD_EP_Abort" to fix bugs.
This patch adds the low level functions USB_EPStopXfer, USB_EPSetNak,
USB_EPClearNak and the high level function HAL_PCD_EP_Abort so that
transfers can be stopped.

The functions USB_EPSetNak and USB_EPClearNak allow nak to be enabled
or disabled for an endpoint, preventing or allowing further transfers.

The function USB_EPStopXfer stops pending reads and writes started by
USB_EPStartXfer along with clearing and masking any interrupts enabled
by USB_EPStartXfer.

The function HAL_PCD_EP_Abort aborts any transfers on the given
endpoint. When this function completes the transfer interrupt
is guarenteed not to fire for this endpoint. Furthermore, the size
of data transferred during an aborted read can be found by calling
the function HAL_PCD_EP_GetRxCount.

Other notes on this Change:

1.
Prior to this patch the interrupt USB_OTG_DOEPINT_EPDISD was not
handled. When an OUT endpoint was disabled this interrupt occurred
causing the CPU to get stuck repeatedly handling this interrupt. This
is because this interrupt was unmasked but nothing cleared this
interrupt. This patch also adds code to handle and clear this
interrupt to prevent a lockup.

2.
Stopping a transfer on an OUT endpoint requires global nak OUT to
be in effect. Even with this being done, having entries in the rx fifo
prevented an OUT endpoint from being disabled. This behavior is not
mentioned in the Reference Manual.
Make use of the added function HAL_PCD_EP_Abort to implement
endpoint_abort.
Also always use the max endpoint size for SetTxFifo
since re-configuring fifos when endpoints are added or removed
causes tests to fail.
When activating an endpoint assign new data rather than ORing
data to it. This ensures that values set from the previous use
do not effect the current configuration.
@cmonr
Copy link
Contributor

cmonr commented Jun 28, 2018

@bcostm @jeromecoutant @fkjagodzinski If y'all could re-review.

Copy link
Member

@fkjagodzinski fkjagodzinski left a comment

Choose a reason for hiding this comment

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

👍 for very clear an verbose commit messages.

@cmonr
Copy link
Contributor

cmonr commented Jun 30, 2018

/morph build

@mbed-ci
Copy link

mbed-ci commented Jun 30, 2018

Build : SUCCESS

Build number : 2482
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/7322/

Triggering tests

/morph test
/morph uvisor-test
/morph export-build
/morph mbed2-build

@mbed-ci
Copy link

mbed-ci commented Jun 30, 2018

@mbed-ci
Copy link

mbed-ci commented Jun 30, 2018

@0xc0170 0xc0170 merged commit 9165547 into ARMmbed:feature-hal-spec-usb-device Jul 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants