diff --git a/README.md b/README.md index ef95620..a648910 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,13 @@ The amount of pressure applied determines the radius of the state change. [README](rust/game-of-life/README.md) +rust/uart-passthrough +--------------------- + +Pass through UART from host to the ESP8285 WIFI chip. + +[README](rust/uart-passthrough/README.md) + ROM re'ing =========== diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 3191959..c68c5fa 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -4,6 +4,7 @@ members = [ "mandelbrot", "game-of-life", "accelerometer", + "uart-passthrough", ] [patch.crates-io] diff --git a/rust/uart-passthrough/.cargo/config b/rust/uart-passthrough/.cargo/config new file mode 100644 index 0000000..8bcf92f --- /dev/null +++ b/rust/uart-passthrough/.cargo/config @@ -0,0 +1,8 @@ +[target.riscv64gc-unknown-none-elf] +rustflags = [ + "-C", "link-arg=-Tmemory.x", + "-C", "link-arg=-Tlink.x", +] + +[build] +target = "riscv64gc-unknown-none-elf" diff --git a/rust/uart-passthrough/.gitignore b/rust/uart-passthrough/.gitignore new file mode 100644 index 0000000..f0e3bca --- /dev/null +++ b/rust/uart-passthrough/.gitignore @@ -0,0 +1,2 @@ +/target +**/*.rs.bk \ No newline at end of file diff --git a/rust/uart-passthrough/Cargo.toml b/rust/uart-passthrough/Cargo.toml new file mode 100644 index 0000000..d03a3ab --- /dev/null +++ b/rust/uart-passthrough/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "uart-passthrough" +version = "0.1.0" +authors = ["W.J. van der Laan "] +edition = "2018" + +[dependencies] +nb = "0.1.1" +riscv-rt = "0.5.0" +k210-hal = "0.1.0" +riscv = "0.5" +k210-shared = { path = "../k210-shared" } diff --git a/rust/uart-passthrough/README.md b/rust/uart-passthrough/README.md new file mode 100644 index 0000000..933865f --- /dev/null +++ b/rust/uart-passthrough/README.md @@ -0,0 +1,6 @@ +# `uart-passthrough` + +Pass through UART from host to the ESP8285 WIFI chip. + +Any input from the host is forwarded to the ESP8285, and any input from the ESP8285 +is forwarded to the host. Currently only supports a fixed baudrate of 115200. diff --git a/rust/uart-passthrough/src/main.rs b/rust/uart-passthrough/src/main.rs new file mode 100644 index 0000000..e4af5e9 --- /dev/null +++ b/rust/uart-passthrough/src/main.rs @@ -0,0 +1,41 @@ +#![allow(dead_code)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] +#![no_std] +#![no_main] + +use k210_hal::pac; +use k210_hal::prelude::*; +use k210_shared::board::def::io; +use k210_shared::soc::fpioa; +use k210_shared::soc::sysctl; +use nb::block; +use riscv_rt::entry; + +#[entry] +fn main() -> ! { + let p = pac::Peripherals::take().unwrap(); + let clocks = k210_hal::clock::Clocks::new(); + + // Configure UARTHS (→host) + let serial = p.UARTHS.constrain(115_200.bps(), &clocks); + let (mut tx, mut rx) = serial.split(); + + // Configure UART1 (→WIFI) + sysctl::clock_enable(sysctl::clock::UART1); + sysctl::reset(sysctl::reset::UART1); + fpioa::set_function(io::WIFI_RX as u8, fpioa::function::UART1_TX); + fpioa::set_function(io::WIFI_TX as u8, fpioa::function::UART1_RX); + let wifi_serial = p.UART1.constrain(115_200.bps(), &clocks); + let (mut wtx, mut wrx) = wifi_serial.split(); + + // Relay characters between UARTs + loop { + if let Ok(ch) = wrx.read() { + let _res = block!(tx.write(ch)); + } + if let Ok(ch) = rx.read() { + let _res = block!(wtx.write(ch)); + } + } +}