Index: libs/usart/usart.c
===================================================================
--- libs/usart/usart.c	(revision 6f227546ef38cc47b1c29f7ab2ec23f8e18ebffd)
+++ libs/usart/usart.c	(revision e5dd493b7c3c3ead0be3dcdea9ecd5ec46b1a067)
@@ -8,15 +8,18 @@
 #endif
 
-#ifdef __AVR_ATmega128__
 // FIXME there are two USARTs in this case and we should be able to drive either
-#define UBRRH UBRR0H
-#define UBRRL UBRR0L
-#define UCSRA UCSR0A
-#define UCSRC UCSR0C
-#define UCSRB UCSR0B
-#define UDR   UDR0
+
+// Compatibility for devices with single USART only
+#ifdef __AVR_ATmega8__
+#define UBRR0H UBRRH
+#define UBRR0L UBRRL
+#define UCSR0A UCSRA
+#define UCSR0C UCSRC
+#define UCSR0B UCSRB
+#define UDR0   UDR
+#define UDRE0  UDRE
+#define RXC0   RXC
 #endif
 
-//This function is used to initialize the USART
 void USARTInit()
 {
@@ -51,6 +54,4 @@
 
 
-//This fuction writes the given "data" to
-//the USART which then transmit it via TX line
 void USARTWriteChar(char data)
 {
@@ -67,7 +68,4 @@
 
 
-//This function is used to read the available data
-//from USART. This function will wait untill data is
-//available.
 char USARTReadChar()
 {
Index: libs/usart/usart.h
===================================================================
--- libs/usart/usart.h	(revision 6f227546ef38cc47b1c29f7ab2ec23f8e18ebffd)
+++ libs/usart/usart.h	(revision e5dd493b7c3c3ead0be3dcdea9ecd5ec46b1a067)
@@ -1,9 +1,30 @@
 /* USART i/o library
- * Copyright 2010-2014, Adrien Destugues <pulkomandy@pulkomandy.tk>
+ * Copyright 2010-2019, Adrien Destugues <pulkomandy@pulkomandy.tk>
  * Distributed under the terms of the MIT Licence */
 
-#include <stdint.h>
+/** Initialize the USART.
+ *
+ * Baudrate is set according to the BAUD define.
+ * Currently the USART is set to 8N1, except on ATmega128 where it's set to 7E1
+ * (don't ask why, I don't remember). This should be made configurable.
+ *
+ * On ATmega128, this always uses the first USART.
+ */
+void USARTInit();
 
-void USARTInit();
+/** Write a byte to the USART.
+ *
+ * This function blocks if the USART is not ready to accept any data. There is
+ * no IO buffering.
+ */
 void USARTWriteChar(char data);
+
+/** Write an 8bit integer as hex to the USART.
+ */
 void USARTWriteHex(unsigned char i);
+
+/** This function is used to read the available data from USART.
+ *
+ * It waits untill data is available.
+ */
+char USARTReadChar();
Index: test_uart/Makefile
===================================================================
--- test_uart/Makefile	(revision 6f227546ef38cc47b1c29f7ab2ec23f8e18ebffd)
+++ test_uart/Makefile	(revision e5dd493b7c3c3ead0be3dcdea9ecd5ec46b1a067)
@@ -1,11 +1,22 @@
+MCU=atmega8
+BAUD=57600
+FCPU=16000000
+PROG=avr109 -P /dev/ports/usb0 -b $(BAUD) -u
+
 testusart.hex: testusart.bin
 	avr-objcopy -j .text -j .data -O ihex testusart.bin testusart.hex
 
 testusart.bin: usart.o main.o
-	avr-gcc usart.o main.o -o testusart.bin -mmcu=atmega8 -Os
+	avr-gcc usart.o main.o -o testusart.bin -mmcu=$(MCU) -Os
 
 main.o: testuart.c ../libs/usart/usart.h
-	avr-gcc -c testuart.c -mmcu=atmega8 -Os -o main.o -mmcu=atmega8 -Os
+	avr-gcc -c testuart.c -mmcu=$(MCU) -Os -o main.o
 
 usart.o: ../libs/usart/usart.c ../libs/usart/usart.h
-	avr-gcc -c ../libs/usart/usart.c -o usart.o -mmcu=atmega8 -Os
+	avr-gcc -c ../libs/usart/usart.c -o usart.o -mmcu=$(MCU) -DBAUD=$(BAUD) -DF_CPU=$(FCPU) -Os
+
+flash: testusart.hex
+	avrdude -c $(PROG) -p $(MCU) -Uflash:w:testusart.hex
+
+clean:
+	rm *.bin *.o *.hex
Index: test_uart/testuart.c
===================================================================
--- test_uart/testuart.c	(revision 6f227546ef38cc47b1c29f7ab2ec23f8e18ebffd)
+++ test_uart/testuart.c	(revision e5dd493b7c3c3ead0be3dcdea9ecd5ec46b1a067)
@@ -3,5 +3,5 @@
 void main(void)
 {
-	USARTInit(51);
+	USARTInit();
 	USARTWriteChar('Z');
 	while(1);
Index: test_uart/testusart.hex
===================================================================
--- test_uart/testusart.hex	(revision 6f227546ef38cc47b1c29f7ab2ec23f8e18ebffd)
+++ test_uart/testusart.hex	(revision e5dd493b7c3c3ead0be3dcdea9ecd5ec46b1a067)
@@ -2,9 +2,9 @@
 :1000100012C011C010C00FC00EC00DC00CC00BC06C
 :100020000AC009C008C011241FBECFE5D4E0DEBF5E
-:10003000CDBF26D02BC0E4CF89B990BD86E880BD66
-:1000400088E18AB908955D9BFECF8CB908955F9BC6
-:10005000FECF8CB10895982F92959F709A3010F42E
-:10006000905D01C0995C5D9BFECF9CB98F708A301A
-:1000700010F4805D01C0895C5D9BFECF8CB9089552
-:1000800083E390E0D9DF8AE5DEDFFFCFF894FFCF8E
+:10003000CDBF26D029C0E4CF10BC82E289B9599A3D
+:1000400086E880BD88E18AB908955D9BFECF8CB9B2
+:1000500008955F9BFECF8CB10895CF93C82F8295F2
+:100060008F708A3048F4805DF0DF8C2F8F708A307B
+:1000700028F4805DCF91E9CF895CF6CF895CFACF17
+:0C008000DBDF8AE5E2DFFFCFF894FFCF62
 :00000001FF
