Repository navigation
machine/nxpmk66f18: do not yield in UART writes from an interrupt - #6117
Open
davecheney wants to merge 1 commit into
Open
davecheney wants to merge 1 commit into
davecheney wants to merge 1 commit into
Conversation
runtime.Gosched has no interrupt check. A UART Write or WriteByte from an interrupt handler with a full TXBuffer called gosched from interrupt context, and the runtime aborted with "fatal error: blocked inside interrupt". println is not affected, it uses PutcharUART. machine_rp2_uart.go avoids this by only yielding outside interrupts. A busy-wait alone is not enough here. TXBuffer is drained by the UART interrupt at priority 64, which cannot run while a handler of equal or higher priority is active, so the handler would wait forever. In interrupt context the wait now moves bytes to the FIFO itself, with interrupts disabled so it does not race the UART interrupt. Flush gets the same treatment. Tested on a Teensy 3.6 with tinygo-org#6026 and tinygo-org#6027 applied: a handler writing 12 lines of 64 bytes aborted before this change, and now completes at priority 0x20 and 0x80 with every byte intact.
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.
runtime.Gosched has no interrupt check. A UART Write or WriteByte from an interrupt handler with a full TXBuffer called gosched from interrupt context, and the runtime aborted with "fatal error: blocked inside interrupt". println is not affected, it uses PutcharUART. machine_rp2_uart.go avoids this by only yielding outside interrupts.
A busy-wait alone is not enough here. TXBuffer is drained by the UART interrupt at priority 64, which cannot run while a handler of equal or higher priority is active, so the handler would wait forever. In interrupt context the wait now moves bytes to the FIFO itself, with interrupts disabled so it does not race the UART interrupt. Flush gets the same treatment.
Tested on a Teensy 3.6 with #6026 and #6027 applied: a handler writing 12 lines of 64 bytes aborted before this change, and now completes at priority 0x20 and 0x80 with every byte intact.