USB CDC RX silently drops data when the receive buffer is full

Đang mở
#6,303 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
28/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
go, raspberry-pi
Lĩnh vực
embedded-iot

Hướng nghiên cứu

Start from cdcCallbackRx, which copies incoming USB data into the RX ring buffer and drops whatever exceeds USB.rx.Free(). Reproduce with the linked s1 program on a Pico, then look at how cdc.USB.ReadByte() drains that buffer. Done means the transfer is backpressured instead of truncated, so a 1024-byte send with a 5-second read pause arrives intact. The fix needs a flow-control design choice, so confirm the approach with a maintainer first.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

As mentioned in #6253, I found this while setting up a test environment for that work. Since it causes silent data loss, I'm reporting it separately.

USB CDC RX data is lost on a Raspberry Pi Pico when the application stops reading for 5 seconds.

With the same test program, a 512-byte transfer is received correctly (byte count and SHA-256 match), but a 1024-byte transfer results in only 513 bytes being read.

Steps to reproduce

Minimal reproducer: https://github.com/rdon-key/tinygo-usb-test/tree/main/s1

From the repository root, flash the Pico with TinyGo 0.44.0:

tinygo flash -target=pico -scheduler=tasks ./s1/tinygo/main.go

Run the host program on Windows (adjust the port as needed):

go -C s1/host run . -port COM12 -size 512

Reset the Pico, then run it again with 1024 bytes:

go -C s1/host run . -port COM12 -size 1024

The host sends size bytes where data[i] = byte(i).

On the Pico, the program reads the first byte using cdc.USB.ReadByte(), sleeps for 5 seconds without reading, and then reads for another 3 seconds.

The Pico sends back the number of bytes actually read and their SHA-256 hash. The host compares both with the transmitted data.

Actual result

512 bytes — PASS

S1 - USB CDC RX Data Loss Reproducer
Sent     : 512 B
Received : 512 B
SHA-256  : MATCH
Result   : PASS

1024 bytes — FAIL

S1 - USB CDC RX Data Loss Reproducer
Sent     : 1024 B
Received : 513 B
SHA-256  : MISMATCH
Result   : FAIL
Expected result

USB CDC should not silently lose data when the application temporarily stops reading.

When the receiver cannot accept more data, USB transfers should be backpressured rather than silently discarded.

Environment
  • Board: Raspberry Pi Pico (RP2040)
  • TinyGo: 0.44.0
  • Target: pico
  • Scheduler: tasks
  • Host: Windows AMD64
Notes

The CDC RX ring buffer has a capacity of 512 bytes.

In TinyGo 0.44.0, cdcCallbackRx limits incoming data to the available RX buffer space:

free := USB.rx.Free()
USB.rx.Put(b[:min(len(b), int(free))])

This silently discards any bytes that do not fit. It matches the observed result: 1 byte consumed by ReadByte() + 512 bytes buffered = 513 bytes.

The results above were obtained on Windows. It has not been tested with a Linux host yet.

Ngôn ngữ chính
Go
Star
17.8k
Fork
1.1k
Merge trung bình
1 ngày 4 giờ
Pull request đã merge (30 ngày)
380

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của tinygo-org/tinygo

Tất cả issue của tinygo-org/tinygo

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.