Semihosting: input from eclipse blocks.

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • Semihosting: input from eclipse blocks.

    I'm using semihosting under Eclipse to do console IO using jlink. Output works fine, but input just hangs. I'm using a nRF51822. What am I missing please?
    CODE

    C Source Code

    1. #include <stdio.h>
    2. int main(void) {
    3. char c;
    4. printf("Please type a character:\n");
    5. c = getchar();
    6. while (1)
    7. printf("You typed '%c'\n", c);
    8. }

    OUTPUT

    SEGGER J-Link GDB Server V4.98b - Terminal output channel
    Please type a character:
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

    Other linker flags: --specs=rdimon.specs -Wl,--start-group -lgcc -lc -lc -lm -lrdimon -Wl,--end-group

    GDB SEGGER J-Link Debugging

    Starting target CPU...
    ...Target halted @ semihosting bkpt, waiting for GDB handling
    Reading 25 bytes @ address 0x20000B00
    ...Target halted @ semihosting bkpt, waiting for GDB handling

    I have also tried using the more direct method using the following code with identical results

    C Source Code

    1. static char _SH_ReadC(void) { char c;
    2. c = BKPT(SYS_READC, (void*) 0, (void*) 0); return c;}
    3. static void _SH_Write0(char* ptr) { BKPT(SYS_WRITE0, (void*) ptr, (void*) 0);}
  • Hi,

    what do you mean with "but input just hangs."?
    In your example code you are reading the input only once (line 5) and print it in an endless loop (lines 6..7).

    Can you test with this example?

    C Source Code

    1. #include <stdio.h>
    2. int main(void) {
    3. char c;
    4. while (1) {
    5. printf("Please type a character:\n");
    6. c = getchar();
    7. printf("You typed '%c'\n", c);
    8. }
    9. }
  • Does anyone have a semihosting input example program for SEGGER that works please?


    Trivial program below using semihosting never returns from getchar() The program outputs "Please type a character",
    and then doesn't seem to see any of my input, and apparently hangs. I have tried generating input, both from gdb, and
    a telnet connection, with identical results.


    #include <stdio.h>
    int main(void) {
    char c;
    while (1) {
    printf("Please type a character:\n");
    c = getchar();
    printf("You typed '%c'\n", c);
    }
    }
    GDB says the following:
    Starting target CPU...
    ...Target halted @ semihosting bkpt, waiting for GDB handling
    Reading 25 bytes @ address 0x200003F0
    ...Target halted @ semihosting bkpt, waiting for GDB handling




    The monitor window looks like this:
    SEGGER J-Link GDB Server V4.98b - Terminal output channel
    Please type a character:
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa <to infinity and beyond>

    The program is compiled with these linker flags
    Other linker flags: --specs=rdimon.specs -Wl,--start-group -lgcc -lc -lc -lm -lrdimon -Wl,--end-group



    If I interrupt the program
    the stack trace looks like this:




    Blinky_PCA10000_NOSD_SH [GDB SEGGER J-Link Debugging]
    Blinky_C_nRF51822.elf
    Thread #1 <main> (Suspended : Signal : SIGTRAP:Trace/breakpoint trap)
    _swiread() at 0x330
    _read() at 0x360
    _read_r() at 0xbb4
    __sread() at 0x880
    __srefill_r() at 0x17d2
    __srget_r() at 0xeec
    main() at main3.c:13 0xbfa
    JLinkGDBServerCL.exe
    arm-none-eabi-gdb