Skip to content

drivers: usb: udc: max32: Fix MAX32 udc event handling - #1

Open
Brandon-Hurst wants to merge 2 commits into
adafruit:circuitpython-v4.3.0from
Brandon-Hurst:cktpy/max32/udc-fixes
Open

drivers: usb: udc: max32: Fix MAX32 udc event handling#1
Brandon-Hurst wants to merge 2 commits into
adafruit:circuitpython-v4.3.0from
Brandon-Hurst:cktpy/max32/udc-fixes

Conversation

@Brandon-Hurst

Copy link
Copy Markdown

Upstream PR

This PR is a duplicate of zephyrproject-rtos#104103 for Circuitpython's fork.

Description

MAX32 USB had some functions in ISR context allocating memory & acquiring mutexes. This PR fixes this by separating the transfer completion events into ISR-context and thread-context steps using the message queue. Additionally, some apparent swapping of devicetree configuration for in/out endpoints and configuration structs is resolved. Finally, handling of deferred endpoint transfers was added.

Commit 1:

  • Rename UDC_MAX32_EVT_XFER to UDC_MAX32_EVT_START_XFER
  • Add MAX32 UDC events for XFER_IN_DONE and XFER_OUT_DONE
  • Refactor xfer_in/out callbacks to only submit messages to a message queue
  • Provide xfer_in_Done and xfer_out_done to handle transfer completions from UDC thread context.
  • Add XFER_IN_DONE and XFER_OUT_DONE events to thread handler
  • Fix swapping in devicetree macros of num_of_in_eps / num_of_out_eps and ep_cfg_in / ep_cfg_out

Commit 2:

  • Add WARN-level logging for deferred transfers on a busy endpoint
  • Add guard to only submit resume events when the device was suspended
  • Handle deferred transfers on transfer completion of the busy endpoint

Functional Tests

Tested the cdc_acm sample and the mass sample with the FAT filesystem successfully.

Twister Tests

❯ ./scripts/twister -p apard32690/max32690/m4 -b \
  -T samples/subsys/usb/ \
  -T tests/drivers/udc/
ZEPHYR_BASE unset, using "/home/bjh/workspace/z/zephyr-main/zephyr"
Renaming previous output directory to /home/bjh/workspace/z/zephyr-main/zephyr/twister-out.1
INFO    - Using Ninja..
INFO    - Zephyr version: v4.3.0-6204-g5fb7cb3094d0
INFO    - Using 'zephyr' toolchain.
INFO    - Building initial testsuite list...
INFO    - Built testsuite list in 0.02 seconds
INFO    - Writing JSON report /home/bjh/workspace/z/zephyr-main/zephyr/twister-out/testplan.json
INFO    - JOBS: 32
INFO    - Adding tasks to the queue...
INFO    - Added initial list of jobs to queue
INFO    - Total complete:   20/  20  100%  built (not run):   17, filtered:   28, failed:    0, error:    0
INFO    - 45 test scenarios (45 configurations) selected, 28 configurations filtered (25 by static filter, 3 at runtime).
INFO    - 0 of 17 executed test configurations passed (0.00%), 17 built (not run), 0 failed, 0 errored, with no warnings in 169.26 seconds.
INFO    - 0 test configurations executed on platforms, 17 test configurations were only built.
INFO    - Saving reports...
INFO    - Writing JSON report /home/bjh/workspace/z/zephyr-main/zephyr/twister-out/twister.json
INFO    - Writing xunit report /home/bjh/workspace/z/zephyr-main/zephyr/twister-out/twister.xml...
INFO    - Writing xunit report /home/bjh/workspace/z/zephyr-main/zephyr/twister-out/twister_report.xml...
INFO    - Run completed

Issue was resolved where deferred transfers due to a busy
endpoint were not being resolved. This was causing some trasnfers
to never complete.

Add the following to the xfer_in_done and xfer_out_done
event functions:

```C
/* Start any transfer deferred while this endpoint was busy */
if (ep_cfg->addr != USB_CONTROL_EP_OUT && udc_buf_peek(ep_cfg) != NULL) {
        udc_event_xfer_out(dev, ep_cfg);
}
```

Logging was also added to warn of any deferred ep transfers.

Signed-off-by: Brandon Hurst <brandon.hurst97@gmail.com>
MAX32 USB had some functions in ISR context allocating memory &
acquiring mutexes. This commit fixes this by separating the
transfer completion events into ISR-safe / non ISR-safe steps.

Additionally, some apparent swapping of devicetree configuration
for in/out endpoints is resolved.

- Rename UDC_MAX32_EVT_XFER to UDC_MAX32_EVT_START_XFER
- Add MAX32 UDC events for XFER_IN_DONE and XFER_OUT_DONE
- Refactor xfer_in/out callbacks to only submit messages to a
message queue.
- Provide xfer_in_Done and xfer_out_done to handle transfer
completions from UDC thread context.
- Add XFER_IN_DONE and XFER_OUT_DONE events to thread handler
- Fix swapping in devicetree macros of num_of_in_eps /
num_of_out_eps and ep_cfg_in / ep_cfg_out

Signed-off-by: Brandon Hurst <brandon.hurst97@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant