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

drivers: add driver for Synopsys DWC2 that is used as USB OTG peripheral on STM32 and ESP32x SoCs #18644

Merged
merged 12 commits into from
Sep 29, 2022

Conversation

gschorcht
Copy link
Contributor

@gschorcht gschorcht commented Sep 25, 2022

Contribution description

This PR adds a driver for the Synopsys DWC2 IP core. It is an alternative to PR #18624 which avoids a lot of code duplication. STM32 as well as ESP32x SoCs use the Synopsys DWC2 core. According to tinyUSB documentation, EFM32GG12 and GD32VF103 also integrate the Synopsys DWC2 core.

Instead of copying the code from STM32's periph/usbdev_otg.c and modifying it very slightly only for ESP32x SoCs (as done in PR #18624), the code is now moved to a common location and extended by only a very small number of MCU-Specific changes. The Namespace is changed from stm32 to dwc2. STM32 and ESP32x SoCs use the driver as periph_usbdev driver.

Testing procedure

The following tests have to work for an ESP32 node as well as a STM32 node to check whether it is still working for STM32.

  1. Flash tests/usbus_hid
    BOARD=esp32s3-devkit make -C tests/usbus_hid flash term
    
    BOARD=nucleo-f767zi make -C tests/usbus_hid flash term
    
    Use the dmesg command and check the USB HID devices was found
    [1230033.363705] usb 1-2.4: USB disconnect, device number 91
    [1230033.625919] usb 1-2.4: new full-speed USB device number 92 using xhci_hcd
    [1230033.732624] usb 1-2.4: New USB device found, idVendor=1209, idProduct=7d01, bcdDevice= 1.00
    [1230033.732627] usb 1-2.4: New USB device strings: Mfr=3, Product=2, SerialNumber=4
    [1230033.732629] usb 1-2.4: Product: esp32s3-devkit
    [1230033.732630] usb 1-2.4: Manufacturer: RIOT-os.org
    [1230033.732631] usb 1-2.4: SerialNumber: A5894EECB420ECF1
    [1230033.739837] hid-generic 0003:1209:7D01.00D9: hiddev2,hidraw5: USB HID v1.10 Device [RIOT-os.org esp32s3-devkit] on usb-0000:00:14.0-2.4/input0
    and that there is a new /dev/hidrawX device to which you can write as root characters that are echoed in console window, for example:
    # echo -n "Hello" > /dev/hidraw5
    
    main(): This is RIOT! (Version: 2022.10-devel-619-gca66ff-cpu/esp32/periph_usbdev)
    RIOT USB HID echo test
    Write input to the hidraw device under /dev/hidrawX, and see if it gets echoed here
    USB_HID rx_cb: Test argument 
    Msg received via USB HID: 
    Hello
    
  2. Flash tests/usbus_ecm
    BOARD=esp32s3-devkit make -C tests/usbus_hid flash term
    
    BOARD=nucleo-f767zi make -C tests/usbus_hid flash term
    
    On the host computer, using tools such as ethtool must show the USB CDC ECM interface as link detected:
    # ethtool enp0s20u9u4
    Settings for enp0s20u9u4:
            Current message level: 0x00000007 (7)
                                   drv probe link
            Link detected: yes
    You should be able to ping the ESP32x node from the host and vice versa using the IPv6 address of the USB CDC ECM interface.

Issues/PRs references

@github-actions github-actions bot added Area: boards Area: Board ports Area: cpu Area: CPU/MCU ports Area: drivers Area: Device drivers Area: Kconfig Area: Kconfig integration Platform: ARM Platform: This PR/issue effects ARM-based platforms Platform: ESP Platform: This PR/issue effects ESP-based platforms labels Sep 25, 2022
@benpicco benpicco requested review from bergzand and dylad September 25, 2022 19:45
@benpicco benpicco added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Sep 25, 2022
Copy link
Contributor

@benpicco benpicco left a comment

Choose a reason for hiding this comment

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

Awesome, that's the way to go 😃

Works like a charm (I only tested on STM32, the only ESP32x board I have that has a USB port directly connected to the MCU is ESP32-C3), just two small nitpicks:

cpu/esp32/Makefile.features Outdated Show resolved Hide resolved
boards/common/esp32s2/include/periph_conf_common.h Outdated Show resolved Hide resolved
@github-actions github-actions bot added Area: doc Area: Documentation Area: tools Area: Supplementary tools labels Sep 26, 2022
@gschorcht gschorcht force-pushed the drivers/synopsys_dwc2 branch from ff7d953 to 79c3baf Compare September 26, 2022 19:41
@gschorcht gschorcht force-pushed the drivers/synopsys_dwc2 branch from 79c3baf to c422d45 Compare September 26, 2022 22:41
Copy link
Contributor

@benpicco benpicco left a comment

Choose a reason for hiding this comment

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

Please squash!

@gschorcht
Copy link
Contributor Author

Oops ...

-- running on worker comsys thread 7, build number 395.
make: Entering directory '/tmp/dwq.0.9713961674827482/55744c144780056868086f3022f1d3e8/examples/rust-gcoap'
make: Leaving directory '/tmp/dwq.0.9713961674827482/55744c144780056868086f3022f1d3e8/examples/rust-gcoap'
make: Entering directory '/tmp/dwq.0.9713961674827482/55744c144780056868086f3022f1d3e8/examples/rust-gcoap'
Building application "rust_gcoap" for "native" with MCU "native".

ccache: error: Failed to create temporary file for /cache/.ccache/tmp/tmp.cpp_stdout.8zgYzC: No space left on device

Since `esp_can.h` is included by main `cpu/esp32/include/periph_cpu.h` after the include of the specific `periph_cpu_$(CPU_FAM)`, it is not necessary to include `esp_can.h` in each specific `periph_cpu_$(CPU_FAM)`.
This file is an excerpt of STM32 header file `stm32/smsis/f7/include/stm32f767xx.h` since the ESP32x SoCs use the same Synopsys DWC2 IP core as USB peripherals.
@gschorcht gschorcht force-pushed the drivers/synopsys_dwc2 branch from c422d45 to 890acb4 Compare September 26, 2022 23:01
@benpicco
Copy link
Contributor

benpicco commented Sep 26, 2022

Yea comsys ran out of space after the update to Ubuntu 22.04

@gschorcht gschorcht added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Sep 27, 2022
@maribu maribu added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Sep 27, 2022
@chrysn chrysn added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Sep 27, 2022
@maribu
Copy link
Member

maribu commented Sep 27, 2022

Looks like the auto-merge of the jammy fixes came in to late. I'll restart the CI run, so that no unrelated issued pop up in the build log.

@maribu maribu added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Sep 27, 2022
@maribu
Copy link
Member

maribu commented Sep 27, 2022

I restarted the CI run an restored the CI queue in the same order it was before.

@benpicco benpicco added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Sep 27, 2022
@benpicco benpicco enabled auto-merge September 27, 2022 23:11
@benpicco
Copy link
Contributor

Looks like CI is back to normal now - thank you for providing all this 😃

Btw: Does the ESP-C3 use the same peripheral or does this require more changes?

@gschorcht
Copy link
Contributor Author

gschorcht commented Sep 28, 2022

Btw: Does the ESP-C3 use the same peripheral

Unfortunatly not. ESP32-C3 uses a special USB Serial/JTAG controller which is an USB CDC ACM device with fixed configuration. If at all, we could only develop a driver which then only supports the CDC ACM class. ESP32-S2 and ESP32-S3 have this USB Serial/JTAG controller in addition to the USB OTG controller.

@gschorcht gschorcht force-pushed the drivers/synopsys_dwc2 branch from 890acb4 to 13eadda Compare September 28, 2022 15:00
@benpicco benpicco merged commit 45afb8f into RIOT-OS:master Sep 29, 2022
@gschorcht
Copy link
Contributor Author

@benpicco Thanks for reviewing and merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: boards Area: Board ports Area: cpu Area: CPU/MCU ports Area: doc Area: Documentation Area: drivers Area: Device drivers Area: Kconfig Area: Kconfig integration Area: tools Area: Supplementary tools 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 Platform: ESP Platform: This PR/issue effects ESP-based platforms
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants