Skip to content

arch/arm/imxrt & serial: fix eDMA NCE errors caused by 0-iteration TCD on buffer wrap - #20893

Merged
acassis merged 2 commits into
apache:masterfrom
Sarthak-Pandey:fix/imxrt-lpuart-tcd-citer-zero
Oct 23, 2026
Merged

acassis merged 2 commits into
apache:masterfrom
Sarthak-Pandey:fix/imxrt-lpuart-tcd-citer-zero

Conversation

@Sarthak-Pandey

Copy link
Copy Markdown
Contributor

Summary

Fixes #20881

When the TX ring buffer wraps around with head == 0, uart_xmitchars_dma() sets nbuffer = dev->xmit.buffer and nlength = 0.
In arch/arm/src/imxrt/imxrt_serial.c, imxrt_dma_send() previously only checked if (dev->dmatx.nbuffer). Consequently, a second chained TCD descriptor was allocated and linked with iter = nlength = 0.

Under the i.MX RT eDMA architecture:

  • TCDn_CITER[CITER] = 0 triggers an ES[NCE] (Descriptor Configuration Error).
  • When CONFIG_IMXRT_EDMA_HOE=y (Halt on Error, default), the eDMA engine sets CR[HALT] = 1, freezing all other shared eDMA peripherals (LPSPI IMUs, LPI2C barometers/magnetometers, other UART channels).
  • In addition, imxrt_dmaterminate() did not reset CITER/BITER, leaving residual error state and causing errors in pairs upon channel re-activation.

Solution:

  1. drivers/serial/serial_dma.c: In uart_xmitchars_dma(), set nbuffer = NULL and nlength = 0 when head == 0 on wrap-around, protecting all architectures.
  2. arch/arm/src/imxrt/imxrt_serial.c: In imxrt_dma_send(), guard split-transfer descriptor creation with if (dev->dmatx.nbuffer && dev->dmatx.nlength > 0).
  3. arch/arm/src/imxrt/imxrt_edma.c:
    • In imxrt_dmaterminate(), clear TCD_CITER and TCD_BITER to prevent repeated NCE error traps.
    • In imxrt_dmach_xfrsetup(), validate config->iter > 0 and return -EINVAL if 0.

Impact

  • Users: Resolves critical eDMA lockups and IMU sensor dropouts during high-speed UART DMA transmissions.
  • Hardware: i.MX RT (and all other architectures using serial DMA ring buffers).
  • Compatibility: Fully backward compatible.

Testing

  • Verified on i.MX RT1176 board (PX4 fmu-v6xrt target) with continuous LPUART transmission at 921600 baud.
  • Zero eDMA errors (ES = 0, CR = 0x412), no peripheral pauses or IMU interruptions observed after applying the fix.

When the TX circular buffer wraps around with head == 0,
uart_xmitchars_dma() previously set nbuffer to the start of the buffer
even though nlength was 0. This caused underlying DMA drivers to treat
it as an active split transfer with zero length.

Set nbuffer to NULL and nlength to 0 when head is 0.

Signed-off-by: Sarthak Pandey <[email protected]>
- In imxrt_dma_send(), verify dev->dmatx.nlength > 0 before setting up
  a chained TCD. Chaining a TCD with iter == 0 causes eDMA NCE errors
  and halts the eDMA engine when HOE is enabled.
- In imxrt_dmaterminate(), clear CITER and BITER registers so residual
  zero-iteration states do not trigger repeated NCE errors on channel
  re-activation.
- In imxrt_dmach_xfrsetup(), return -EINVAL if config->iter is 0.

Fixes apache#20881

Signed-off-by: Sarthak Pandey <[email protected]>
@Sarthak-Pandey
Sarthak-Pandey force-pushed the fix/imxrt-lpuart-tcd-citer-zero branch from 286974f to f9c6060 Compare October 22, 2026 21:28
@github-actions github-actions Bot added Arch: arm Issues related to ARM (32-bit) architecture Area: Drivers Drivers issues Size: S The size of the change in this PR is small labels Oct 22, 2026
@github-actions

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

@acassis
acassis merged commit d9a2e42 into apache:master Oct 23, 2026
53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: arm Issues related to ARM (32-bit) architecture Area: Drivers Drivers issues Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] imxrt: LPUART TX DMA links a TCD with CITER = 0 on buffer wrap, causing eDMA NCE errors

3 participants