J-Link OB, Cortex-M3, GDB, and semihosting

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

  • J-Link OB, Cortex-M3, GDB, and semihosting

    Is ARM semihosting I/O supported with JLinkGDBServer and a J-Link OB attached to a Toshiba TMPM341 (Cortex-M3)? I've been poking around this forum for a while now, but I only turned up some very old messages, and no answers that really came out and said what was going on. The documentation (UM08005_JLinkGDBServer.pdf) makes mention of the "semihosting enable" and "semihosting ThumbSWI" remote commands, but their more detailed descriptions have a few hints that they're oriented to the older pre ARMv7 architectures.

    If I try to do Cortex-M3-style semihosting (via a "bkpt 0xab" instruction), the debugger just halts, with a breakpoint trap. Here's a little gdb transcript:

    (gdb) c

    Program received signal SIGTRAP, Trace/breakpoint trap.
    0x000003d6 in semihost_SYS_WRITE0 (s=0x20000004 "Hello, world!\n") at driver/semihosting.c:5
    5 __asm ("mov r1, %[string]; \
    (gdb) disas
    Dump of assembler code for function semihost_SYS_WRITE0:
    0x000003d0 <+0>: mov r2, r0
    0x000003d2 <+2>: mov r1, r2
    0x000003d4 <+4>: movs r0, #4
    => 0x000003d6 <+6>: bkpt 0x00ab
    0x000003d8 <+8>: bx lr
    End of assembler dump.


    My GDB build should support things fine - I was using semihosting successfully with the LPCXpresso dev boards from NXP. The only major differences are the GDB server software and the specific target chip (the LPC I was using was Cortex-M0, but I don't think that should make a difference). So, presumably the LPC debug server software supports semihosting, but the Segger JLinkGDBServer does not - unless I'm doing something wrong, which is certainly quite possible.

    Is there a way to get this I/O channel working? In the absence of semihosting, does JLinkGDBServer support DCC for I/O? What does it expect to see on the target side for support, if so?

    Thanks for any information you can provide! Please let me know if there's any other information you'd find useful from my side.

    The post was edited 1 time, last by carlnorum ().

  • While I'm here, one more question:

    When I'm running off the PLL, executing a "wfi" instruction sometimes seems to cause the debugger to trap. It doesn't happen all the time - it seems to come and go in waves. I guess I'm setting something up wrong someplace, but any insight is welcome!

    I had originally thought it had to do with running off of the internal oscillator vs the external oscillator/PLL (or vice versa), but that doesn't seem to be the case.
  • carlnorum wrote:

    When I'm running off the PLL, executing a "wfi" instruction sometimes seems to cause the debugger to trap. It doesn't happen all the time - it seems to come and go in waves. I guess I'm setting something up wrong someplace, but any insight is welcome!

    I had originally thought it had to do with running off of the internal oscillator vs the external oscillator/PLL (or vice versa), but that doesn't seem to be the case.
    Semi-solved - the debugger loses its brain if the processor is idle for too long. I had the watchdog set for ~200 ms, so it looks like JLinkGDBServer just gave up the ghost. Adding an empty SysTick handler that runs every millisecond keeps things happy. Even doing 2 ms was too long - is there a way to configure the debugger to wait a bit longer before deciding disaster has struck and causing a GDB exception?
  • Hi,

    Semihosting on Cortex-M via "BKPT 0xAB":
    Has been added in V4.70 of the J-Link software: segger.com/jlink-software.html
    Please refer to the GDBServer manual (UM08005), description of "monitor semihosting enable" (chapter 3.5.23)
    which gives some additional information about how semihosting terminal data can be received.

    WFI: Be careful. If debugging with WFI instructions is possible at all heavily depends on the device. Depending on the device, different clocks are disabled when executing a WFI instruction.
    On some devices even the clock of the debug unit is disabled makign any connection impossible so the debugger does not even have a chance to detect if the CPU is in some kind of low power state.
    On some devices (like the STM32 series) there is a chip specific(!) register which allows to configure that certain clocks are kept on on WFI/WFE making debugging with these instructions possible.


    Best regards
    Alex
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • SEGGER - Alex wrote:

    Semihosting on Cortex-M via "BKPT 0xAB":
    Has been added in V4.70 of the J-Link software: segger.com/jlink-software.html
    Please refer to the GDBServer manual (UM08005), description of "monitor semihosting enable" (chapter 3.5.23)
    which gives some additional information about how semihosting terminal data can be received.
    Great, thanks. When will the Mac OS X version be available? That download link shows only version 4.62a. I'll download the windows version and take a peek at the documentation in the meantime.

    SEGGER - Alex wrote:

    WFI: Be careful. If debugging with WFI instructions is possible at all heavily depends on the device. Depending on the device, different clocks are disabled when executing a WFI instruction. On some devices even the clock of the debug unit is disabled makign any connection impossible so the debugger does not even have a chance to detect if the CPU is in some kind of low power state. On some devices (like the STM32 series) there is a chip specific(!) register which allows to configure that certain clocks are kept on on WFI/WFE making debugging with these instructions possible.
    Yeah, that's what it looks like is going on. I'm not sure if it's chip-side or debugger-side, but something definitely goes out to lunch. It seems OK if I just put an empty SysTick interrupt that runs every milliscond.
  • I downloaded 4.70 and ran it in a Windows VM, connected with the GDB I've been running on Mac OS X. It seemed to work OK, but the semihosting wasn't reliable. I don't know if that's related to the use of the NMI in this example program, though. I'll keep experimenting and hope for the best - any information about the 4.70 release date for Mac OS X will be appreciated!

    Feature request to add: Can you deliver the semihosting I/O to GDB directly to be printed out on its console, rather than needing a separate terminal window? That would be much more convenient. It's certainly not a dealbreaker, though.
  • Hi,

    It is not really fun to have this output directly in the GDBServer...
    since it will be mixed with other output done by the GDBServer e.g. if monitor commands are executed or if the CPU gets halted/restarted etc.
    For SWO it would be even worse: You could have single characters sometimes which are preceded by status messages from GDBServer etc.

    V4.70 Mac Release: Probably next week or the week after.


    Best regards
    Alex
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • Hi,

    We will put it on the internal "wish list" but not sure if and if yes how this needs to be implemented,
    since GDBServer is only allowed to send data to GDB if it explicitly asks for it and I am not sure if
    GDB is even aware of something like semihosting terminal output.

    As it is for now it is a real flexible solution since the user is totally free what to do with the output.
    He can watch it in a telnet session, redirect it to the logged into a file, etc.


    Best regards
    Alex
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • Hi Dan,

    Sorry, too much on the desk right now.
    Currently working on a new Windows release. Mac is planned for this month, too.


    Best regards
    Alex
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • V4.74 for Mac is available.
    segger.com/jlink-software.html

    It includes the semihosting functionality of GDBServer that was already available in the windows version.
    semihosting output to GDB I/O has not been implemented yet. I can still not give you any timeframe for this yet.


    Best regards
    Alex
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • Thanks Alex! It's working great for output.

    However, whenever I try to use the SYS_READC service (0x07), I get 0x07 (same state as before the bkpt) back.

    Does the Mac version of J-Link 4.74 support SYS_READC (or any semihosting services other than SYS_WRITEC and SYS_WRITE0)?

    Thanks,
    Dan
  • Hello Dan,

    Terminal input is not supported yet (and I do not think we did mention it to be supported so far).
    In > 90% of the cases, terminal output is used and the most important operation.
    Terminal input support is on the ToDo list.
    It may(!!) be available by the end of this week but this is nothing I can promise.

    Does the Mac version of J-Link 4.74 support SYS_READC (or any semihosting services other than SYS_WRITEC and SYS_WRITE0)?

    Currently, the following services/commands are supported:
    SYS_OPEN
    SYS_CLOSE
    SYS_WRITEC
    SYS_WRITE0
    SYS_WRITE


    Best regards
    Alex
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • What is the current status of SYS_READC? It does not report being unsupported but still does not seem to work properly, unless I am doing something wrong. I am using JLinkGDBServer on Linux 64 bits and I am connecting to EFM32 Cortex-M3. I am using sourcery codebench lite and custom semi-hosting code which seems to be working properly for SYS_WRITE and SYS_WRITEC. It is just SYS_READ that is giving me problems - basically it does not work.
  • Hi,

    We implemented nearly all semihosting commands to GDB Server some time ago.

    Could you please specify what is going wrong with SYS_READ?
    Are you trying to read from a file or from terminal input via a telnet client?

    Could you post your semihosting code for SYS_READ as a reference?


    Best regards
    Johannes - J-Link development / support
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.