-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now we can split uart into transmit and receive halves. It can be used by bootloaders or firmware to create split stdin and stdout console halves. Signed-off-by: Zhouqi Jiang <[email protected]>
- Loading branch information
Showing
6 changed files
with
239 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[package] | ||
name = "uart-cli-demo" | ||
version = "0.1.0" | ||
edition = "2021" | ||
publish = false | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
bouffalo-hal = { path = "../../../bouffalo-hal", features = ["bl808"] } | ||
bouffalo-rt = { path = "../../../bouffalo-rt", features = ["bl808-dsp"] } | ||
panic-halt = "0.2.0" | ||
embedded-time = "0.12.1" | ||
|
||
[[bin]] | ||
name = "uart-cli-demo" | ||
test = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
UART peripheral demo with embedded-cli library | ||
|
||
Build this example with: | ||
|
||
``` | ||
rustup target install riscv64imac-unknown-none-elf | ||
cargo build --target riscv64imac-unknown-none-elf --release -p uart-cli-demo | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
println!("cargo:rustc-link-arg=-Tbouffalo-rt.ld"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#![no_std] | ||
#![no_main] | ||
|
||
use bouffalo_hal::prelude::*; | ||
use bouffalo_rt::{entry, Clocks, Peripherals}; | ||
use embedded_time::rate::*; | ||
use panic_halt as _; | ||
|
||
#[entry] | ||
fn main(p: Peripherals, c: Clocks) -> ! { | ||
let tx = p.gpio.io14.into_uart(); | ||
let rx = p.gpio.io15.into_uart(); | ||
let sig2 = p.uart_muxes.sig2.into_transmit::<0>(); | ||
let sig3 = p.uart_muxes.sig3.into_receive::<0>(); | ||
|
||
let config = Default::default(); | ||
let serial = p | ||
.uart0 | ||
.freerun(config, 2000000.Bd(), ((tx, sig2), (rx, sig3)), &c); | ||
|
||
let (mut tx, mut rx) = serial.split(); | ||
|
||
let mut buf = [0u8; 1]; | ||
|
||
writeln!(tx, "Hello world!").ok(); | ||
rx.read_exact(&mut buf).ok(); | ||
writeln!(tx, "Character: {}", buf[0]).ok(); | ||
|
||
loop { | ||
// TODO: use embedded-cli to build a serial console | ||
} | ||
} |