-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add support for dcd_sof_enable() to some additional ports. #2647
Add support for dcd_sof_enable() to some additional ports. #2647
Conversation
USB->DEVICE.INTENSET.bit.SOF = 1; | ||
} else { | ||
USB->DEVICE.INTENCLR.bit.SOF = 1; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SAMD support has been tested (both enable and disable) on a Seeed Studio XIAO SAMD21
dcd_reg->USBINTR |= INTR_SOF; | ||
} else { | ||
dcd_reg->USBINTR &= ~INTR_SOF; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implementation has been tested (both enable and disable) on NXP MIMXRT-1010-EVK where the interrupt fires at 125ms as expected for a high speed connection.
} else { | ||
_dcd.sof_enabled = false; | ||
NRF_USBD->INTENCLR = USBD_INTENCLR_SOF_Msk; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested on nrf52840 dongle (PCA10059).
Thanks for your PR, since your are working on it , could you please also add tinyusb/src/portable/synopsys/dwc2/dcd_dwc2.c Line 1161 in ccc7a36
For ci_hs it can be read from |
Is this different? I noticed they already had something like this?
My testing from within micropython is using the |
They are similar, except I need to fix tud_sof_cb() always receive frame_count 0 |
I just fixed the CI issue and frame count in tud_sof_cb(). |
I've added I haven't tested renesas changes at all yet as I'm chasing some support to get USB working at all on the renesas evk I've got. The 4 ports covered at this point are the main ones I'm planning on adding at this time as these (mimx, samd, nrf, renesas) are the only ones I've got access to where the matching micropython ports directly use libusb, other than rp2 where these functions have already been added. I will also look at esp32s3 and esp32s2 are a separate issue, I do want that added too but in expecting some complications from IDF integration. If that's in fact trivial I'll add support for this platform too. |
esp32 use dcd_dwc2 which already have sof support, it is little more complicate if you want to try: # 1. Source ESP-IDF
# Windows
%userprofile%\esp\esp-idf\export.bat
# Linux
. $HOME/esp/esp-idf/export.sh
# 2. Enter example directory
cd tinyusb/examples/device/hid_composite_freertos
# 3. Run cmake in project directory specifying the board
cmake -DBOARD=espressif_s3_devkitc -B build -G Ninja .
ninja.exe -C build |
I would have assumed esp32s2/3 uses this driver which doesn't have these sof functions configured?
|
dcd_esp32sx is old driver still maintained by espressif (with some specific logging), a new driver has been created for all devices with dwc2: |
Thanks @HiFiPhile that's really interesting about the esp32sX driver! With that info I've been able to get a build of micropython working on the S3 that's using our existing tinyusb submodule and this driver directly, ignoring most of the esp32 usb implementation. It just took a little bit of extra support to manage switching from USB serial/jtag mode to USB OTG mode, but my test code for that seems to be working pretty well so far. |
957f924
to
eca7837
Compare
eca7837
to
a9745c9
Compare
Thanks for your SOF frame count fix, I've also now finished adding I've been able to test all of them and have confirmed the frame counts are passed through as expected. In case it helps, the code in using sof interrupt for plus the test printf to confirm SOF frame count is here: https://github.com/andrewleech/micropython/blob/54e0abf5d15441ad7a2a9d8058e45c6f8e193f68/shared/tinyusb/mp_usbd_cdc.c#L124 I now consider this PR complete and ready for final review thanks (pending me rebasing it / fixing the merge conflict). |
// TODO implement later | ||
rusb2_reg_t* rusb = RUSB2_REG(rhport); | ||
_dcd.sof_enabled = en; | ||
rusb->INTENB0_b.SOFE = en ? 1: 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renesas updates tested on a EK-RA4W1 which had a usb cable added to the appropriate breakout header pins (the USB peripheral actually isn't connected to a USB port on these eval boards).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your work and tests !
Thanks for your support and reviews @HiFiPhile ! |
Describe the PR
This PR fills out the stubbed dcd_sof_enable() function for mimxrt, samd and renesas-ra ports.
Additional context
I'm working on a TinyUSB feature in micropython that uses SOF to provide some simple timing / delay shortly after connection of CDC: micropython/micropython#14485
This also relates to #2595 where it was found a delay is needed after CDC connection before sending / flushing TX data from TinyUSB (device) to host so its not lost.
In the micropython stm port (not using tinyusb) the SOF interrupt is enabled on CDC connection / DTR enable and is used to count 8ms before disabling the SOF interrupt again and flushing buffered data to the host. I'm planning on replicating this process using TinyUSB on other micropython ports, eventually replacing the STM USB stack with TinyUSB on that port also.