Skip to content

Conversation

@AidenHu
Copy link
Contributor

@AidenHu AidenHu commented Nov 18, 2025

When USB hub is used, maybe multiple devices are attached, so need to consider about this.

@zephyrbot zephyrbot added platform: NXP NXP area: USB Universal Serial Bus labels Nov 18, 2025
@AidenHu AidenHu force-pushed the support-multiple-devices-connect-usb-host branch 2 times, most recently from 091e8b6 to 0be1c7c Compare November 18, 2025 14:46
Copy link
Contributor

@josuah josuah left a comment

Choose a reason for hiding this comment

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

Thanks. Some discussion about it below.

Comment on lines 470 to 472
SYS_DLIST_FOR_EACH_NODE(&uhs_ctx->udevs, node) {
device_count++;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can use device_count = sys_dlist_len(&uhs_ctx->udevs); in this case.

doc

But let's discuss on https://github.com/zephyrproject-rtos/zephyr/pull/99591/files#r2538708506 first?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@

I think you can use device_count = sys_dlist_len(&uhs_ctx->udevs); in this case.

doc

But let's discuss on https://github.com/zephyrproject-rtos/zephyr/pull/99591/files#r2538708506 first?

@josuah agree, already done for sys_dlist_len

Comment on lines +476 to +479
if (device_count == 1U) {
err = uhc_bus_reset(uhs_ctx->dev);
if (err) {
LOG_ERR("Failed to signal bus reset");
return err;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

What about PORT_RESET hub class feature? Where this should be handled? At high-level Linux solves the issue by having a software-only hub at the top level.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What about PORT_RESET hub class feature? Where this should be handled? At high-level Linux solves the issue by having a software-only hub at the top level.

Hi @tmon-nordic
The PORT_RESET of HUB is handled by a set feature request. This is handled in hub class layer. Actually I have finished the first version USB hub class and tested in my local project. Recently I will created one PR about it.

When hub is used, need to consider about multiple
devices are attached.

Signed-off-by: Aiden Hu <[email protected]>
@AidenHu AidenHu force-pushed the support-multiple-devices-connect-usb-host branch 2 times, most recently from 46ef4c9 to 111a8d6 Compare November 19, 2025 13:22
@AidenHu AidenHu force-pushed the support-multiple-devices-connect-usb-host branch from 111a8d6 to caaeeff Compare November 20, 2025 01:13
@josuah
Copy link
Contributor

josuah commented Nov 20, 2025

Thank you @AidenHu for the modifications. As soon as the CI tests above all pass, and review is complete, this PR can be merged.

screenshot_2025_1120_0245_57

It is possible to read more about it here ("Continuous Integration") if curious.

@AidenHu
Copy link
Contributor Author

AidenHu commented Nov 20, 2025

@josuah
Considering this PR is created based on the main, main branch is old for usb host. Now you are updating the host stack. Therefore, I create another signal commit in the host_hub_pr, which host_hub_pr is using your newest USB Host: integrate class API [2: helpers] #94590.
Appreciate your feedback about merging this PR to main or cherrypick signal commit to USB Host: integrate class API [2: helpers] #94590


udev = usbh_device_get_root(ctx);

if (udev) {
Copy link
Contributor

@josuah josuah Nov 21, 2025

Choose a reason for hiding this comment

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

Comparing explicitly against NULL helps with MISRA compliance.

See rule 85 here:
https://docs.zephyrproject.org/latest/contribute/coding_guidelines/index.html#coding-guidelines

This is not strictly applied, as I remember, but it can also help keeping the code a bit more homogene.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comparing explicitly against NULL helps with MISRA compliance.

See rule 85 here: https://docs.zephyrproject.org/latest/contribute/coding_guidelines/index.html#coding-guidelines

This is not strictly applied, as I remember, but it can also help keeping the code a bit more homogene.

Thanks, fixed it as the rule.

add usbh_device_get_root and usbh_device_is_root
function to check root device

Signed-off-by: Aiden Hu <[email protected]>
@AidenHu AidenHu force-pushed the support-multiple-devices-connect-usb-host branch from caaeeff to 4f2a48f Compare November 21, 2025 10:45
@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: USB Universal Serial Bus platform: NXP NXP

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants