Skip to content

Commit 5daa852

Browse files
committed
UART embedded-io fixes
1 parent 3bc2ee4 commit 5daa852

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

va108xx-hal/CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88

99
## [unreleased]
1010

11+
## [v0.11.1] 2025-03-10
12+
13+
## Fixed
14+
15+
- Fix `embedded_io` UART implementation to implement the documented contract properly.
16+
The implementation will now block until at least one byte is available or can be written, unless
17+
the send or receive buffer is empty.
18+
1119
## [v0.11.0] 2025-03-07
1220

1321
## Changed
@@ -253,6 +261,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
253261
- README with basic instructions how to set up own binary crate
254262

255263
[unreleased]: https://egit.irs.uni-stuttgart.de/rust/va108xx-rs/compare/va108xx-hal-v0.11.0...HEAD
264+
[v0.11.1]: https://egit.irs.uni-stuttgart.de/rust/va108xx-rs/compare/va108xx-hal-v0.11.0...va108xx-hal-v0.11.1
256265
[v0.11.0]: https://egit.irs.uni-stuttgart.de/rust/va108xx-rs/compare/va108xx-hal-v0.10.0...va108xx-hal-v0.11.0
257266
[v0.10.0]: https://egit.irs.uni-stuttgart.de/rust/va108xx-rs/compare/va108xx-hal-v0.9.0...va108xx-hal-v0.10.0
258267
[v0.9.0]: https://egit.irs.uni-stuttgart.de/rust/va108xx-rs/compare/va108xx-hal-v0.8.0...va108xx-hal-v0.9.0

va108xx-hal/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "va108xx-hal"
3-
version = "0.11.0"
3+
version = "0.11.1"
44
authors = ["Robin Mueller <[email protected]>"]
55
edition = "2021"
66
description = "HAL for the Vorago VA108xx family of microcontrollers"

va108xx-hal/src/uart/mod.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,15 @@ impl<Uart: Instance> embedded_hal_nb::serial::Read<u8> for Rx<Uart> {
892892

893893
impl<Uart: Instance> embedded_io::Read for Rx<Uart> {
894894
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
895+
if buf.is_empty() {
896+
return Ok(0);
897+
}
895898
let mut read = 0;
899+
loop {
900+
if self.0.rxstatus().read().rdavl().bit_is_set() {
901+
break;
902+
}
903+
}
896904
for byte in buf.iter_mut() {
897905
match <Self as embedded_hal_nb::serial::Read<u8>>::read(self) {
898906
Ok(w) => {
@@ -1058,6 +1066,14 @@ impl<Uart: Instance> embedded_hal_nb::serial::Write<u8> for Tx<Uart> {
10581066

10591067
impl<Uart: Instance> embedded_io::Write for Tx<Uart> {
10601068
fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
1069+
if buf.is_empty() {
1070+
return Ok(0);
1071+
}
1072+
loop {
1073+
if self.0.txstatus().read().wrrdy().bit_is_set() {
1074+
break;
1075+
}
1076+
}
10611077
let mut written = 0;
10621078
for byte in buf.iter() {
10631079
match <Self as embedded_hal_nb::serial::Write<u8>>::write(self, *byte) {
@@ -1066,7 +1082,7 @@ impl<Uart: Instance> embedded_io::Write for Tx<Uart> {
10661082
}
10671083
}
10681084

1069-
Ok(buf.len())
1085+
Ok(written)
10701086
}
10711087

10721088
fn flush(&mut self) -> Result<(), Self::Error> {

0 commit comments

Comments
 (0)