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 #19460

Merged
merged 2 commits into from
Apr 9, 2023

Conversation

dylad
Copy link
Member

@dylad dylad commented Apr 7, 2023

Contribution description

This 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

This can be tested with tests/usbus_msc on any board using this usbdev_fs driver.
It is easier to test this PR with #19443 alongside. Then the following would be enough:
CFLAGS='-DSECTOR_COUNT=64' USEMODULE='mtd_emulated' make -j8 BOARD=p-nucleo-wb55 -C tests/usbus_msc flash

Otherwise this can also be tested by attaching a SPI<->SDCARD adapter.

Issues/PRs references

None.

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 <[email protected]>
@dylad dylad added the Process: needs backport Integration Process: The PR is required to be backported to a release or feature branch label Apr 7, 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 7, 2023
@dylad dylad added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Apr 7, 2023
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 <[email protected]>
@dylad dylad force-pushed the pr/cpu/stm32/usbdev_fs/fixes_for_msc branch from c03b951 to 701242d Compare April 7, 2023 20:41
@riot-ci
Copy link

riot-ci commented Apr 7, 2023

Murdock results

✔️ PASSED

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

Success Failures Total Runtime
6882 0 6882 09m:34s

Artifacts

Copy link
Contributor

@gschorcht gschorcht left a comment

Choose a reason for hiding this comment

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

The changes make sense and are working, tested with STMF32F303ZE.

@gschorcht gschorcht added the Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) label Apr 8, 2023
@gschorcht
Copy link
Contributor

bors merge

@bors
Copy link
Contributor

bors bot commented Apr 9, 2023

Build succeeded:

@bors bors bot merged commit 6f0ac0c into RIOT-OS:master Apr 9, 2023
@dylad dylad deleted the pr/cpu/stm32/usbdev_fs/fixes_for_msc branch April 10, 2023 12:08
bors bot added a commit that referenced this pull request Apr 14, 2023
19462: cpu/stm32/usbdev_fs: fix ep registration and EP_REG assignments [backport 2023.04] r=dylad a=dylad


### 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

Co-authored-by: Dylan Laduranty <[email protected]>
@benpicco benpicco added this to the Release 2023.07 milestone Aug 2, 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: needs backport Integration Process: The PR is required to be backported to a release or feature branch Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants