From 3e98fbcdc8d862f9725d5b5fa6331620c2a0ff76 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Thu, 4 Oct 2018 13:36:38 +0200 Subject: [PATCH] avr: use machine.UART0 as stdout --- src/machine/machine_avr.go | 7 +++++-- src/runtime/runtime_avr.go | 13 +++---------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/machine/machine_avr.go b/src/machine/machine_avr.go index ff02d052..993276d3 100644 --- a/src/machine/machine_avr.go +++ b/src/machine/machine_avr.go @@ -291,8 +291,11 @@ func (uart UART) Configure(config UARTConfig) { *avr.UBRR0H = avr.RegValue(ps >> 8) *avr.UBRR0L = avr.RegValue(ps & 0xff) - // enable RX interrupt - *avr.UCSR0B |= avr.UCSR0B_RXCIE0 + // enable RX, TX and RX interrupt + *avr.UCSR0B = avr.UCSR0B_RXEN0 | avr.UCSR0B_TXEN0 | avr.UCSR0B_RXCIE0 + + // 8-bits data + *avr.UCSR0C = avr.UCSR0C_UCSZ01 | avr.UCSR0C_UCSZ00 } // WriteByte writes a byte of data to the UART. diff --git a/src/runtime/runtime_avr.go b/src/runtime/runtime_avr.go index 6c369ff0..070e146d 100644 --- a/src/runtime/runtime_avr.go +++ b/src/runtime/runtime_avr.go @@ -4,6 +4,7 @@ package runtime import ( "device/avr" + "machine" "unsafe" ) @@ -54,19 +55,11 @@ func init() { } func initUART() { - // Initialize UART at 9600 baud when running at 16MHz. - *avr.UBRR0H = 0 - *avr.UBRR0L = 0x67 - - *avr.UCSR0B = avr.UCSR0B_RXEN0 | avr.UCSR0B_TXEN0 // enable RX and TX - *avr.UCSR0C = avr.UCSR0C_UCSZ01 | avr.UCSR0C_UCSZ00 // 8-bits data + machine.UART0.Configure(machine.UARTConfig{}) } func putchar(c byte) { - for (*avr.UCSR0A & avr.UCSR0A_UDRE0) == 0 { - // Wait until previous char has been sent. - } - *avr.UDR0 = avr.RegValue(c) // send char + machine.UART0.WriteByte(c) } // Sleep this number of ticks of 16ms.