diff --git a/components/drivers/usb/usbdevice/class/cdc_vcom.c b/components/drivers/usb/usbdevice/class/cdc_vcom.c index c7097f135c893742acff62545406fb839a767d58..e74738bbe0b991b42a681d572aa958603175ef52 100644 --- a/components/drivers/usb/usbdevice/class/cdc_vcom.c +++ b/components/drivers/usb/usbdevice/class/cdc_vcom.c @@ -332,14 +332,33 @@ static rt_err_t _ep_out_handler(ufunction_t func, rt_size_t size) if((data->serial.parent.flag & RT_DEVICE_FLAG_ACTIVATED) && (data->serial.parent.open_flag & RT_DEVICE_OFLAG_OPEN)) { - /* receive data from USB VCOM */ + #ifdef RT_USING_SERIAL_V1 + /* notify receive data */ + rt_hw_serial_isr(&data->serial,RT_SERIAL_EVENT_RX_IND); + #endif + #ifdef RT_USING_SERIAL_V2 + int ch = -1; + int put_index = 0; + while (1) + { + ch = data->serial.ops->getc(&data->serial); + if (ch == -1) break; + /* disable interrupt */ + level = rt_hw_interrupt_disable(); + data->ep_out->buffer[put_index++] = ch; + /* enable interrupt */ + rt_hw_interrupt_enable(level); + if (put_index >= data->serial.config.rx_bufsz) break; + } + #endif level = rt_hw_interrupt_disable(); - + /* receive data from USB VCOM */ rt_ringbuffer_put(&data->rx_ringbuffer, data->ep_out->buffer, size); rt_hw_interrupt_enable(level); - + #ifdef RT_USING_SERIAL_V2 /* notify receive data */ rt_hw_serial_isr(&data->serial,RT_SERIAL_EVENT_RX_IND); + #endif } data->ep_out->request.buffer = data->ep_out->buffer; @@ -498,8 +517,11 @@ static rt_err_t _function_enable(ufunction_t func) data->ep_out->buffer = rt_malloc(CDC_RX_BUFSIZE); RT_ASSERT(data->ep_out->buffer != RT_NULL); -#ifdef RT_USING_SERIAL_V2 +#if defined(RT_USING_SERIAL_V1) + data->serial.serial_rx = data->ep_out->buffer; +#elif defined(RT_USING_SERIAL_V2) data->serial.serial_rx = &data->rx_ringbuffer; + //data->serial.serial_tx = &data->tx_ringbuffer; #endif data->ep_out->request.buffer = data->ep_out->buffer;