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

cpu/stm32/usbdev_fs: fix ep registration and EP_REG assignments [backport 2023.04] #19462

Merged

Conversation

dylad
Copy link
Member

@dylad dylad commented Apr 10, 2023

Contribution description

This backport PR provides two fixes for the usbdev_fs driver:

Fix endpoints registration
Fix assignment of toggleable bits in EP_REG(x) registers

These bugs were encountered with the USBUS MSC implementation.

Regarding the endpoints registration:

For the usbdev_fs peripheral, IN and OUT endpoints of the same index must have the same type.
For instance, if EP1 OUT is a bulk endpoint, EP1 IN must either be unused or used as bulk too but it cannot be used as interrupt or isochronous.
With the previous check, the following registration pattern (EP OUT Bulk -> EP IN Interrupt -> EP IN Bulk) would assign both EP OUT Bulk and EP IN Interrupt to same endpoint index. So the configuration would be broken.
Applying the same registration pattern with this patch would now produce EP OUT Bulk -> 1 / EP IN Interrupt -> 2 / EP IN Bulk 1. Which is a working configuration for this IP.

and for the second fix:

EP_REG(x) registers have a total of 6 toggleable bits. Those bits can only be toggled if we write a one to it, otherwise writing a zero has no effect
This commit fixes all the access to these registers to prevent from modifying these bits when not needed.
Without this patch, the endpoint status (VALID / NACK / STALL) can be erroneously modify because bits are not cleared when assigning the new content to the register and thus make the bits toggle and change values.

Testing procedure

See #19460

Issues/PRs references

#19460

dylad added 2 commits April 10, 2023 21:18
For the usbdev_fs peripheral, IN and OUT endpoints of the same index must have the same type.
For instance, if EP1 OUT is a bulk endpoint, EP1 IN must either be unused or used as bulk too but it cannot be used as interrupt or isochronous.
With the previous check, the following registration pattern (EP OUT Bulk -> EP IN Interrupt -> EP IN Bulk) would assign both EP OUT Bulk and EP IN Interrupt to same endpoint index. So the configuration would be broken.
Applying the same registration pattern with this patch would now produce EP OUT Bulk -> 1 / EP IN Interrupt -> 2 / EP IN Bulk 1. Which is a working configuration for this IP

Signed-off-by: Dylan Laduranty <dylan.laduranty@mesotic.com>
EP_REG(x) registers have a total of 6 toggleable bits. Those bits can only be toggled if we write a one to it, otherwise writing a zero has no effect
This commit fixes all the access to these registers to prevent from modifying these bits when not needed

Signed-off-by: Dylan Laduranty <dylan.laduranty@mesotic.com>
@dylad dylad added the Process: release backport Integration Process: The PR is a release backport of a change previously provided to master label Apr 10, 2023
@github-actions github-actions bot added Area: cpu Area: CPU/MCU ports Platform: ARM Platform: This PR/issue effects ARM-based platforms labels Apr 10, 2023
@dylad dylad changed the title cpu/stm32/usbdev_fs: fix ep registration and EP_REG assignments [backport] cpu/stm32/usbdev_fs: fix ep registration and EP_REG assignments [backport 2023.04] Apr 10, 2023
Copy link
Contributor

@MrKevinWeiss MrKevinWeiss left a comment

Choose a reason for hiding this comment

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

quick check for backport, looks good. ACK.

@MrKevinWeiss
Copy link
Contributor

bors merge

@bors
Copy link
Contributor

bors bot commented Apr 14, 2023

🕐 Waiting for PR status (GitHub check) to be set, probably by CI. Bors will automatically try to run when all required PR statuses are set.

@MrKevinWeiss MrKevinWeiss added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Apr 14, 2023
@riot-ci
Copy link

riot-ci commented Apr 14, 2023

Murdock results

✔️ PASSED

9311940 cpu/stm32/usbdev_fs: fix EP_REG(x) assignment for toggleable bits

Success Failures Total Runtime
6882 0 6882 10m:44s

Artifacts

@dylad
Copy link
Member Author

dylad commented Apr 14, 2023

bors cancel
bors merge

@bors
Copy link
Contributor

bors bot commented Apr 14, 2023

Build succeeded:

@bors bors bot merged commit fc46123 into RIOT-OS:2023.04-branch Apr 14, 2023
@dylad dylad deleted the backport/cpu/stm32/usbdev_fs/fixes_for_msc branch April 15, 2023 09:44
@jia200x jia200x added this to the Release 2023.04 milestone Apr 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: cpu Area: CPU/MCU ports CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: ARM Platform: This PR/issue effects ARM-based platforms Process: release backport Integration Process: The PR is a release backport of a change previously provided to master
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants