mirror of
https://github.com/esphome/esphome.git
synced 2026-02-28 18:04:19 -07:00
6d1fa9fa725f33845a4e8b1a8c6a5bbcf7dc78ec
Remove the FreeRTOS mutex (lock_) that wrapped all ESP-IDF UART driver calls. A codebase audit confirmed all UART wrapper methods (read_array, write_array, peek_byte, available, flush) are called exclusively from the cooperative main loop. The lock was protecting single-threaded code from itself and added 4 unnecessary semaphore operations per read_array call on the hot path. Fix a race condition in rx_event_task_func where uart_flush_input() was called from a separate FreeRTOS task without taking the lock, racing with read_array() on the main loop. This could destroy ring buffer data mid-read, causing data loss. The flush was also unnecessary since the ESP-IDF driver self-heals the buffer-full condition: uart_read_bytes() internally calls uart_check_buf_full() which moves stashed FIFO bytes back into the ring buffer and re-enables RX interrupts. Move the event queue allocation behind USE_UART_WAKE_LOOP_ON_RX. When the feature is disabled, uart_driver_install is called with queue_size=0 and uart_queue=NULL (the documented API for skipping the event queue). This saves ~320 bytes of RAM per UART instance and reduces ISR overhead since the driver skips xQueueSendFromISR when no queue exists. Add thread safety documentation to the class and rx_event_task.
Description
ESPHome is a system to control your ESP8266/ESP32 by simple yet powerful configuration files and control them remotely through Home Automation systems.
Readme
Multiple Licenses
518 MiB
Languages
C++
64.1%
Python
35.5%
C
0.3%
