Skip to content

Usb device init: wait_us fix #13206

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 1 commit into from
Jul 1, 2020
Merged

Conversation

vvkaggarwal12
Copy link

@vvkaggarwal12 vvkaggarwal12 commented Jun 30, 2020

Summary of changes

"fixes #13203"
In usb device phy initialization, ThisThread::sleep_for changed to wait_us.
As before the usb phy is initialized, all the interrupts are disabled, so sleep_for is not supported.
USB device was not getting enumerated as a result of this delay.
Calling wait_us will resolve the issue.

Impact of changes

Migration actions required

Documentation

None


Pull request type

[X] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[] No Tests required for this change (E.g docs only update)
[X] Covered by existing mbed-os tests (Greentea or Unittest)
[] Tests / results supplied as part of this PR

Reviewers


@0xc0170 0xc0170 changed the title Usb device fix Usb device init: wait_us fix Jun 30, 2020
@@ -411,7 +411,7 @@ void USBPhyHw::init(USBPhyEvents *events)
LPC_PINCON->PINSEL4 |= 0x00040000;

// Connect must be low for at least 2.5uS
ThisThread::sleep_for(300);
wait_us(300000);
Copy link
Contributor

Choose a reason for hiding this comment

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

I previously only read a comment about 2.5uS and we had there 300 ms delay? This is quite a long delay. Wouldn't be sufficient to just a spin for 1ms?

Copy link
Contributor

Choose a reason for hiding this comment

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

900 should be sufficient based on the comment

Copy link
Author

Choose a reason for hiding this comment

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

900 should be sufficient based on the comment

Yes 900us should be sufficient. Previously it was 300ms, so given that much.
Updated the pull request with 900us.

Copy link
Contributor

@kjbracey kjbracey Jun 30, 2020

Choose a reason for hiding this comment

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

If interrupts are disabled, shouldn't really be waiting for 900us either. That's enough to cause many characters of serial loss.

But why do you think interrupts are disabled? Where is this being called from? (If interrupts were disabled, I would expect the sleep_for to have generated an assert, not just "USB device was not getting enumerated" as described.

And where did "900us" come from? Only comment I can see says "2.5us".

Copy link
Author

Choose a reason for hiding this comment

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

Have a look at issue number:
#13203
Earlier delay given was 300ms. As mentioned in the comments, i given 900us.

Copy link
Author

Choose a reason for hiding this comment

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

Should I implement mutex solution for this and give a pull request?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll ask Russ why USBDevice lock implements critical section, will get back

Copy link
Contributor

@0xc0170 0xc0170 Jun 30, 2020

Choose a reason for hiding this comment

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

Thinking about this. as the comment states 2.5us minimal, therefore waiting here 3us should be sufficient (there could be just typo and 300ms applied instead earlier).

The USB Device should be interrupt safe, thus locking the way it is. I propose to wait 5us to be on the safe side (stating that in the commit message to be clear).

Copy link
Author

Choose a reason for hiding this comment

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

Thinking about this. as the comment states 2.5us minimal, therefore waiting here 3us should be sufficient (there could be just typo and 300ms applied instead earlier).

The USB Device should be interrupt safe, thus locking the way it is. I propose to wait 5us to be on the safe side (stating that in the commit message to be clear).

I will change the delay to 5us then.

Copy link
Author

Choose a reason for hiding this comment

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

I'll ask Russ why USBDevice lock implements critical section, will get back

Ok martin, Could you please update here, if mutex needs to be implemented for this.

@ciarmcom ciarmcom requested review from maclobdell and a team June 30, 2020 13:00
@ciarmcom
Copy link
Member

@vvkaggarwal12, thank you for your changes.
@maclobdell @ARMmbed/mbed-os-maintainers please review.

kjbracey
kjbracey previously approved these changes Jul 1, 2020
Copy link
Contributor

@kjbracey kjbracey left a comment

Choose a reason for hiding this comment

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

Fine, but doesn't need to be 5 commits :)

@mergify mergify bot added needs: CI and removed needs: review labels Jul 1, 2020
0xc0170
0xc0170 previously approved these changes Jul 1, 2020
@0xc0170
Copy link
Contributor

0xc0170 commented Jul 1, 2020

@vvkaggarwal12 if you can squash all into one commit ? I can run CI asap

@mergify mergify bot dismissed stale reviews from kjbracey and 0xc0170 July 1, 2020 07:43

Pull request has been modified.

@vvkaggarwal12
Copy link
Author

@vvkaggarwal12 if you can squash all into one commit ? I can run CI asap

@0xc0170 squashed all commit into single.

@0xc0170
Copy link
Contributor

0xc0170 commented Jul 1, 2020

CI started

@mbed-ci
Copy link

mbed-ci commented Jul 1, 2020

Test run: SUCCESS

Summary: 6 of 6 test jobs passed
Build number : 1
Build artifacts

@0xc0170 0xc0170 added the release-type: patch Indentifies a PR as containing just a patch label Jul 1, 2020
@0xc0170 0xc0170 merged commit ffeb926 into ARMmbed:master Jul 1, 2020
@mergify mergify bot removed the ready for merge label Jul 1, 2020
rajkan01 pushed a commit to rajkan01/mbed-os that referenced this pull request Jul 6, 2020
@adbridge adbridge added release-version: 6.2.0 Release-pending and removed release-type: patch Indentifies a PR as containing just a patch Release-pending labels Jul 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mbed LPC17xx USB device not working
7 participants