-
Couldn't load subscription status.
- Fork 8.2k
STM32 UDC: fix transmission on halted endpoints #93796
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -829,6 +829,14 @@ static int udc_stm32_ep_set_halt(const struct device *dev, | |
| return -EIO; | ||
| } | ||
|
|
||
| /* | ||
| * Mark non-control endpoint as halted | ||
| * to indicate stall condition | ||
| */ | ||
| if (USB_EP_GET_IDX(cfg->addr) != 0) { | ||
| cfg->stat.halted = true; | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
|
|
@@ -847,6 +855,22 @@ static int udc_stm32_ep_clear_halt(const struct device *dev, | |
| return -EIO; | ||
| } | ||
|
|
||
| /* Clear halted state to resume normal operation */ | ||
| cfg->stat.halted = false; | ||
|
|
||
| if (USB_EP_GET_IDX(cfg->addr) != 0U) { | ||
| struct net_buf *buf = udc_buf_peek(cfg); | ||
|
|
||
| /* Start IN (device-to-host) transfer if not busy */ | ||
| if (buf != NULL && USB_EP_DIR_IS_IN(cfg->addr) && !udc_ep_is_busy(cfg)) { | ||
| udc_stm32_tx(dev, cfg, buf); | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about the OUT direction? Do you need to restart anything explicitly here? I did not have time to look at the OUT path in my suggestion, so I just added a comment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point regarding the OUT direction. For OUT endpoints, I will add logic to re-arm the endpoint (e.g., by calling udc_stm32_rx()) to ensure it is ready to receive new data. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| /* Prepare OUT (host-to-device) transfer if busy */ | ||
| else if (buf != NULL && USB_EP_DIR_IS_OUT(cfg->addr) && udc_ep_is_busy(cfg)) { | ||
| udc_stm32_rx(dev, cfg, buf); | ||
| } | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
|
|
@@ -879,8 +903,19 @@ static int udc_stm32_ep_enqueue(const struct device *dev, | |
|
|
||
| lock_key = irq_lock(); | ||
|
|
||
| if (USB_EP_DIR_IS_IN(epcfg->addr)) { | ||
| ret = udc_stm32_tx(dev, epcfg, buf); | ||
| if (USB_EP_DIR_IS_IN(epcfg->addr) != 0U) { | ||
| if (!epcfg->stat.halted) { | ||
| /* Endpoint is not halted, safe to transmit data */ | ||
| ret = udc_stm32_tx(dev, epcfg, buf); | ||
| } else { | ||
| /* | ||
| * Endpoint is halted (stalled) by the host. | ||
| * Skip transmission to avoid protocol violations | ||
| * and potential data corruption. | ||
| */ | ||
| LOG_DBG("ep 0x%02x halted", epcfg->addr); | ||
| ret = 0; | ||
| } | ||
| } else { | ||
| ret = udc_stm32_rx(dev, epcfg, buf); | ||
| } | ||
|
|
||
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 commit message does not look nice. You can have up to 75 characters per line in the commit message.
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.
Done