Skip to content

Commit d11d208

Browse files
committed
implement Stderr in vexos PAL
1 parent 24e381c commit d11d208

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

library/std/src/sys/pal/vexos/stdio.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,26 @@ impl Stderr {
7272

7373
impl io::Write for Stderr {
7474
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
75-
Ok(buf.len())
75+
let written =
76+
unsafe { vex_sdk::vexSerialWriteBuffer(STDIO_CHANNEL, buf.as_ptr(), buf.len() as u32) };
77+
78+
if written < 0 {
79+
return Err(io::Error::new(
80+
io::ErrorKind::Uncategorized,
81+
"Internal write error occurred.",
82+
));
83+
}
84+
85+
Ok(written as usize)
7686
}
7787

7888
fn flush(&mut self) -> io::Result<()> {
89+
unsafe {
90+
while (vex_sdk::vexSerialWriteFree(STDIO_CHANNEL) as usize) != STDOUT_BUF_SIZE {
91+
vex_sdk::vexTasksRun();
92+
}
93+
}
94+
7995
Ok(())
8096
}
8197
}

src/doc/rustc/src/platform-support/armv7a-vex-v5.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ This target generates binaries in the ELF format that may uploaded to the brain
3030
This includes:
3131

3232
- `std::time`, not including `SystemTime` as the SDK does not provide absolute time information.
33-
- `std::io`, including `stdin()` and `stdout()`, but not `stderr()`, as stderr does not exist on this platform.
33+
- `std::io`, including `stdin`/`stdout`/`stderr`. `stdout` and `stderr` are both written to USB channel 1 on this platform and are not differentiated.
3434
- `std::fs`, with the exception of directory reading and file deletion, due to public SDK limitations.
3535
- modules which do not need to interact with the OS beyond allocation,
3636
such as `std::collections`, `std::hash`, `std::future`, `std::sync`, etc.

0 commit comments

Comments
 (0)