rust-raspberrypi-OS-tutorials/03_uart1
Andre Richter a3fef3844d Add deref comment to tutorial 3 as well
This is the first time reader will encounter it.
2018-04-13 22:11:42 +02:00
..
raspi3_glue Remove own boilerplate code 2018-04-10 21:26:09 +02:00
src Add deref comment to tutorial 3 as well 2018-04-13 22:11:42 +02:00
aarch64-raspi3-none-elf.json Add abi blacklist for target 2018-04-09 22:11:43 +02:00
Cargo.lock Remove own boilerplate code 2018-04-10 21:26:09 +02:00
Cargo.toml Add tutorial 03_uart1 2018-04-01 16:50:16 +02:00
kernel8.img Add Deref trait in the spirit of cortex-m peripherals 2018-04-13 22:05:50 +02:00
link.ld Add tutorial 03_uart1 2018-04-01 16:50:16 +02:00
Makefile Fix clippy targets 2018-04-09 22:18:27 +02:00
README.md minor style fixes 2018-04-04 20:41:33 +02:00

Tutorial 03 - UART1, Auxilary mini UART

It is time for the famous Hello World example. We're going to write on the UART1 first, as it's easier to program as it has a fixed clocked frequency.

NOTE: qemu does not redirect UART1 to terminal by default, only UART0!

gpio.rs

We have a new header file. This defines the base MMIO address, and the GPIO controller's addresses. This file going to be very popular, as many device needs it.

We are using the volatile_register crate to modify MMIO addresses, because it allows easy wrapping of addresses to volatile types. It will also be used for UART registers.

uart.rs

A very minimal implementation.

MiniUart::init(&self) initializes the device and maps it to the GPIO ports.

MiniUart::send(&self, c: char) sends a character over the serial line.

MiniUart::getc(&self) receives a character. The carrige return character (13) will be converted into a newline character (10).

MiniUart::puts(&self, string: &str) prints out a string. On newline, a carrige return character will also be sent (13 + 10).

main.rs

First we have to call the uart initialization code. Then we wait for the first keypress from the user before we say "Hello Rustacean!". If you've purchased an USB serial cable, you should see it on screen's screen. After that, every character typed in screen will be echoed back. If you haven't turned off local echo, that means you'll see every pressed key twice.