From 37ff052b34c0c064d0a7c3bfa3f7c8d7291ff62c Mon Sep 17 00:00:00 2001 From: bunnie Date: Sat, 25 Oct 2025 22:23:36 +0800 Subject: [PATCH] chunk data to the USB subsystem the chunks match the size of the application buffer, eliminating the possibility of an overrun (of the buffer at least) there is a possibility still i think of overrunning USB itself but i think the CPU can't produce data fast enough to actually do that. --- services/usb-bao1x/src/main.rs | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/services/usb-bao1x/src/main.rs b/services/usb-bao1x/src/main.rs index a6ce7522b..f7f1d06ce 100644 --- a/services/usb-bao1x/src/main.rs +++ b/services/usb-bao1x/src/main.rs @@ -745,20 +745,10 @@ pub(crate) fn main_hw() -> ! { let buffer = unsafe { Buffer::from_memory_message(mem_msg) }; match buffer.to_original::() { Ok(usb_send) => { - // this is implemented as a "blocking write": the routine will block until the - // data has all been written. - let send_data = usb_send.s.as_bytes(); - let to_send = usb_send.s.len(); - let mut sent = 0; - while sent < to_send { - match cu.serial_port.write(&send_data[sent..to_send]) { - Ok(written) => { - sent += written; - } - Err(_) => { - // just drop characters - } - } + for chunk in + usb_send.s.as_bytes().chunks(bao1x_hal::usb::driver::CRG_UDC_APP_BUFSIZE) + { + cu.serial_port.write(&chunk).ok(); cu.serial_port.flush().ok(); // just drop characters on error } }