J-Link is a rather nice general-purpose ARM debugger and offers more standardized GDB implementation than the ST-Link. Also, EDU version is priced at about 50 euros, while basic full version is not that much more expensive at about 300 euros. The super-duper Ultra version goes for about 600, or 800 with Ethernet. Since I use it for research and education, non-commercial EDU version suits me just fine. Although it does have some limitations license-wise, it is identical to JLink Base.
Ok, let's set it up. First we need their software bundle, obtainable from their download page. I took linux 64 bit deb installer, installed it with
$ sudo dpkg -i JLink_Linux_V650a_x86_64.deb
Installer conveniently also creates for us udev rules under /etc/udev/rules.d/99-jlink.rules. Quite sophisticated, but ensures, that JLink works pretty much out of the box. Now, let's connect it and try it out. I'll try to connect to my custom board with STM32F427ZI controller on it:
$ JLinkGDBServer -if JTAG -device STM32F427ZI
Note, that I specifiec particular MCU version. Full list of supported devices is available on their supported device page
Aaaand something bad happened. Well, not bad, but not exactly what I wanted:
SEGGER J-Link GDB Server V6.50a Command Line Version JLinkARM.dll V6.50a (DLL compiled Aug 26 2019 10:23:45) Command line: -if JTAG -device STM32F427ZI -----GDB Server start settings----- GDBInit file: none GDB Server Listening port: 2331 SWO raw output listening port: 2332 Terminal I/O port: 2333 Accept remote connection: yes Generate logfile: off Verify download: off Init regs on start: off Silent mode: off Single run mode: off Target connection timeout: 0 ms ------J-Link related settings------ J-Link Host interface: USB J-Link script: none J-Link settings file: none ------Target related settings------ Target device: STM32F427ZI Target interface: JTAG Target interface speed: 4000kHz Target endian: little Connecting to J-Link... J-Link is connected. Firmware: J-Link V9 compiled May 17 2019 09:50:41 Hardware: V9.30 S/N: 269303419 OEM: SEGGER-EDU Feature(s): FlashBP, GDB Checking target voltage... Connecting to target failed. Connected correctly? GDB Server will be closed... Shutting down... Could not connect to target. Please check power, connection and settings.
Oh, ah, it tells me to check my setup. Right, board is not powered up. Let's fix it. Once device is powered up and JTAG connection extablishes correctly, we get output of our GDB server:
SEGGER J-Link GDB Server V6.50a Command Line Version JLinkARM.dll V6.50a (DLL compiled Aug 26 2019 10:23:45) Command line: -if JTAG -device STM32F427ZI -----GDB Server start settings----- GDBInit file: none GDB Server Listening port: 2331 SWO raw output listening port: 2332 Terminal I/O port: 2333 Accept remote connection: yes Generate logfile: off Verify download: off Init regs on start: off Silent mode: off Single run mode: off Target connection timeout: 0 ms ------J-Link related settings------ J-Link Host interface: USB J-Link script: none J-Link settings file: none ------Target related settings------ Target device: STM32F427ZI Target interface: JTAG Target interface speed: 4000kHz Target endian: little Connecting to J-Link... J-Link is connected. Firmware: J-Link V9 compiled May 17 2019 09:50:41 Hardware: V9.30 S/N: XXXXXXX OEM: SEGGER-EDU Feature(s): FlashBP, GDB Checking target voltage... Target voltage: 3.30 V Listening on TCP/IP port 2331 Connecting to target... J-Link found 2 JTAG devices, Total IRLen = 9 JTAG ID: 0x4BA00477 (Cortex-M4) Connected to target Waiting for GDB connection...
Previously I wrote about setting up Eclipse environment. Let's extend it to include debugging facilities provided by JLink.
To install appropriate plugins, we start our Eclipse and go to "Help/Eclipse Marketlace". There we search for "jlink" and get offered to install "GNU MCU Eclipse", which contains quite a few useful plugins. Let's go with that and install everything they offer (unless you know what you want). Once installed, restart eclipse, open some project (you can try existing written in any previous tutorials) and add debug configuration under "Run/Debug Configurations". On the left side we now have at least "GDB SEGGER J-Link Debugging". Right click on it and add new configuration, then set up your target on the right side. Then change project settings under "C/C++ Build/Settings/Devices" choose your target device (F427ZI in my case). Also check that under "Window/Preferences/MCU/Global SEGGER J-Link Path" the path is correct. For me it defaulted to /opt/SEGGER/JLink, while .deb installer actually put it under /opt/SEGGER/JLink_V650a. If this path is incorrect, you'll get launcher issues, similar to:
Error in services launch sequence
Launching command [/JLinkGDBServer -if jtag -device STM32F427ZI -endian little -speed 1000 -port 2331 -swoport 2332 -telnetport 2333 -vd -ir -localhostonly 1 -singlerun -strict -timeout 0 -nogui] failed.
Launching command [/JLinkGDBServer -if jtag -device STM32F427ZI -endian little -speed 1000 -port 2331 -swoport 2332 -telnetport 2333 -vd -ir -localhostonly 1 -singlerun -strict -timeout 0 -nogui] failed.
Cannot run program "/JLinkGDBServer": Unknown reason
Other way to bypass this issue, is to change Executable field under debug configuration "Debugger" tab to either point to specific file, or just use ${jlink_gdbserver} if you have added installation to PATH.
Another error I got was:
Error in final launch sequence
Failed to execute MI command:
-target-select remote localhost:2331
Error message from debugger back end:
Truncated register 16 in remote 'g' packet
Failed to execute MI command:
-target-select remote localhost:2331
Error message from debugger back end:
Truncated register 16 in remote 'g' packet
Truncated register 16 in remote 'g' packet
This usually means that the GDB client is set up incorrectly. I switched from Cross GDB to arm-none-eabi-gdb from my toolchain under "Debug Configurations/Debugger". I also had to disable semihosting in "Debug Configurations/Startup", since that introduces quite a few bugs.
Now you should be able to launch your debugger and expect it to stop at main() entry. Happy debugging!
Based on:
https://gnu-mcu-eclipse.github.io/debug/jlink/install/
https://gnu-mcu-eclipse.github.io/debug/jlink/
No comments:
Post a Comment