Skip to content
This repository was archived by the owner on Dec 2, 2020. It is now read-only.

Fix for JLink debuggers #35

Closed
wants to merge 1 commit into from
Closed

Fix for JLink debuggers #35

wants to merge 1 commit into from

Conversation

korken89
Copy link
Contributor

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{}
}

When sending 1 character it returns -1 from syscall. This fix mitigates
the issue, but it not correct.
@korken89 korken89 requested a review from a team as a code owner April 23, 2019 09:18
@rust-highfive
Copy link

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
Copy link
Contributor Author

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.

@korken89 korken89 closed this Aug 13, 2019
@korken89 korken89 deleted the jlink_fix branch August 13, 2019 19:06
@nickray
Copy link
Contributor

nickray commented Aug 18, 2019

@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
Copy link
Contributor Author

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
Copy link
Contributor

nickray commented Aug 18, 2019

Thanks! Seems I haven't hit your issue yet, I was just lacking monitor semihosting IOClient 2. 🤦‍♂️

@korken89
Copy link
Contributor Author

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

bors bot added a commit that referenced this pull request Aug 21, 2019
39: korken89's J-Link fix behind a feature flag r=adamgreig a=nickray

In response to #38 I suggest picking up #35 again.

@korken89 since you observed -1, -2, -3, maybe `n > 0xffff_fff0` is a good condition instead of catching just "-1"? As I understand it, worst case some very long outputs get truncated.

I did send an email to Segger support (would be good if these special cases were a finite list, and documented in UM08001), but who knows if they will answer :)

Co-authored-by: Nicolas Stalder <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants