-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Usb device init: wait_us fix #13206
Conversation
targets/TARGET_NXP/USBHAL_LPC17.cpp
Outdated
@@ -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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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".
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@vvkaggarwal12, thank you for your changes. |
There was a problem hiding this 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 :)
@vvkaggarwal12 if you can squash all into one commit ? I can run CI asap |
…for, delay given is 5us
Pull request has been modified.
7733936
to
8d1503b
Compare
@0xc0170 squashed all commit into single. |
CI started |
Test run: SUCCESSSummary: 6 of 6 test jobs passed |
Usb device init: wait_us fix
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
Test results
Reviewers