Skip to content

machine/nxpmk66f18: do not yield in UART writes from an interrupt - #6117

Open
davecheney wants to merge 1 commit into
tinygo-org:devfrom
davecheney:mk66-uart-irq-gosched
Open

davecheney wants to merge 1 commit into
tinygo-org:devfrom
davecheney:mk66-uart-irq-gosched

Conversation

@davecheney

Copy link
Copy Markdown
Contributor

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.

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.
@davecheney davecheney added this to the 0.45 milestone Oct 31, 2026
@davecheney
davecheney marked this pull request as ready for review October 31, 2026 08:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant