You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Andre Richter 90d88f65b6
Streamlining, cleanup, and minor fixes.
6 years ago
..
.cargo Use aarch64-unknown-none target in nightly 🎉 6 years ago
raspi3_boot 🎉 Update to Rust 2018 🎉 6 years ago
src Streamlining, cleanup, and minor fixes. 6 years ago
Cargo.lock Minor Cargo.lock fix 6 years ago
Cargo.toml Fix accidental local path in dependency 6 years ago
Makefile Streamlining, cleanup, and minor fixes. 6 years ago
README.md UART1 output on QEMU. Rework some Readmes. 6 years ago
kernel8 Streamlining, cleanup, and minor fixes. 6 years ago
kernel8.img Streamlining, cleanup, and minor fixes. 6 years ago
link.ld Alignment. Binaries from newer Rust version. 6 years ago

README.md

Tutorial 05 - UART0, PL011

Finally, we can set up UART0 thanks to the mailbox interface. This tutorial produces the same output as tutorial 04, but it prints the serial number on UART0.

uart.rs

In the init function, we use the mailbox to set a base clock for the UART:

mbox.buffer[0] = 9 * 4;
mbox.buffer[1] = mbox::REQUEST;
mbox.buffer[2] = mbox::tag::SETCLKRATE;
mbox.buffer[3] = 12;
mbox.buffer[4] = 8;
mbox.buffer[5] = mbox::clock::UART; // UART clock
mbox.buffer[6] = 4_000_000; // 4Mhz
mbox.buffer[7] = 0; // skip turbo setting
mbox.buffer[8] = mbox::tag::LAST;

// Insert a compiler fence that ensures that all stores to the
// mbox buffer are finished before the GPU is signaled (which
// is done by a store operation as well).
compiler_fence(Ordering::Release);

if mbox.call(mbox::channel::PROP).is_err() {
    return Err(UartError::MailboxError); // Abort if UART clocks couldn't be set
};

Afterwards, we can program the rate divisors:

self.IBRD.write(IBRD::IBRD.val(2)); // Results in 115200 baud
self.FBRD.write(FBRD::FBRD.val(0xB));

Baud rate calculation won't be covered in detail here. Please see this reference from ARM for details.

The API for using the UART is identical to the UART1 API.

main.rs

We query the board's serial number and display it on the serial console.