Skip to content

Conversation

@tzy0002088
Copy link

When ECONNABORTED is received, clear MSC_CLASS_ENABLED to prevent issuing an OUT request after a soft disconnect at the application layer. Otherwise, during a subsequent soft connect, MSC_BULK_OUT_QUEUED would not be cleared, causing the OUT transfer to fail and leading to enumeration failure.

@zephyrbot zephyrbot added size: XS A PR changing only a single line of code area: USB Universal Serial Bus labels Oct 17, 2025
if (err == -ECONNABORTED) {
LOG_WRN("request ep 0x%02x, len %u cancelled",
bi->ep, buf->len);
atomic_clear_bit(&ctx->bits, MSC_CLASS_ENABLED);
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks simply wrong. Why msc_bot_disable() is not called in your use case?

Copy link
Contributor

Choose a reason for hiding this comment

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

usbd_disable() first calls usbd_config_set(uds_ctx, 0);

int usbd_disable(struct usbd_context *const uds_ctx)
{
int ret;
if (!usbd_is_enabled(uds_ctx)) {
LOG_WRN("USB device support is already disabled");
return -EALREADY;
}
usbd_device_lock(uds_ctx);
ret = usbd_config_set(uds_ctx, 0);

which will in turns call usbd_config_reset()
if (usbd_get_config_value(uds_ctx) != 0) {
ret = usbd_config_reset(uds_ctx);

which disables all classes
usbd_config_classes_enable(cfg_nd, false);

so it will call msc_bot_disable().

Copy link
Author

@tzy0002088 tzy0002088 Oct 17, 2025

Choose a reason for hiding this comment

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

bae5fe0f-cc25-49e4-bfea-4ee2ac26e7e2

ep_dequeue exists in step 1, which first submits -ECONNABORTED, causing the request to be executed first.

Copy link
Author

Choose a reason for hiding this comment

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

usbd_interface_shutdown -> usbd_ep_disable -> udc_ep_dequeue -> udc_submit_ep_event

Copy link
Author

Choose a reason for hiding this comment

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

The thread priority behind the USBD preempted the current thread’s priority, causing the USBD request to be executed first.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, and we also need to know how to completely resolve it. It seems that currently all UDC drivers are affected by this issue.

Copy link
Author

@tzy0002088 tzy0002088 Oct 20, 2025

Choose a reason for hiding this comment

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

@tmon-nordic In this commit, k_sched_lock is called in usbd_disable to disable the scheduler, just like in usbd_enable.

Copy link
Author

@tzy0002088 tzy0002088 Oct 20, 2025

Choose a reason for hiding this comment

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

@tmon-nordic However, I’m not sure why k_yield is called inside usbd_ep_disable. Since calling k_yield forces a context switch, it causes the MSC thread to run first. That’s why I disabled it here.

Copy link
Contributor

Choose a reason for hiding this comment

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

The new approach is much better. However, I think it is still important to look into why the subsequent enqueue is not failing.

Copy link
Author

Choose a reason for hiding this comment

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

I don't know why the yield is called at that position. The reason why ep_enqueue did not fail is that ep_dequeue cleared busy, and ep_enqueue did not determine that it was busy.

@tzy0002088
Copy link
Author

@jfischer-no FYI

clear MSC_CLASS_ENABLED to prevent issuing an OUT
request after a soft disconnect at the application layer.
Otherwise, during a subsequent soft connect, MSC_BULK_OUT_QUEUED
would not be cleared, causing the OUT transfer to fail
and leading to enumeration failure.

Signed-off-by: tangzhenye <[email protected]>
@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 size: XS A PR changing only a single line of code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants