Is semihosting supported when running on an ST-Link/v2? #1368
-
I'm trying to follow the rust book for embedded programming (https://docs.rust-embedded.org/book/start/hardware.html). At some point it tells me to enable semihosting, which restuls in:
I'm new to this, so I have no clue if it's just not supported, if I compiled the blackmagic firmware wrong, if I compiled my program incorrectly, or screwed up something different entirely. I did see the https://black-magic.org/usage/semihosting.html section on the website, and I assume those flags need to be passed to the linker of my rust program. But I haven't found any way to do that / the rust book I'm reading does not mention this, nor did I find it in the documentation of https://crates.io/crates/cortex-m-semihosting (which implements the semihosting). Help is greatly appreciated 😊. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 10 replies
-
The ST-Link v2 platform should support semihosting, so the redirect command should be visible in the You are correct that you do have to compile with an appropriate crate that invokes the semihosting halo using the break instruction that encodes to |
Beta Was this translation helpful? Give feedback.
-
@dragonmux Ahh, thank you so much! Yes, I am on Linux and I see the Just a little suggestion from a novice, wouldn't it be helpful if those commands were documented under https://black-magic.org/usage/semihosting.html? Because I thought it might work differently, but didn't find anything in, what I thought was the correct, documentation page. Anyway, I tried attaching to the serial port using Here is the code I'm using: hprintln!(">>>>>>>>>>>>>>>..").unwrap();
let mut led_pin = pins.gpio25.into_push_pull_output();
loop {
led_pin.set_high().unwrap();
hprintln!("high").unwrap();
delay.delay_ms(500);
led_pin.set_low().unwrap();
hprintln!("low").unwrap();
delay.delay_ms(500);
} Output from the second serial interface (with (yes, there is something wrong with the newlines and I'm not good enough to figure it out lol)
Output from gdb (without
|
Beta Was this translation helpful? Give feedback.
-
You make a fair point regarding documenting semihosting better. We agree the documentation is lacking and it's on our list of things to fix, if someone doesn't contribute better documentation first. At the moment that page is more focused on how to enable use of semihosting and is C-focused (the library calls talked about are specific to newlib and C family languages). It being rewritten to have sections on making use of semihosting within BMP, how to enable semihosting in C-based firmware and how to enable semihosting in Rust-based firmware at a minimum would probably be ideal and the direction we'd take it when we get around to it. |
Beta Was this translation helpful? Give feedback.
monitor arm semihosting enable
is only for OpenOCD. BMP implements a different set of monitor commands (monitor help
to list), and that we remember, semihosting should always be enabled once attached to an ARM core. Semihosting output goes to the secondary serial port for BMP (/dev/ttyBmpTarg if on Linux) when you runmonitor redirect_stdout enable
.The ST-Link v2 platform should support semihosting, so the redirect command should be visible in the
monitor help
output.You are correct that you do have to compile with an appropriate crate that invokes the semihosting halo using the break instruction that encodes to
0xbeab
, but that should be all that is required.