mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-21 04:49:04 +00:00
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.
This commit is contained in:
committed by
Ron Evans
parent
37531930b8
commit
632e5f9872
@@ -104,8 +104,10 @@ func (uart *UART) SetBaudRate(br uint32) {
|
|||||||
func (uart *UART) writeByte(c byte) error {
|
func (uart *UART) writeByte(c byte) error {
|
||||||
// wait until buffer is not full
|
// wait until buffer is not full
|
||||||
for uart.Bus.UARTFR.HasBits(rp.UART0_UARTFR_TXFF) {
|
for uart.Bus.UARTFR.HasBits(rp.UART0_UARTFR_TXFF) {
|
||||||
|
if !interrupt.In() {
|
||||||
gosched()
|
gosched()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// write data
|
// write data
|
||||||
uart.Bus.UARTDR.Set(uint32(c))
|
uart.Bus.UARTDR.Set(uint32(c))
|
||||||
@@ -114,9 +116,11 @@ func (uart *UART) writeByte(c byte) error {
|
|||||||
|
|
||||||
func (uart *UART) flush() {
|
func (uart *UART) flush() {
|
||||||
for uart.Bus.UARTFR.HasBits(rp.UART0_UARTFR_BUSY) {
|
for uart.Bus.UARTFR.HasBits(rp.UART0_UARTFR_BUSY) {
|
||||||
|
if !interrupt.In() {
|
||||||
gosched()
|
gosched()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// SetFormat for number of data bits, stop bits, and parity for the UART.
|
// SetFormat for number of data bits, stop bits, and parity for the UART.
|
||||||
func (uart *UART) SetFormat(databits, stopbits uint8, parity UARTParity) error {
|
func (uart *UART) SetFormat(databits, stopbits uint8, parity UARTParity) error {
|
||||||
|
|||||||
Reference in New Issue
Block a user