rust: Add uart-passthrough

This commit is contained in:
Wladimir J. van der Laan 2019-05-20 13:49:43 +00:00
parent f046ca6066
commit a9b7ed1a43
7 changed files with 77 additions and 0 deletions

View File

@ -125,6 +125,13 @@ The amount of pressure applied determines the radius of the state change.
[README](rust/game-of-life/README.md) [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 ROM re'ing
=========== ===========

View File

@ -4,6 +4,7 @@ members = [
"mandelbrot", "mandelbrot",
"game-of-life", "game-of-life",
"accelerometer", "accelerometer",
"uart-passthrough",
] ]
[patch.crates-io] [patch.crates-io]

View File

@ -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"

2
rust/uart-passthrough/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/target
**/*.rs.bk

View File

@ -0,0 +1,12 @@
[package]
name = "uart-passthrough"
version = "0.1.0"
authors = ["W.J. van der Laan <laanwj@protonmail.com>"]
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" }

View File

@ -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.

View File

@ -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));
}
}
}