drivers: usb: udc: Add SAM USBHS driver#101731
drivers: usb: udc: Add SAM USBHS driver#101731kartben merged 5 commits intozephyrproject-rtos:mainfrom
Conversation
|
@nandojve Nice work, thanks! I have just tested this on the CANbardo board - works without a hitch. I have yet to review the code. |
Hi @henrikbrixandersen , Nice to read! Don't waist time reviewing the code yet. I will do some rewriting. I notice that 1 line of code can change quite lot the performance so it needs some restructure. However, it is always nice to share because someone can always find some spot. |
|
@nandojve Feel free to cherry-pick c5e9ee0 (from https://github.com/henrikbrixandersen/zephyr/tree/pr_101731_canbardo) on top of your branch. This will aid me in verifying your changes. |
I'll pick it! |
db8f576 to
54d575b
Compare
|
The following west manifest projects have changed revision in this Pull Request:
✅ All manifest checks OK Note: This message is automatically posted and updated by the Manifest GitHub Action. |
54d575b to
6822345
Compare
f5d374e to
386fe68
Compare
| - "fifo": Dual-Port RAM (DPRAM) for endpoint FIFOs | ||
|
|
||
| The SAM USBHS has 10 hardware endpoints (EP0-EP9). EP0 is the | ||
| bidirectional control endpoint. The remaining endpoints are |
There was a problem hiding this comment.
There is nothing like "bidirectional control endpoint" in USB spec. I see it used more often, and it is really annoying. Please do not use it in the code or devicetree comments.
There was a problem hiding this comment.
dropped bidirectional word
| num-bidir-endpoints: | ||
| const: 1 | ||
| description: | | ||
| Number of bidirectional endpoints. For SAM USBHS, only EP0 is truly | ||
| bidirectional. Non-EP0 endpoints are direction-constrained by hardware. |
There was a problem hiding this comment.
You do not need this property, include usb-controller.yaml instead. A USB device must have control IN/OUT endpoints.
There was a problem hiding this comment.
dropped num-bidir-endpoints (num of bidirectional endpoints). Almost (if not) all drivers are using it include the driver you wrote for sam0.
| zephyr_library_sources_ifdef(CONFIG_UDC_RENESAS_RA udc_renesas_ra.c) | ||
| zephyr_library_sources_ifdef(CONFIG_UDC_MAX32 udc_max32.c) | ||
| zephyr_library_sources_ifdef(CONFIG_UDC_SAM0 udc_sam0.c) | ||
| zephyr_library_sources_ifdef(CONFIG_UDC_SAM_USBHS udc_sam_usbhs.c) |
There was a problem hiding this comment.
Fixes: #74663
Please remove it from commit message.
There was a problem hiding this comment.
This is how we link a issue to a PR. It is documented in adding links. This is Zephyr only and it is correct.
|
rebase to solve conflicts after #103703 |
|
I tested it with sam_e70_xplained, and it does not seem to work. Default build does get in the address state, and not able to perform any control transfer to the host. Forced to the full-speed, the controller seems to work, but fails to pass test 14/21. |
Add missing macros to allow same70 usbhs driver build. Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
Add Atmel SAM USBHS driver for SAM E70/S70/V70/V71 family. The driver was tested using CDC-ACM and testusb samples. Fixes: zephyrproject-rtos#74663 Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
Add USB device next (usbd) feature support for the SAM V71 Xplained Ultra board. Add the revison B board to USB sample integration platforms. Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
Add USB device next (usbd) feature support for the SAM E70 Xplained board. Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
List USB device controller as a supported feature in order to increase test coverage. Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
|
Hi @jfischer-no ,
I'm not sure why this is happening to you. I just build and run in V71 and it seems that everything is fine. [ 3958.616670] usb 9-1: new high-speed USB device number 3 using xhci_hcd
[ 3958.757712] usb 9-1: New USB device found, idVendor=2fe3, idProduct=0009, bcdDevice= 4.03
[ 3958.757718] usb 9-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 3958.757720] usb 9-1: Product: Zephyr testusb sample
[ 3958.757721] usb 9-1: Manufacturer: Zephyr Project
[ 3958.757722] usb 9-1: SerialNumber: 003134534B484A483034303130303138
[ 3958.760892] usbtest 9-1:1.0: Linux gadget zero
[ 3958.760896] usbtest 9-1:1.0: high-speed {control in/out bulk-in bulk-out} tests (+alt)
[ 3958.761116] usbtest 9-1:1.1: Linux gadget zero
[ 3958.761118] usbtest 9-1:1.1: high-speed {control in/out int-in int-out} tests (+alt)
[ 3958.761310] usbtest 9-1:1.2: Linux gadget zero
[ 3958.761313] usbtest 9-1:1.2: high-speed {control in/out iso-in iso-out} tests (+alt)
$ sudo ./testusb -v 512 -D /dev/bus/usb/009/003
./testusb: /dev/bus/usb/009/003 may see only control tests
high speed /dev/bus/usb/009/003 0
/dev/bus/usb/009/003 test 0, 0.000006 secs
/dev/bus/usb/009/003 test 1, 0.441105 secs
/dev/bus/usb/009/003 test 2, 0.418498 secs
/dev/bus/usb/009/003 test 3, 0.151261 secs
/dev/bus/usb/009/003 test 4, 0.210730 secs
/dev/bus/usb/009/003 test 5, 9.428364 secs
/dev/bus/usb/009/003 test 6, 13.415915 secs
/dev/bus/usb/009/003 test 7, 4.808556 secs
/dev/bus/usb/009/003 test 8, 6.800738 secs
/dev/bus/usb/009/003 test 9, 4.592050 secs
/dev/bus/usb/009/003 test 10, 21.002133 secs
/dev/bus/usb/009/003 test 11, 9.593004 secs
/dev/bus/usb/009/003 test 12, 10.639120 secs
/dev/bus/usb/009/003 test 13, 7.125249 secs
/dev/bus/usb/009/003 test 14, 1.500239 secs
/dev/bus/usb/009/003 test 17, 0.438577 secs
/dev/bus/usb/009/003 test 18, 0.418428 secs
/dev/bus/usb/009/003 test 19, 0.430639 secs
/dev/bus/usb/009/003 test 20, 0.410579 secs
/dev/bus/usb/009/003 test 21, 1.500111 secs
/dev/bus/usb/009/003 test 24, 13.239355 secs
/dev/bus/usb/009/003 test 27, 9.358318 secs
/dev/bus/usb/009/003 test 28, 13.144901 secs
/dev/bus/usb/009/003 test 29, 1.374946 secs
sudo dmesg -c
[ 3996.729222] usbtest 9-1:1.0: TEST 0: NOP
[ 3996.729970] usbtest 9-1:1.0: TEST 1: write 1024 bytes 1000 times
[ 3997.171935] usbtest 9-1:1.0: TEST 2: read 1024 bytes 1000 times
[ 3997.591437] usbtest 9-1:1.0: TEST 3: write/512 0..1024 bytes 1000 times
[ 3997.743436] usbtest 9-1:1.0: TEST 4: read/512 0..1024 bytes 1000 times
[ 3997.955061] usbtest 9-1:1.0: TEST 5: write 1000 sglists 32 entries of 1024 bytes
[ 4007.384194] usbtest 9-1:1.0: TEST 6: read 1000 sglists 32 entries of 1024 bytes
[ 4020.800860] usbtest 9-1:1.0: TEST 7: write/512 1000 sglists 32 entries 0..1024 bytes
[ 4025.610243] usbtest 9-1:1.0: TEST 8: read/512 1000 sglists 32 entries 0..1024 bytes
[ 4032.411721] usbtest 9-1:1.0: TEST 9: ch9 (subset) control tests, 1000 times
[ 4037.004401] usbtest 9-1:1.0: TEST 10: queue 32 control calls, 1000 times
[ 4058.007199] usbtest 9-1:1.0: TEST 11: unlink 1000 reads of 1024
[ 4058.848192] usbtest 9-1:1.0: unlink retry
[ 4061.880191] usbtest 9-1:1.0: unlink retry
[ 4062.920200] usbtest 9-1:1.0: unlink retry
[ 4064.256194] usbtest 9-1:1.0: unlink retry
[ 4067.601164] usbtest 9-1:1.0: TEST 12: unlink 1000 writes of 1024
[ 4078.240992] usbtest 9-1:1.0: TEST 13: set/clear 1000 halts
[ 4085.367076] usbtest 9-1:1.0: TEST 14: 1000 ep0out, 1..1024 vary 512
[ 4086.869445] usbtest 9-1:1.0: TEST 17: write odd addr 1024 bytes 1000 times core map
[ 4087.308943] usbtest 9-1:1.0: TEST 18: read odd addr 1024 bytes 1000 times core map
[ 4087.728323] usbtest 9-1:1.0: TEST 19: write odd addr 1024 bytes 1000 times premapped
[ 4088.159815] usbtest 9-1:1.0: TEST 20: read odd addr 1024 bytes 1000 times premapped
[ 4088.571315] usbtest 9-1:1.0: TEST 21: 1000 ep0out odd addr, 1..1024 vary 512
[ 4090.073688] usbtest 9-1:1.0: TEST 24: unlink from 1000 queues of 32 1024-byte writes
[ 4103.315378] usbtest 9-1:1.0: TEST 27: bulk write 31Mbytes
[ 4112.674595] usbtest 9-1:1.0: TEST 28: bulk read 31Mbytes
[ 4125.820420] usbtest 9-1:1.0: TEST 29: Clear toggle between bulk writes 1000 times
[ 4203.997512] usb 9-1: USB disconnect, device number 3
[ 4206.012476] usb 9-1: new full-speed USB device number 4 using xhci_hcd
[ 4206.181049] usb 9-1: New USB device found, idVendor=2fe3, idProduct=0009, bcdDevice= 4.03
[ 4206.181055] usb 9-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 4206.181057] usb 9-1: Product: Zephyr testusb sample
[ 4206.181058] usb 9-1: Manufacturer: Zephyr Project
[ 4206.181060] usb 9-1: SerialNumber: 003134534B484A483034303130303138
[ 4206.192120] usbtest 9-1:1.0: Linux gadget zero
[ 4206.192123] usbtest 9-1:1.0: full-speed {control in/out bulk-in bulk-out} tests (+alt)
[ 4206.192258] usbtest 9-1:1.1: Linux gadget zero
[ 4206.192259] usbtest 9-1:1.1: full-speed {control in/out int-in int-out} tests (+alt)
[ 4206.192377] usbtest 9-1:1.2: Linux gadget zero
[ 4206.192379] usbtest 9-1:1.2: full-speed {control in/out iso-in iso-out} tests (+alt)
$ sudo ./testusb -v 512 -D /dev/bus/usb/009/004
./testusb: /dev/bus/usb/009/004 may see only control tests
full speed /dev/bus/usb/009/004 0
/dev/bus/usb/009/004 test 0, 0.000005 secs
/dev/bus/usb/009/004 test 1, 1.287039 secs
/dev/bus/usb/009/004 test 2, 1.045827 secs
/dev/bus/usb/009/004 test 3, 0.649190 secs
/dev/bus/usb/009/004 test 4, 0.544383 secs
/dev/bus/usb/009/004 test 5, 37.908149 secs
/dev/bus/usb/009/004 test 6, 33.278872 secs
/dev/bus/usb/009/004 test 7, 19.530196 secs
/dev/bus/usb/009/004 test 8, 17.712640 secs
/dev/bus/usb/009/004 test 9, 22.035955 secs
/dev/bus/usb/009/004 test 10, 107.999626 secs
/dev/bus/usb/009/004 test 11, 3.840403 secs
/dev/bus/usb/009/004 test 12, 3.912775 secs
/dev/bus/usb/009/004 test 13, 32.000422 secs
/dev/bus/usb/009/004 test 14, 7.501008 secs
/dev/bus/usb/009/004 test 17, 1.249939 secs
/dev/bus/usb/009/004 test 18, 1.062828 secs
/dev/bus/usb/009/004 test 19, 1.249953 secs
/dev/bus/usb/009/004 test 20, 1.062865 secs
/dev/bus/usb/009/004 test 21, 7.501050 secs
/dev/bus/usb/009/004 test 24, 37.499771 secs
/dev/bus/usb/009/004 test 27, 37.646954 secs
/dev/bus/usb/009/004 test 28, 34.132905 secs
/dev/bus/usb/009/004 test 29, 4.000142 secs
$ sudo dmesg -c
[ 4220.773983] usbtest 9-1:1.0: TEST 0: NOP
[ 4220.775975] usbtest 9-1:1.0: TEST 1: write 1024 bytes 1000 times
[ 4222.063950] usbtest 9-1:1.0: TEST 2: read 1024 bytes 1000 times
[ 4223.110943] usbtest 9-1:1.0: TEST 3: write/512 0..1024 bytes 1000 times
[ 4223.760948] usbtest 9-1:1.0: TEST 4: read/512 0..1024 bytes 1000 times
[ 4224.306939] usbtest 9-1:1.0: TEST 5: write 1000 sglists 32 entries of 1024 bytes
[ 4262.215797] usbtest 9-1:1.0: TEST 6: read 1000 sglists 32 entries of 1024 bytes
[ 4295.495664] usbtest 9-1:1.0: TEST 7: write/512 1000 sglists 32 entries 0..1024 bytes
[ 4315.027598] usbtest 9-1:1.0: TEST 8: read/512 1000 sglists 32 entries 0..1024 bytes
[ 4332.741513] usbtest 9-1:1.0: TEST 9: ch9 (subset) control tests, 1000 times
[ 4354.779457] usbtest 9-1:1.0: TEST 10: queue 32 control calls, 1000 times
[ 4462.781023] usbtest 9-1:1.0: TEST 11: unlink 1000 reads of 1024
[ 4466.622951] usbtest 9-1:1.0: TEST 12: unlink 1000 writes of 1024
[ 4470.536939] usbtest 9-1:1.0: TEST 13: set/clear 1000 halts
[ 4502.538811] usbtest 9-1:1.0: TEST 14: 1000 ep0out, 1..1024 vary 512
[ 4510.045794] usbtest 9-1:1.0: TEST 17: write odd addr 1024 bytes 1000 times core map
[ 4511.296775] usbtest 9-1:1.0: TEST 18: read odd addr 1024 bytes 1000 times core map
[ 4512.360770] usbtest 9-1:1.0: TEST 19: write odd addr 1024 bytes 1000 times premapped
[ 4513.611761] usbtest 9-1:1.0: TEST 20: read odd addr 1024 bytes 1000 times premapped
[ 4514.675754] usbtest 9-1:1.0: TEST 21: 1000 ep0out odd addr, 1..1024 vary 512
[ 4522.182769] usbtest 9-1:1.0: TEST 24: unlink from 1000 queues of 32 1024-byte writes
[ 4559.687579] usbtest 9-1:1.0: TEST 27: bulk write 31Mbytes
[ 4597.335431] usbtest 9-1:1.0: TEST 28: bulk read 31Mbytes
[ 4631.469302] usbtest 9-1:1.0: TEST 29: Clear toggle between bulk writes 1000 timesIs by any chance you forget to run a I'll push again my another machine with latest main, just in case, with the same hash I tested few minutes ago. |
I have solely tested on the I've previously ran some of the Local build command:
Zephyr/CANnectivity console: Linux dmesg: I have also just tested the CDC-ACM sample from Zephyr on the same board: Local build command:
Zephyr console: Linux dmesg: Let me know if you need me to provide other outputs or try different things. |
|
henrikbrixandersen
left a comment
There was a problem hiding this comment.
Retested with latest push on the canbardo board.
Not sure what is wrong with sam_e70_xplained. It also does not work with the legacy stack in main. |



Summary
Add USB Device Controller (UDC) driver for SAM E70/S70/V70/V71 USBHS peripheral, enabling USB device_next stack support for these MCUs.
drivers/usb/udc/udc_sam_usbhs.cTest Plan
Fixes: #74663