yangsong8-a1 opened a new pull request, #22160: URL: https://github.com/apache/nuttx/pull/22160
## Summary With `CONFIG_ESP32_SPIRAM`, `esp32_dmasend()` copied a TX buffer in PSRAM to a buffer from `kmm_malloc()` / `xtensa_imm_malloc()`, started the DMA on it and freed it right away: - `dmasend()` runs with `uart_spinlock()` held (since #21746), and from interrupt context through `uart_putchars()`; the heap takes a mutex. - The buffer was freed while the DMA still read it. Copy to a static buffer in internal RAM instead, one per UART with TX DMA, of the size of its TX buffer. The next transfer of a UART only starts after its DMA interrupt releases `dma_sem`, so the buffer is not reused while the DMA reads it. ## Impact esp32 with `CONFIG_ESP32_UARTn_TXDMA` (EXPERIMENTAL) and `CONFIG_ESP32_SPIRAM`: `CONFIG_UARTn_TXBUFSIZE` bytes more internal RAM per such UART, no heap use in the TX path. Without SPIRAM nothing changes. No in-tree defconfig enables UART TX DMA. ## Testing No xtensa-esp32 toolchain or board here. I configured `esp32-devkitc:psram` with `CONFIG_EXPERIMENTAL=y` and `CONFIG_ESP32_UART0_TXDMA=y` (SMP), and compiled `esp32_serial.c` with xtensa-esp32s3-elf-gcc 12.2.0 (esp-12.2.0_20230208) and the flags of the real build, minus `-mfix-esp32-psram-cache-*`, with SPIRAM enabled and disabled: no warnings. Not tested: a full esp32 build, any hardware. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
