rust-embedded / cortex-m-semihosting

Semihosting for ARM Cortex-M processors
Apache License 2.0
40 stars 19 forks source link

Fix for JLink debuggers #35

Closed korken89 closed 5 years ago

korken89 commented 5 years ago

Explanation

When sending 1 character it returns -1 from syscall. This fix mitigates the issue, but it not correct. This is probably not the correct way to solve it (might be a bug in the JLink debugger firmware), but it currently solves the issue.


To reproduce

JLink version info (this dev board https://www.decawave.com/product/dwm1001-development-board/):

Firmware: J-Link OB-STM32F072-128KB-CortexM compiled Jan  7 2019 14:08:04
Hardware: V1.00

Minimal example showing the problem:

#![no_main]
#![no_std]

// panic handler
extern crate panic_semihosting;
extern crate nrf52_hal_common;

use cortex_m_semihosting::hprint;
use cortex_m_rt::entry;

#[entry]
fn main() -> ! {
    hprint!("a").unwrap();

    loop{}
}
rust-highfive commented 5 years ago

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @therealprof (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

korken89 commented 5 years ago

The JLink seems very unstable for semihosting, sometimes it returns -2 and -3 as well. I would not accept this PR. The better fix is to use OpenOCD, it does not have this issue.

nickray commented 5 years ago

@korken89 Can you add some more info about this fix and its retraction? I'm playing around with an LPCXpresso55S69 and in my case (GDB + JLink) the hprintln is just being silently swallowed. OpenOCD isn't currently an option since it has no support (yet) AFAIK.

korken89 commented 5 years ago

Sure! The fix checks the return value from the system call, and it was sometimes -1. So this was changed to be accepted. This is however probably a bug in jlink.

The better fix, if one wants to do this, is to accept negative numbers plus some testing of what -1, -2 etc corresponds to.

nickray commented 5 years ago

Thanks! Seems I haven't hit your issue yet, I was just lacking monitor semihosting IOClient 2. :man_facepalming:

korken89 commented 5 years ago

Hehe, a easy thing to miss :) but if you at the same issue I had, please report it