USB: Check the peripheral frequency for a stable connection #884
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes an issue that is mainly only found on the V2 clocking API.
With the V2 clocking API giving the user the freedom to configure clocks as they wish, the USB peripheral can be clocked to any frequency. This causes massive stability issues.
Therefore, the USBBus constructor now forces the user to provide a 48Mhz constructor in the UsbBus::new function, since this will be used by almost all users. This function returns an error if the provided USB clock Freq is not 48Mhz.
In case the user wishes to provide a faster running USB clock (GCLK_USB can run up to 60Mhz) - For the crazy reason of connecting 2 SAMx chips together over a faster USB bus, I have provided
unsafe fn UsbBus::new_unchecked
function to bypass the clock freq check