From aa3322197a6d16cdc8fa616c181619d774289937 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Wed, 27 Aug 2025 08:14:03 +0200 Subject: [PATCH] rp2040: allow writing to the UART inside interrupts Writing to the UART takes time and that may not be a good idea inside an interrupt, but it is essential for debugging sometimes (especially since USB-CDC typically doesn't work inside an interrupt). This fixes UART support in interrupts for the RP2040 at least. You can test it with `-serial=uart` and connecting a USB-UART adapter to the right pins. --- src/machine/machine_rp2_uart.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/machine/machine_rp2_uart.go b/src/machine/machine_rp2_uart.go index 03ebb9d874..872418a766 100644 --- a/src/machine/machine_rp2_uart.go +++ b/src/machine/machine_rp2_uart.go @@ -104,7 +104,9 @@ func (uart *UART) SetBaudRate(br uint32) { func (uart *UART) writeByte(c byte) error { // wait until buffer is not full for uart.Bus.UARTFR.HasBits(rp.UART0_UARTFR_TXFF) { - gosched() + if !interrupt.In() { + gosched() + } } // write data @@ -114,7 +116,9 @@ func (uart *UART) writeByte(c byte) error { func (uart *UART) flush() { for uart.Bus.UARTFR.HasBits(rp.UART0_UARTFR_BUSY) { - gosched() + if !interrupt.In() { + gosched() + } } }