Debugging Cortex-M4 on i.MX7D with Segger J-Link and GDB (and thus standard Eclipse)

cancel
Showing results for 
Search instead for 
Did you mean: 

Debugging Cortex-M4 on i.MX7D with Segger J-Link and GDB (and thus standard Eclipse)

5,148 Views
dry
Senior Contributor I

Hello,

 

I recently got the iMX7D based SABRE board to play with (MCIMX7SABRE), and I'm interested in the M4 side for work.

I needed to set it up to work with existing tools at hand: GDB, Segger J-Link, Eclipse essentially. And using the NXP's supported  & provided FreeRTOS and the BSP.

 

The docs & readme's are good, but I found I had to do some extra setup steps or tweaking to make it work in my setup.

What I referred to or examined :

 

1. i.MX 7Dual SABRE Board|NXP   the Getting Started part

2. Getting_Started_with_FreeRTOS_BSP_for_i.MX_7Dual.pdf (inside FreeRTOS provided BSP package)

3. https://www.nxp.com/docs/en/application-note/AN5317.pdf  (that's the key app note really )

4. https://www.nxp.com/docs/en/user-guide/KSDK13GSUG.pdf   (referred to under 1))

5. IMX7D - SEGGER - Support Wiki 

 

I found the above enough to connect to M4 and upload a binary blob, but I had to add extra steps to setup the debugging properly.  As you will note from 1), 2) ,  J-Link and GDB (and plain Eclipse ) is not supported in the docs.  When going through 1), under "3. FreeRTOS" tab, clicking on "Use ARM GCC" brings up a window with extra information with some required GDB steps, but they are definitely not enough. And at the top of that window you can click on "Download PDF" and get 4), which I found irrelevant:  it describes Kinetis SDK, Attolic (which are Eclipse based..),and other IDE's setup for other targets, I didn't see iMX7 or SABRE in that doc.  And, it uses OpenSDA, and I don't think the SABRE board I'm using even has it (am I wrong..?). In any case, I've setup it to use J-Linkj through JTAG interface.

 

The key doc is the appnote in 3), and the Segger's script to connect to M4 of iMX7D referred to in 5) but is also part of standard J-Link install  - at least in my Segger version V 6.20b I'm using now.

 

However, I've modified that Segger's script (see attached) and the appnote (from 3)) process of connecting to M4 and starting to debug.  I find, in my testing on this one board with iMX7D and the provided examples (i tested 2), I don't have to do first connect to the A7 to let the M4 go: with the modified reset procedure it seems to work with just the M4 connection. 

(So is this spurious .. ?  The AN in 3) says you have to first connect to A7 & start M4, and Segger's wiki repeats what the AN says.  May be I got 'lucky' ..)

 

After you've connected to M4, with or without the initial A7 connection to enable M4 (and using or not the customized script or not), the GDB commands  required , after you connected to Segger GDBServer, are:

 

monitor halt                // Eclipse: I un-tick Initial Reset & halt and put this under "additional to alternative inits window .. "

                                    // (put whatever else you need, but with customized Segger script initial reset is done on connect)

load                           // Eclipse does this if you tick enable Load executable 

---------------------         // The below goes to Run/Restart Commands, un-tick Pre-Run/Restart reset

mon clrbp
mon halt
mon memU32 0x3039000C 0xAC
eval "monitor memU32 0x00180000 %p", &__stack
eval "monitor memU32 0x00180004 %p", &Reset_Handler + 1
mon memU32 0xE000EDFC 0x01000001
mon memU32 0x3039000C 0xAA

--------------------

tbreak main                  //Eclipse tick Set breakpoint at ..

continue                       //Eclipse tick continue 

 

With Eclipse, using the modified J-Link script, the above steps would be under "Startup" bar.

 

So with these settings, I'm able to debug on the iMX7D Cortex-M4, using my Segger J-Link, GDB and Eclipse (not Kinetis, Attolic , or DS-5, just Eclipse with GNU ARM plugin)

 

 

Anyone else has same tools but sets it up differently?  If you don't mind sharing ...

Original Attachment has been moved to: NXP_iMX7D_Connect_CortexM4.JLinkScript.zip

Labels (2)
6 Replies

2,721 Views
dry
Senior Contributor I

Updated script with a fix.   

2,721 Views
kashyap_gada
Contributor II

Hey D. RY, I tried above JLinkScript with Toradex Colibri imx7 but it failed to debug with following output - 

Debug Output

SEGGER J-Link GDB Server V6.70g Command Line Version

JLinkARM.dll V6.70g (DLL compiled Apr 23 2020 09:11:56)

Command line: -if jtag -device MCIMX7D7_M4 -endian little -speed 1000 -port 2331 -swoport 2332 -telnetport 2333 -vd -ir -localhostonly 1 -singlerun -strict -timeout 0 -nogui -scriptfile /opt/SEGGER/NXP_iMX7D_Connect_CortexM4.JLinkScript
-----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: localhost only
Generate logfile: off
Verify download: on
Init regs on start: on
Silent mode: off
Single run mode: on
Target connection timeout: 0 ms
------J-Link related settings------
J-Link Host interface: USB
J-Link script: /opt/SEGGER/NXP_iMX7D_Connect_CortexM4.JLinkScript
J-Link settings file: none
------Target related settings------
Target device: MCIMX7D7_M4
Target interface: JTAG
Target interface speed: 1000kHz
Target endian: little

Connecting to J-Link...
J-Link is connected.
Firmware: J-Link ARM-OB STM32 compiled Aug 22 2012 19:52:04
Hardware: V7.00
Feature(s): RDI,FlashDL,FlashBP,JFlash,GDBFull
Checking target voltage...
Target voltage: 3.30 V
Listening on TCP/IP port 2331
Connecting to target...

J-Link found 1 JTAG device, Total IRLen = 4
JTAG ID: 0x4BA00477 (Cortex-M4)
Connected to target
Waiting for GDB connection...Connected to 127.0.0.1
Reading all registers
Read 4 bytes @ address 0x00000000 (Data = 0x20008000)
Read 2 bytes @ address 0x00000000 (Data = 0x8000)
Received monitor command: speed 1000
Target interface speed set to 1000 kHz
Received monitor command: clrbp
Received monitor command: reset
WARNING: T-bit of XPSR is 0 but should be 1. Changed to 1.
Resetting target
Received monitor command: halt
Halting target CPU...
...Target halted (PC = 0x00000000)
Received monitor command: regs
R0 = 00000000, R1 = 00000000, R2 = 00000000, R3 = 00000000
R4 = 00000000, R5 = 00000000, R6 = 00000000, R7 = 00000000
R8 = 00000000, R9 = 00000000, R10= 00000000, R11= 00000000
R12= 00000000, R13= 00000000, MSP= 00000000, PSP= 00000000
R14(LR) = FFFFFFFF, R15(PC) = 00000000
XPSR 01000000, APSR 00000000, EPSR 01000000, IPSR 00000000
CFBP 00000000, CONTROL 00, FAULTMASK 00, BASEPRI 00, PRIMASK 00
Reading all registers
Received monitor command: speed auto
Select auto target interface speed (1000 kHz)
Received monitor command: flash breakpoints 0
Flash breakpoints disabled
Received monitor command: semihosting enable
Semi-hosting enabled (Handle on BKPT)
Received monitor command: semihosting IOClient 1
Semihosting I/O set to TELNET Client
Read 4 bytes @ address 0x00000000 (Data = 0x00000000)
Downloading 576 bytes @ address 0x00000000 - Verified OK
Downloading 10440 bytes @ address 0x1FFF8000 - Verified OK
Downloading 8 bytes @ address 0x1FFFA8C8 - Verified OK
Downloading 4 bytes @ address 0x1FFFA8D0 - Verified OK
Downloading 4 bytes @ address 0x1FFFA8D4 - Verified OK
Downloading 156 bytes @ address 0x20000000 - Verified OK
Writing register (PC = 0x1fff80b4)
Read 4 bytes @ address 0x1FFF80B4 (Data = 0xF8DFB672)
Read 2 bytes @ address 0x1FFF80B4 (Data = 0xB672)
Read 2 bytes @ address 0x1FFF9220 (Data = 0xB508)
Received monitor command: clrbp
Received monitor command: reset
WARNING: T-bit of XPSR is 0 but should be 1. Changed to 1.
Resetting target
Received monitor command: halt
Halting target CPU...
...Target halted (PC = 0x00000000)
Read 2 bytes @ address 0x1FFF9220 (Data = 0xB508)
Received monitor command: regs
R0 = 00000000, R1 = 00000000, R2 = 00000000, R3 = 00000000
R4 = 00000000, R5 = 00000000, R6 = 00000000, R7 = 00000000
R8 = 00000000, R9 = 00000000, R10= 00000000, R11= 00000000
R12= 00000000, R13= 00000000, MSP= 00000000, PSP= 00000000
R14(LR) = FFFFFFFF, R15(PC) = 00000000
XPSR 01000000, APSR 00000000, EPSR 01000000, IPSR 00000000
CFBP 00000000, CONTROL 00, FAULTMASK 00, BASEPRI 00, PRIMASK 00
Reading all registers
Setting breakpoint @ address 0x1FFF9220, Size = 2, BPHandle = 0x0001
Starting target CPU...
/opt/SEGGER/JLink/JLinkGUIServerExe: error while loading shared libraries: libQtGui.so.4: cannot open shared object file: No such file or directory
Reading all registers
Removing breakpoint @ address 0x1FFF9220, Size = 2
WARNING: Could not remove breakpoint @ address 0x1FFF9220
ERROR: Failed to set breakpoint at 0x1FFF9220
WARNING: Failed to read memory @ address 0xEA5FA2C8
WARNING: Failed to read memory @ address 0xEA5FA2C8   

Regards

0 Kudos

2,721 Views
dry
Senior Contributor I

Hi Kashyap,

I can check on my small Toradex board with iMX7D.  I haven't checked Segger's updated software in a while.

Note, from your trace I saw:

Firmware: J-Link ARM-OB STM32 compiled Aug 22 2012 19:52:04

Is this some on-board Segger debugger you using?

/opt/SEGGER/JLink/JLinkGUIServerExe: error while loading shared libraries: libQtGui.so.4: cannot open shared object file: No such file or directory

Looks like broken Segger install. It doesn't matter for debugging but I would just use non-GUI version - console is just as great.

0 Kudos

2,721 Views
kashyap_gada
Contributor II

Hi, D. RY,

Thanks for your promt reply. Much appreciated. 

1. Yes its some JTAG clone which works with many IDEs and microcontrollers. I am first time checking with toradex. More details about the JTAG on this page - USB-MiniJTAG JTAG/SWD Debugger/Emulator [USB-MiniJTAG] - US $13.00 : HAOYU Electronics : Make Engine... 

2. I tried the 6.70c (32bit & 64bit) and recently as per toradex web site I tried Jlink Version 6.48b (64/32bit) (Developing M4 Applications Using Visual Studio Code ) 

Both have same results.

What can we do? Which JTAG you use?

Regards

Kashyap

0 Kudos

2,721 Views
dry
Senior Contributor I

Tested on latest  - v6.70g Jlink - and it works as before , i can upload and start debugging Hello World just fine.

Here is log link, if it is of any reconciliation to you..

jlinkgdb v 6.70g log , imx7d

About which IDE / GUI : that I will not check, and it shouldn't affect JLink monitor working. The starting point is the debug probe + GDBServer , and GDB client, and this seems to work.

I do want to improve my connect script, when I have time I will do it.

0 Kudos

2,721 Views
dry
Senior Contributor I

I gave a quick try on Toradex's iMX7D Colibri, and it hooked up to debug Hello World just fine.  Also without initial A7 connect. 

weee haaaaaaa  :smileysilly:.