| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
With RT_USB_DEVICE_CDC and RT_USING_SERIAL_V2 both enabled, _function_enable assigned the embedded rx_ringbuffer to serial.serial_rx. Serial V2 reads that pointer as a struct rt_serial_rx_fifo, whose first member is a rt_ringbuffer, so ring-buffer access happened to work while rx_cpt, rx_cpt_index and rx_timeout landed on the following members of struct vcom, corrupting tx_rbp. The layout shifts again with RT_SERIAL_USING_DMA, which inserts dma_ping_rb ahead of those fields. Serial V2 already owns the receive FIFO: dev_serial_v2.c allocates it with rt_malloc on open and releases it with rt_free on close, so the assignment also made rt_free run on memory inside struct vcom. Drop the assignment and read the FIFO Serial V2 owns. rt_hw_serial_isr reports RX_IND from serial_rx->rb, so the endpoint handler now fills that ring buffer and _vcom_getc drains it. The Serial V1 path is unchanged. Fixes RT-Thread#11739 Signed-off-by: Jaeyeong Lee <lee@jaeyeong.cc>
Sorry, something went wrong.
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 fix/vcom-serial-v2-rx-fifo 分支,关联的 Pull Request 也会同步更新。 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
Sorry, something went wrong.
📌 Code Review Assignment🏷️ Tag: componentsReviewers: @Maihuanyi Changed Files (Click to expand)
📊 Current Review Status (Last Updated: 2026-09-12 07:57 CST)
📝 Review Instructions
|
Sorry, something went wrong.
| level = rt_hw_interrupt_disable(); | ||
|
|
||
| #ifdef RT_USING_SERIAL_V2 | ||
| rx_fifo = (struct rt_serial_rx_fifo *)data->serial.serial_rx; |
There was a problem hiding this comment.
建议添加 rx_bufsz == 0 的轮询接收路径,因为在打开设备前将 config.rx_bufsz 配为 0,并使用 RT_SERIAL_RX_BLOCKING,Serial V2 会进入轮询模式,不分配 serial_rx。
if (data->serial.config.rx_bufsz == 0)
{
rt_ringbuffer_put(&data->rx_ringbuffer, data->ep_out->buffer, size);
}
Sorry, something went wrong.
|
Sorry, something went wrong.
Signed-off-by: Jaeyeong Lee <lee@jaeyeong.cc>
| Back | FazBrowse Home | New Git URL |
拉取/合并请求描述:(PR description)
为什么提交这份PR (why to submit this PR)
Fixes #11739
With RT_USB_DEVICE_CDC and RT_USING_SERIAL_V2 both enabled, _function_enable() assigned the embedded rx_ringbuffer to serial.serial_rx:
Serial V2 reads that pointer as a struct rt_serial_rx_fifo *. Because rt_ringbuffer is the first member of rt_serial_rx_fifo, ring-buffer access happened to work, while rx_cpt, rx_cpt_index and rx_timeout landed on the members that follow rx_ringbuffer inside struct vcom, corrupting tx_rbp. The layout shifts again when RT_SERIAL_USING_DMA is enabled, which inserts dma_ping_rb ahead of those fields.
Serial V2 already owns the receive FIFO: dev_serial_v2.c allocates it with rt_malloc() on open and releases it with rt_free() on close. The assignment therefore also overwrote the FIFO allocated at open time, and made the close path call rt_free() on memory inside struct vcom that was never dynamically allocated. The problem becomes reachable once the USB host configures the CDC device.
你的解决方案是什么 (what is your solution)
No API or Kconfig change is involved. The diff is limited to components/legacy/usb/usbdevice/class/cdc_vcom.c (+23 / -4).
请提供验证的bsp和config (provide the config and bsp)
BSP: Not board-specific. The change is in the common component
components/legacy/usb/usbdevice/class/cdc_vcom.c, which is shared by every BSP that
provides a USB device controller. It was not verified on physical hardware. Verification
was done by code review, struct-layout analysis of struct vcom versus
struct rt_serial_rx_fifo, and build checks. Testing on a board with a USB device
controller and RT_USB_DEVICE_CDC + RT_USING_SERIAL_V2 enabled is very welcome.
.config: RT_USING_SERIAL_V2, RT_USB_DEVICE, RT_USB_DEVICE_CDC
action: https://github.com/Finder16/rt-thread/actions/runs/33252216932
(qemu-vexpress-a9, sourcery-arm, branch fix/vcom-serial-v2-rx-fifo, result: success)
Note: no BSP in the tree enables RT_USB_DEVICE_CDC together with RT_USING_SERIAL_V2 in
its default .config, so cdc_vcom.c is not compiled by the BSP build CI. The linked run
only confirms that the tree still builds with this change applied. Review of the USB CDC
path itself, and testing on hardware with a USB device controller, would be appreciated.
贡献者 (Contributors)
This issue was analyzed and reported together with:
当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following: