This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

JLinkExe hangs in Makefile but not in terminal on Mac OS

Here are the commands I use to upload a program to the device:

JLinkExe  -device nrf51422_xxac -if swd -speed 4000 
loadbin filename.bin 0x18000 
r 
exit

It works like a charm when entered from terminal, but when added to the Makefile, it hangs after printing out last log message:

Loading: _build/nrf51422_xxac_s110.bin
JLinkExe  -device nrf51422_xxac -if swd -speed 4000
SEGGER J-Link Commander V5.10g (Compiled Jan  6 2016 13:58:14)
DLL version V5.10g, compiled Jan  6 2016 13:57:56
Connecting to J-Link via USB...O.K.
Firmware: J-Link OB-SAM3U128-V2-NordicSemi compiled Aug 28 2015 19:26:24
Hardware version: V1.00
S/N: 681121013
Emulator has Trace capability
VTref = 3.300V
Type "connect" to establish a target connection, '?' for help

So it looks like it hangs after the first JLinkExe command is executed. What is the cause of this? BTW, I am using Xcode with External Build System target to do that. Program is compiled properly.

image description

  • well it doesn't hang - it's just waiting for input. It wants someone to type 'connect'. I don't know why however I did notice my JLink-Edu was doing that yesterday when I was running it from the command line which is rather annoying.

    I'm assuming it's something Segger put in the latest version of JLinkExe, possibly by mistake, but perhaps not. I'd head over to their forums and ask why JLink(Exe) is now asking for a connect command to be typed in even when switches are put on the original command.

    I don't know why it's not doing it when you type it by hand. I suspect they broke something. You could try a downgrade to 5.10

  • oh yes all my JLinks are doing it now - fortunately it doesn't affect RKNRFGO or I would be annoyed. Seems that it no-longer automatically connects, you have to connect it yourself. Typing any command which requires a connection outputs a message about needing a connection but not being connected, and then it connects. That's probably why it works from the terminal.

    You might be able to append a command onto the end of the command line, one which does nothing useful but forces the connect.

    Definitely should ask Segger about this one.

  • I managed to work around this by appliyin Apple script. I created upload.sh script file (had to have executable permissions, use chmod +x if needed). Then Makefile invokes this script instead of JLinkExe commands directly. Content of upload.sh:

    #!/bin/sh 
    osascript <<END 
    tell application "Terminal"
        do script "JLinkExe  -device nrf51422_xxac -if swd -speed 4000\nloadbin filepath.bin 0x18000\nr\nexit\n$1"
    end tell
    END
    

    Replace filepath.bin with full path where bin file is expected to be after compilation (_build subdirectory) or use environmental variables to set it for you (did not have time for this yet and will update my answer when I perfect it).

  • Suggestion on the segger forums just to add

    -AutoConnect 1 
    

    to the command line - try that - I don't have a board to hand right now.

  • Yes that works - just change the run line to

    JLinkExe -if swd -device nrf51 -speed 4000 -Autoconnect 1
    

    and it will work just as it did before - no need to muck around with Applescript.

Related