Configured the LINFlexD console twice, because once is not enough at -O2 - #629
Merged
fdesbiens merged 1 commit intoAug 17, 2026
Merged
Conversation
The console driver runs its configuration sequence a single time, and that works only because this BSP is built without an optimisation flag. Compiled at -O2 the same sequence leaves the line corrupted: every character partially wrong, in the pattern the file already describes for a misconfigured module. What makes it worth guarding against is that the failure is invisible. UARTCR reads back exactly the value written. LINIBRR and LINFBRR read back exactly the values written. linflexd_init returns LINFLEXD_INIT_OK. The registers are right and the line is wrong, so nothing in the returned status tells the caller the console cannot be trusted. Localised by bisection: with every other file at -O2 and this one at -O0 the output is clean, and with only linflexd_init at -O2 it is corrupted, so the fault is in the configuration sequence rather than in the per-byte transmit path. The mechanism is not understood, and this commit does not claim to explain it. Tested and rejected: a 100x larger bound on the wait for initialisation mode, a settling delay before the first LINSR read, a settling delay after leaving initialisation mode, a barrier and read-back between the two UARTCR writes, and waiting for LINSR to report the exit from initialisation mode. None of those makes a single pass work at -O2. A second pass does, at both optimisation levels, which is what this does. Instrumented with a duplicate of the sequence forced to -O2 and reported through a console repaired afterwards, which is how the register read-backs above were obtained. Verified on the S32Z280-594EVB. The boot image passes six of six probes with the console status still reporting 0x00000000, and the reproducer builds clean and prints correctly at both -O0 and -O2. Assisted-by: Claude Code (Opus 5) <noreply@anthropic.com>
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.
The S32Z280 console driver runs its configuration sequence once, and that works only because this BSP is built without an optimisation flag (
CMAKE_BUILD_TYPEis empty, so everything compiles at-O0). Compiled at-O2the same sequence leaves the line corrupted — every character partially wrong, in exactly the pattern the file already documents for a module configured outside initialisation mode.Why this is worth guarding against
The failure is invisible to the caller:
UARTCRreads back exactly the value written (0x33)LINIBRRreads back 21, the value writtenLINFBRRreads back 11, the value writtenlinflexd_initreturnsLINFLEXD_INIT_OKThe registers are right and the line is wrong. Nothing in the returned status says the console cannot be trusted, which is the worst property a console can have — it is the instrument every other bring-up result is read through.
How it was localised
By bisection rather than inspection:
-O2,linflexd.cat-O0-O0, onlylinflexd_initat-O2-O0, onlylinflexd_putcat-O2So the fault is in the configuration sequence, not the per-byte transmit path. The
putcDTF handshake — whose comment warns that its ordering is load-bearing in both directions — is innocent and untouched.The register read-backs above were obtained by instrumenting a duplicate of the sequence forced to
-O2and reporting its observations through a console repaired afterwards by a known-good pass.What this commit does not claim
The mechanism is not understood. Tested and rejected as explanations:
LINSRreadUARTCRwritesLINSRto report the exit from initialisation modeNone makes a single pass work at
-O2. A second pass does, reliably, at both optimisation levels. Since delays do not help but a second pass does, the evidence points away from timing, and the comment in the code says so and lists what was ruled out, so the next person does not repeat it.Verification
On the S32Z280-594EVB:
0x00000000-O0and-O2, where previously-O2was unreadable