STM32 USARTv1/v2/v3: add SerialConfig.external_rx_buffer - #112
Open
bugobliterator wants to merge 1 commit into
Open
bugobliterator wants to merge 1 commit into
bugobliterator wants to merge 1 commit into
Conversation
bugobliterator
force-pushed
the
pr-usart-external-rx-buffer
branch
from
September 11, 2026 03:12
1fb39e4 to
7ab848f
Compare
When set, the driver leaves RXNEIE clear and its interrupt handler never reads the data register to take data (USARTv1 reads it only to clear an error flag). Without this, an IDLE or TX interrupt that finds a byte the external receive path has not taken yet diverts it into the unused input queue, losing it from the stream. Found by inspection while chasing a byte-loss bug that turned out to be a different issue. Issue found and fix developed with the assistance of Claude (Anthropic).
bugobliterator
force-pushed
the
pr-usart-external-rx-buffer
branch
from
September 11, 2026 03:12
7ab848f to
7a3576b
Compare
andyp1per
reviewed
Sep 11, 2026
andyp1per
left a comment
Contributor
There was a problem hiding this comment.
Looks ok to me. Please try and upstream this for maintenance.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ArduPilot receives on USART ports with DMA: it clears
RXNEIEaftersdStart()and keepsIDLEIEon so a partially filled DMA buffer is flushed when the line goes idle. The serial driver's interrupt handler still runs on every IDLE (and TX) interrupt, and its receive loop readsRDRwheneverRXNE/RXFNEis set, with no check that the receive interrupt is actually enabled. A byte that has landed in the RX FIFO but has not yet been fetched by the DMA at that instant is pulled into the SerialDriver input queue, which the DMA receive path never reads. Such a byte would be lost from the stream with no error flag and no DMA drop.The window is the time between the handler sampling
ISRand the DMA serving the request, a few hundred nanoseconds, so it can only matter at multi-megabaud rates with short inter-chunk gaps. The race was found by inspection while chasing a byte-loss bug that turned out to be a different issue altogether. A test that provokes this race deliberately is being written.Fix
New
SerialConfig.external_rx_buffer(USARTv1, v2, v3). When set:sd_lld_start()does not enableRXNEIE;DRonly to clear an error flag and leaves a pending byte alone).Default
false; behaviour for existing users is unchanged. Thedefault_configinitialisers gain the field.Compile-checked on F4 (USARTv1), F7 (USARTv2) and H7 (USARTv3) targets, and run on an STM32H757 with ArduPilot setting the flag whenever RX DMA is enabled.
The issue was found and the fix developed with the assistance of Claude (Anthropic).