From ceef6e0ccd646aef61b907aeb9f29269d1caba50 Mon Sep 17 00:00:00 2001 From: Jaeyeong Lee Date: Sat, 12 Sep 2026 08:56:47 +0900 Subject: [PATCH] fix[usb]: support VCOM polling receive with Serial V2 Signed-off-by: Jaeyeong Lee --- .../legacy/usb/usbdevice/class/cdc_vcom.c | 40 ++++++++++++++----- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/components/legacy/usb/usbdevice/class/cdc_vcom.c b/components/legacy/usb/usbdevice/class/cdc_vcom.c index 7d4463ea89..e99013ce39 100644 --- a/components/legacy/usb/usbdevice/class/cdc_vcom.c +++ b/components/legacy/usb/usbdevice/class/cdc_vcom.c @@ -337,6 +337,7 @@ static rt_err_t _ep_in_handler(ufunction_t func, rt_size_t size) static rt_err_t _ep_out_handler(ufunction_t func, rt_size_t size) { rt_base_t level; + rt_bool_t notify_rx = RT_FALSE; struct vcom *data; #ifdef RT_USING_SERIAL_V2 struct rt_serial_rx_fifo *rx_fifo; @@ -355,18 +356,30 @@ static rt_err_t _ep_out_handler(ufunction_t func, rt_size_t size) level = rt_hw_interrupt_disable(); #ifdef RT_USING_SERIAL_V2 - rx_fifo = (struct rt_serial_rx_fifo *)data->serial.serial_rx; - if (rx_fifo != RT_NULL) + if (data->serial.config.rx_bufsz == 0) { - rt_ringbuffer_put(&rx_fifo->rb, data->ep_out->buffer, size); + rt_ringbuffer_put(&data->rx_ringbuffer, data->ep_out->buffer, size); + } + else + { + rx_fifo = (struct rt_serial_rx_fifo *)data->serial.serial_rx; + if (rx_fifo != RT_NULL) + { + rt_ringbuffer_put(&rx_fifo->rb, data->ep_out->buffer, size); + notify_rx = RT_TRUE; + } } #else rt_ringbuffer_put(&data->rx_ringbuffer, data->ep_out->buffer, size); + notify_rx = RT_TRUE; #endif rt_hw_interrupt_enable(level); /* notify receive data */ - rt_hw_serial_isr(&data->serial,RT_SERIAL_EVENT_RX_IND); + if (notify_rx) + { + rt_hw_serial_isr(&data->serial, RT_SERIAL_EVENT_RX_IND); + } } data->ep_out->request.buffer = data->ep_out->buffer; @@ -732,20 +745,29 @@ static int _vcom_getc(struct rt_serial_device *serial) func = (struct ufunction*)serial->parent.user_data; data = (struct vcom*)func->user_data; - RT_UNUSED(data); result = -1; level = rt_hw_interrupt_disable(); #ifdef RT_USING_SERIAL_V2 - rx_fifo = (struct rt_serial_rx_fifo *)serial->serial_rx; - if(rx_fifo != RT_NULL && rt_ringbuffer_getchar(&rx_fifo->rb, &ch) != 0) + if (serial->config.rx_bufsz == 0) { - result = ch; + if (rt_ringbuffer_getchar(&data->rx_ringbuffer, &ch) != 0) + { + result = ch; + } + } + else + { + rx_fifo = (struct rt_serial_rx_fifo *)serial->serial_rx; + if (rx_fifo != RT_NULL && rt_ringbuffer_getchar(&rx_fifo->rb, &ch) != 0) + { + result = ch; + } } #else - if(rt_ringbuffer_getchar(&data->rx_ringbuffer, &ch) != 0) + if (rt_ringbuffer_getchar(&data->rx_ringbuffer, &ch) != 0) { result = ch; }