Skip to content

Commit 0dd14a8

Browse files
authored
Merge pull request #50 from asanza/master
Support WRITEC Semihosting command.
2 parents 1528d08 + 01c491e commit 0dd14a8

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/semihost.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ pub fn get_semihost_func(start: Instant) -> impl FnMut(&SemihostingCommand) -> S
8282
SemihostingResponse::SysIstty { result: Err(-1) }
8383
}
8484
}
85+
SemihostingCommand::SysWriteC {ref data} => {
86+
// println!("writec: data={:?}", data);
87+
print!("{}", *data as char);
88+
io::stdout().flush().expect("Could not flush stdout");
89+
SemihostingResponse::SysWrite { result: Ok(0) }
90+
}
8591
SemihostingCommand::SysWrite { handle, ref data } => {
8692
// println!("write: handle={}, data={:?}", handle, data);
8793
if *handle == TT_HANDLE_STDOUT {

zmu_cortex_m/src/semihosting/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ pub enum SemihostingCommand {
107107
handle: u32,
108108
},
109109
///
110+
/// Write single char to the debug console
111+
///
112+
SysWriteC {
113+
/// char to write
114+
data: u8,
115+
},
116+
///
110117
/// Write data to open file handle
111118
///
112119
SysWrite {
@@ -230,6 +237,7 @@ pub enum SemihostingResponse {
230237

231238
const SYS_OPEN: u32 = 0x01;
232239
const SYS_CLOSE: u32 = 0x02;
240+
const SYS_WRITEC: u32 = 0x03;
233241
const SYS_WRITE: u32 = 0x05;
234242
const SYS_READ: u32 = 0x06;
235243
const SYS_ISTTY: u32 = 0x09;
@@ -273,6 +281,13 @@ pub fn decode_semihostcmd(
273281
let handle = processor.read32(params_ptr)?;
274282
SemihostingCommand::SysClose { handle }
275283
}
284+
SYS_WRITEC => {
285+
let params_ptr = r1;
286+
let ch = processor.read8(params_ptr)?;
287+
SemihostingCommand::SysWriteC {
288+
data: ch,
289+
}
290+
}
276291
SYS_WRITE => {
277292
let params_ptr = r1;
278293
let handle = processor.read32(params_ptr)?;

0 commit comments

Comments
 (0)