-
Notifications
You must be signed in to change notification settings - Fork 16
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
feature(esp_tinyusb): Added tusb_teardown() call while tinyusb_driver_uninstall() #39
base: master
Are you sure you want to change the base?
Conversation
device/esp_tinyusb/tinyusb.c
Outdated
@@ -69,5 +69,6 @@ esp_err_t tinyusb_driver_install(const tinyusb_config_t *config) | |||
esp_err_t tinyusb_driver_uninstall() | |||
{ | |||
tinyusb_free_descriptors(); | |||
tusb_teardown(); |
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.
when you will have time
Is there any good way how I can make this change backward compatible with previous espressif/tinyusb
components (previous versions, which doesn't have this implementation)?
Will appreciate any suggestions.
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.
Here are some ideas, that came to me:
- Tie it to the configuration and use idf version to determine the necessity and implementation of tusb_teardown()
- Define it somewhere in esp_tinyusb with WEAK attribute. Which let us redefine in with new version and don't panic with old versions, when there is no implementation of it
- Enable it with menuconfig (which seems really strange for me, but anyway maybe it is possible).
I like option No.2, but maybe there are other simple and better solution.
}; | ||
|
||
|
||
TEST_CASE("device_class_reconfiguration", "[usb_device]") |
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.
After adding the feature from here: espressif/tinyusb#27, we will be able to run esp_tinyusb
device tests, because they could be run one by one in a one test launch.
Currently, I have no idea how to add them to our CI and where, but if you have some ideas, please feel free to share.
Thanks.
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.
To add usb device test, you just need to create a new pytest marker in your pytest*.py file, like so:
@pytest.mark.usb_device
Then, pytest command being run from build_and_run_test_app_usb.yml
file, must include this new marker.
Right now, we are using only -m usb_host
marker. Thus there will be one more marker -m usb_device
So the new pytest command would look like:
pytest --target=${{ matrix.idf_target }} -m usb_host -m usb_device --build-dir=build_${{ matrix.idf_target }}
This should be all.
@tore-espressif , @peter-marcisovsky I posted two questions for both of you, because it seems that we can make it better and we can use it. I need that for enumeration driver testing (but maybe I will eliminate esp_tinyusb component from the chain, but anyway), so feel free to check it out when possible. Meanwhile, I will go and cover the Enum Driver as much as I can. |
8b60d62
to
ce33baf
Compare
ce33baf
to
d7cb17d
Compare
d7cb17d
to
c14eebb
Compare
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.
Left some observations from using the test app
CONFIG_TINYUSB_CDC_ENABLED=y | ||
CONFIG_TINYUSB_CDC_COUNT=2 | ||
CONFIG_TINYUSB_HID_COUNT=0 | ||
CONFIG_TINYUSB_HID_COUNT=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.
After enabling HID in the menuconfig, the
tinyusb_set_descriptors()
would fail
because of
// Default configuration descriptor is provided only for CDC, MSC and NCM classes
ESP_GOTO_ON_FALSE(config->configuration_descriptor, ESP_ERR_INVALID_ARG, fail, TAG, "Configuration descriptor must be provided for this device");
Thus making all the descriptors test cases failing.
@@ -66,8 +78,18 @@ esp_err_t tinyusb_driver_install(const tinyusb_config_t *config) | |||
return ESP_OK; | |||
} | |||
|
|||
esp_err_t tinyusb_driver_uninstall() | |||
esp_err_t tinyusb_driver_uninstall(void) |
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.
Could we call this function from tearDown()
?
Once a test case fails, the PHY does not get released, thus all the following test cases would fail because of the:
E (23549) usb_phy: usb_new_phy(296): selected PHY is in use
E (23559) TinyUSB: tinyusb_driver_install(65): Install USB PHY failed
if (!tusb_teardown()) { | ||
return ESP_ERR_NOT_FINISHED; | ||
} | ||
|
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.
@roma-jam Should we restore the USB to the default function (eg. USB-Serial-JTAG) at the end of uninstall?
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.
@leeebo I don't think that would be a good idea, as for user it is transparent in that case.
Even, IDK, whether we have such feature before installing tinyUSB driver?
Just in case: do we have such call (maybe in rom) to enable this feature? Or you thinking about configure the PHY during teardown in the way, to enable USB-Serial-JTAG?
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.
The USB-Serial-JTAG is a hardware circuit that can respond to the host's requests and is enabled by default. Users can use the USB-Serial-JTAG for USB download without any code in APP.
But after tinyUSB install then uninstalled, the USB phy not be switched back to USB-Serial-JTAG
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.
@roma-jam @leeebo as a user of the library in esp32s3 I think teardown/uninstall should not auto-reinstall jtag but there should be a convenience function that allows to restore it, if necessary it could be called automatically and be driven by Kconfig to provide best defaults. In my use case i want to be able to switch from usb cdc guest to msc usb host and viceversa and that is currently not possible without a device restart
Is there a timeline for this feature to be finalized? |
Hi @finger563 , This feature allows the re-configure the driver with these changes: espressif/tinyusb#27 Meanwhile, this feature should be available in the upstream of TinyUSB, if anything it is possible to use it. Sorry for the inconvenience. |
esp_tinyusb (Not a Release)
Requirements
Description
tusb_teardown()
call whiletinyusb_driver_uninstall()
Changes
tusb_teardown()
device_class_reconfiguration
which:Notes
tinyusb_driver_install()
andtinyusb_driver_uninstall()
calls.Resolve espressif/esp-idf#13788