-
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 DWC2 Test Mode Support #2416
Conversation
The device should enter the test mode within 3 milliseconds. Right now there is basically no additional delay and the implementation relies that the control complete callback at the |
I've tested test modes on my device using the EHCI tool and the tests pass. @Rocky04, do you have an idea when this would be ready for review? Thanks! |
@shuchitak Was a code change needed or are you also using the DWC2 driver? On which device / MCU have you tested it? I just used a draft for discussion... With the recent changes I'm somewhat happy with it now. |
What would be a good way to toggle that feature off? Like a flag to exclude the handling and all the entire code for it in the case the test mode feature selector should not be used completely. |
@Rocky04, I tested on an xcore device. The dcd layer for xcore (https://github.com/xmos/fwk_rtos/tree/develop/modules/sw_services/usb/portable) is not part of the tinyusb repo. I added implementation for the new dcd functions (shuchitak/fwk_rtos@08dd360) and ran the EHCI tests. |
I thought returning a STALL if dcd_check_test_mode_support() returns False was a good idea. Why would we want to turn the feature off altogether? |
I like to separate the configuration from implementation. Maybe someone don't want to have the support for that feature, then he should not need to alter any code, especially not any driver code. The |
Sorry I meant this line, If somebody doesn't support this feature, they wouldn't implement these dcd functions and TU_VERIFY would return false. Isn't it the same as the existing code doing this, where for the TUSB_REQ_FEATURE_TEST_MODE feature, it would return false? |
Yes, but if it's already supported for a MCU people would need to delete the driver code or override the function. Like Edit: It would work right now by placing an undefine within the TinyUSB configuration file. |
Hmm, I'm not really sure. We could put all the test mode related code in usbd.c in #if TUSB_TEST_MODE_SUPPORT and have the application so something like #define TUSB_TEST_MODE_SUPPORT 1 in the tusb_config.h file, so it is disabled by default? |
Kind of... For this feature I would prefer an opt-out instead of an opt-in, because it should be there for Hi-Speed. Ideally if that feature is not supported the code for it should be excluded from compiling and so to not rely on the linker to drop it afterwards. |
To have it enabled by default, we could add something like #ifndef TUSB_TEST_MODE_SUPPORT in tusb_options.h. So in tusb_config.h, the user would need to explicitly disable it by doing |
Hi @Rocky04, do you have any more thoughts about enabling opt-out for this feature through a #ifdef? Are you planning to add this to usbd.c? Some of the tests are also failing in the compilation stage. I don't see how these changes can fail compilation. |
@shuchitak
For the code exclusion I currently favor to use a symbol and if that is defined to not compile the code in the first place. Because I prefer an opt-out for it and keeping it as simple as possible. |
@Rocky04, I agree, a simple opt out based on a define sounds good. Something like this? diff --git a/src/device/usbd.c b/src/device/usbd.c +#ifndef DISABLE_TUSB_TEST_MODE_SUPPORT
+#endif If this looks okay for you, do you think we could add this change and have this PR reviewed and possibly merged? I need to make a release and would be great if this could make its way into the tinyusb_src repo. Thanks! |
Hi, sorry for the late response. I added the opt-out to exclude the code if the test mode is not wanted. Sadly no-one seems to have reviewed the code so far. There aren't that many people who maintain this repro. |
Thanks for your PR, I've adjusted the logic, test mode is default disabled, one can enable by set |
As mentioned above the Test Mode is mandatory for Hi-Speed per specification. |
It's mandatory for compliance test not for end use, same like WiFi RED test which is mandatory but test firmware is not publicly available. |
Yeah, but these are there for a reason. Only because no one cares and don't send in a device doesn't mean it should be disabled per default. It's not that this feature is only enabled just when doing the test. |
// Disable test mode if not supported as a fall back | ||
if (!dcd_check_test_mode_support(test_selector)) { | ||
test_selector = 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.
This is not dead code! This is a check if the used test selector is actually supported and to fall back to do nothing in that case.
The app can still call dcd_enter_test_mode()
directly and not all chips which are compatible with DWC2 actually support test modes.
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.
dcd layer are private functions can't be called by user code. If there is a need of force enable should implement a usbd_ function
According to the USB 2.0 specification under point 7.1.20 Test Mode Support, high-speed capable functions must support specific test modes to facilitate compliance testing.
This PR adds the fundamental support for that. It was tested on a NUCLEO-U5A5ZJ-Q and STM32F23E-DISCO where this is supported directly by the MCU.
The entering of the test mode is scheduled by a
new eventcontrol complete callback so that the feature request of the host can be acknowledged prior entering it.Edit:
The test modes can be tested with the XHSETT - XHCI Electrical Test Tool from the USB Compliance Tools.