diff --git a/esphome/components/usb_uart/usb_uart.h b/esphome/components/usb_uart/usb_uart.h index c1affe2bc9..91a4329f22 100644 --- a/esphome/components/usb_uart/usb_uart.h +++ b/esphome/components/usb_uart/usb_uart.h @@ -115,17 +115,12 @@ class USBUartChannel : public uart::UARTComponent, public Parenteddata_chunk_pool_[i] = new UsbDataChunk(); this->free_chunks_.push(this->data_chunk_pool_[i]); } } - ~USBUartComponent() { - for (int i = 0; i < MAX_DATA_CHUNKS; i++) { - delete this->data_chunk_pool_[i]; - } - } void setup() override; void loop() override; void dump_config() override; @@ -137,14 +132,17 @@ class USBUartComponent : public usb_host::USBClient { void start_output(USBUartChannel *channel); // Lock-free data transfer from USB task to main loop - LockFreeQueue usb_data_queue_; + static constexpr int USB_DATA_QUEUE_SIZE = 32; + LockFreeQueue usb_data_queue_; protected: std::vector channels_{}; // Pool of pre-allocated data chunks to avoid dynamic allocation - static constexpr int MAX_DATA_CHUNKS = 32; + static constexpr int MAX_DATA_CHUNKS = 40; UsbDataChunk *data_chunk_pool_[MAX_DATA_CHUNKS]; + // IMPORTANT: This is used bidirectionally (USB task pops, main loop pushes) + // which technically violates SPSC, but works in practice because operations are atomic LockFreeQueue free_chunks_; };