Files
micropython/ports/esp32/modmachine.h
Angus Gratton 371db85c8e esp32/machine_uart: Convert machine.UART objects to static instances.
Makes machine.UART objects static instances (similar to other ports), adds
machine_uart_deinit_all() function for cleanup on soft reset.

- Fixes the case where the OS-level uart_event_task is leaked
  (along with 2KB of heap) when a UART object is garbage collected
  (including after a soft reset).

- Fixes hard fault if a previous UART irq() fires after the UART object is
  garbage collected (including after a soft reset), but before any new UART
  object is instantiated for the same UART number.

- Constructing multiple UART objects for the same UART now returns the
  same instance multiple times, not different instances.

- Was also able to streamline deinit/init to only install the driver once,
  rather than install-with-defaults/uninstall/reinstall.

Alternative would be to add a finaliser, but this is more consistent
with how most other UART objects are implemented.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-09-10 16:18:03 +10:00

716 B