From 9ea7d7a8044641e5d6307c5794b698e853de725b Mon Sep 17 00:00:00 2001 From: whitequark Date: Wed, 14 Mar 2018 18:34:31 +0000 Subject: [PATCH] firmware: allow building without system UART. --- artiq/firmware/libboard/lib.rs | 1 + artiq/firmware/libboard/uart_console.rs | 10 +++++++++- artiq/firmware/runtime/main.rs | 20 +++++++++++--------- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/artiq/firmware/libboard/lib.rs b/artiq/firmware/libboard/lib.rs index 4d0311719..a685f5252 100644 --- a/artiq/firmware/libboard/lib.rs +++ b/artiq/firmware/libboard/lib.rs @@ -18,6 +18,7 @@ include!(concat!(env!("BUILDINC_DIRECTORY"), "/generated/sdram_phy.rs")); pub mod sdram; pub mod ident; pub mod clock; +#[cfg(has_uart)] pub mod uart; #[cfg(has_spiflash)] pub mod spiflash; diff --git a/artiq/firmware/libboard/uart_console.rs b/artiq/firmware/libboard/uart_console.rs index 5a1c82f7c..a63adeea1 100644 --- a/artiq/firmware/libboard/uart_console.rs +++ b/artiq/firmware/libboard/uart_console.rs @@ -1,16 +1,24 @@ use core::fmt; -use csr; pub struct Console; impl fmt::Write for Console { + #[cfg(has_uart)] fn write_str(&mut self, s: &str) -> Result<(), fmt::Error> { + use csr; + for c in s.bytes() { unsafe { while csr::uart::txfull_read() != 0 {} csr::uart::rxtx_write(c) } } + + Ok(()) + } + + #[cfg(not(has_uart))] + fn write_str(&mut self, _s: &str) -> Result<(), fmt::Error> { Ok(()) } } diff --git a/artiq/firmware/runtime/main.rs b/artiq/firmware/runtime/main.rs index 20261c025..6fce27df4 100644 --- a/artiq/firmware/runtime/main.rs +++ b/artiq/firmware/runtime/main.rs @@ -77,17 +77,19 @@ fn startup() { #[cfg(has_serwb_phy_amc)] board_artiq::serwb::wait_init(); - let t = board::clock::get_ms(); - info!("press 'e' to erase startup and idle kernels..."); - while board::clock::get_ms() < t + 1000 { - if unsafe { board::csr::uart::rxtx_read() == b'e' } { - config::remove("startup_kernel").unwrap(); - config::remove("idle_kernel").unwrap(); - info!("startup and idle kernels erased"); - break + #[cfg(has_uart)] { + let t = board::clock::get_ms(); + info!("press 'e' to erase startup and idle kernels..."); + while board::clock::get_ms() < t + 1000 { + if unsafe { board::csr::uart::rxtx_read() == b'e' } { + config::remove("startup_kernel").unwrap(); + config::remove("idle_kernel").unwrap(); + info!("startup and idle kernels erased"); + break + } } + info!("continuing boot"); } - info!("continuing boot"); #[cfg(has_i2c)] board_artiq::i2c::init();