Skip to content

Commit

Permalink
uart: refactor uart module to build async/await serial structure (#9)
Browse files Browse the repository at this point in the history
* uart: refactor uart module to build async/await serial structure

The original serial structures were renamed to `BlockingSerial`, `BlockingTransmitHalf` and `BlockingReceiveHalf`. The new `Serial` structure dedicates to async/await function.

Serial constructors now returns error instead of panicking in the HAL crate. Examples are modified to unwrap the return value of the constructor. Ref: https://docs.embassy.dev/embassy-stm32/git/stm32f746ve/usart/struct.Uart.html#method.new

The serial `uart` module is rearranged into files for clearance of code.

* rt: introduce DspInterrupt structure which implements plic::InterruptSource

Implement interrupt enable, initialize RISC-V interrupt in uart-async-demo example

* example: enable interrupt using PLIC in uart-async-demo

TODO: check if T-Head C906 PLIC is different from standard PLIC. If so, we'd contribute the non-standard PLIC into `xuantie` crate.

* hal: uart: use freerun mode on AsyncSerial structure

* rt: fix test error by using xuantie repository commit fe7ec712

---------

Signed-off-by: Zhouqi Jiang <luojia@hust.edu.cn>
luojia65 authored Dec 15, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 80d337f commit 1a354d2
Showing 26 changed files with 2,373 additions and 1,939 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/Cargo.yml
Original file line number Diff line number Diff line change
@@ -42,13 +42,13 @@ jobs:
matrix:
TARGET: [riscv64imac-unknown-none-elf]
TOOLCHAIN: [nightly]
EXAMPLES: [gpio-demo, i2c-demo, jtag-demo, lz4d-demo, psram-demo, pwm-demo,
sdcard-demo, sdcard-gpt-demo, spi-demo, uart-demo]
EXAMPLES: [gpio-demo, i2c-demo, jtag-demo, lz4d-demo, pwm-demo,
sdcard-demo, sdcard-gpt-demo, spi-demo, uart-demo, uart-async-demo, uart-cli-demo]
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
target: ${{ MATRIX.TARGET }}
toolchain: ${{ MATRIX.TOOLCHAIN }}
- name: Run build
run: cargo build --target ${{ MATRIX.TARGET }} --release -p ${{ MATRIX.EXAMPLES }}
run: cargo build --target ${{ MATRIX.TARGET }} --release -p ${{ MATRIX.EXAMPLES }}
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ members = [
"examples/peripherals/pwm-demo",
"examples/peripherals/spi-demo",
"examples/peripherals/uart-demo",
"examples/peripherals/uart-async-demo",
"examples/peripherals/uart-cli-demo",
"examples/peripherals/sdcard-demo",
"examples/peripherals/sdcard-gpt-demo",
2 changes: 2 additions & 0 deletions bouffalo-hal/Cargo.toml
Original file line number Diff line number Diff line change
@@ -20,6 +20,8 @@ as-slice = "0.2.1"
nb = "1.1.0"
# For backward compatibility only.
embedded-hal-027 = { package = "embedded-hal", version = "0.2.7" }
embedded-io-async = "0.6.1"
atomic-waker = "1.1.2"

[dev-dependencies]
memoffset = "0.9.0"
1 change: 1 addition & 0 deletions bouffalo-hal/src/lib.rs
Original file line number Diff line number Diff line change
@@ -39,6 +39,7 @@ pub mod prelude {
pub use embedded_hal::i2c::I2c as _;
pub use embedded_hal::pwm::SetDutyCycle as _;
pub use embedded_io::{Read as _, Write as _};
pub use embedded_io_async::{Read as _, Write as _};
}

/// Wrapper type for manipulations of a field in a register.
Loading

0 comments on commit 1a354d2

Please sign in to comment.