Skip to content

Commit ca075b3

Browse files
Merge pull request #1048 from knurling-rs/fix-qemu-run-uart
Fix qemu-run uart printing
2 parents 533d73a + 4f1d3f3 commit ca075b3

3 files changed

Lines changed: 22 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ Initial release
969969

970970
### [qemu-run-next]
971971

972-
* No changes
972+
* [#1048] Fixed UART read timeout issue ([#1047])
973973

974974
### [qemu-run-v0.1.1]
975975

@@ -1005,6 +1005,8 @@ Initial release
10051005
---
10061006

10071007
[#1049]: https://github.com/knurling-rs/defmt/pull/1049
1008+
[#1048]: https://github.com/knurling-rs/defmt/pull/1048
1009+
[#1047]: https://github.com/knurling-rs/defmt/pull/1047
10081010
[#1041]: https://github.com/knurling-rs/defmt/pull/1041
10091011
[#1036]: https://github.com/knurling-rs/defmt/pull/1036
10101012
[#1028]: https://github.com/knurling-rs/defmt/pull/1028

qemu-run/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Set as your cargo runner, e.g. in your `.cargo/config.toml` file:
1111

1212
```toml
1313
[target.thumbv7em-none-eabihf]
14-
runner = "qemu-run -machine lm3s6965evb"
14+
runner = "qemu-run --machine lm3s6965evb --cpu cortex-m3"
1515
```
1616

1717
It will execute `qemu-system-arm`, pass the given `-machine` argument, pass
@@ -20,6 +20,9 @@ additional arguments to configure semihosting, and pipe semihosting data into
2020

2121
Run `qemu-run --help` to see a list of other command-line arguments available.
2222

23+
Note that `qemu-system-arm` takes long arguments with a single dash (`-`), but
24+
`qemu-run` takes long arguments with a double dash (`--`).
25+
2326
## MSRV
2427

2528
The minimum supported Rust version is 1.83. This crate is tested against the latest stable Rust version and the MSRV.

qemu-run/src/main.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,18 +310,29 @@ fn print_version() -> anyhow::Result<Option<i32>> {
310310

311311
/// Dumps UTF-8 data received on a socket to stdout, line by line
312312
fn print_loop(socket: std::net::TcpListener) {
313+
use std::io::{BufReader, ErrorKind};
313314
for conn in socket.incoming().flatten() {
314315
conn.set_read_timeout(Some(std::time::Duration::from_millis(100)))
315316
.expect("Setting socket timeout");
316-
let mut reader = std::io::BufReader::new(conn);
317+
let mut reader = BufReader::new(conn);
317318
loop {
318319
let mut buffer = String::new();
319-
let Ok(_len) = reader.read_line(&mut buffer) else {
320-
break;
321-
};
320+
let res = reader.read_line(&mut buffer);
322321
if !buffer.is_empty() {
323322
log::info!("UART got: {:?}", buffer);
324323
}
324+
match res {
325+
Ok(_n) => {
326+
// do nothing
327+
}
328+
Err(e) if e.kind() == ErrorKind::TimedOut || e.kind() == ErrorKind::WouldBlock => {
329+
// do nothing
330+
}
331+
Err(e) => {
332+
log::warn!("UART disconnected ({e:?}");
333+
break;
334+
}
335+
}
325336
}
326337
}
327338
}

0 commit comments

Comments
 (0)