Skip to content

Commit 632e5f9

Browse files
aykevldeadprogram
authored andcommitted
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.
1 parent 3753193 commit 632e5f9

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/machine/machine_rp2_uart.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ func (uart *UART) SetBaudRate(br uint32) {
104104
func (uart *UART) writeByte(c byte) error {
105105
// wait until buffer is not full
106106
for uart.Bus.UARTFR.HasBits(rp.UART0_UARTFR_TXFF) {
107-
gosched()
107+
if !interrupt.In() {
108+
gosched()
109+
}
108110
}
109111

110112
// write data
@@ -114,7 +116,9 @@ func (uart *UART) writeByte(c byte) error {
114116

115117
func (uart *UART) flush() {
116118
for uart.Bus.UARTFR.HasBits(rp.UART0_UARTFR_BUSY) {
117-
gosched()
119+
if !interrupt.In() {
120+
gosched()
121+
}
118122
}
119123
}
120124

0 commit comments

Comments
 (0)