0

How to use a Segger J-Link /J-Trace with Metro M4
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

How to use a Segger J-Link /J-Trace with Metro M4

by Adafruit_UMjT7KxnxP8YN8 on Fri Sep 07, 2018 5:22 pm

I recently purchased a Segger J-Link Edu and after a bit of fiddling got it to work with a Metro M4 using Segger's Ozone debugger. Thought I'd share what I learned with others.

I'm using the Adafruit 10-pin 2x5 Socket-Socket 1.27mm IDC (SWD) Cable - 150mm long and JTAG (2x10 2.54mm) to SWD (2x5 1.27mm) Cable Adapter Board to connect the J-Link to the Metro M4.

I created a project file (MetroM4.jdebug) which is attached (renamed MetroM4.txt to make forum sw happy and attached to this post) containing the following settings/customizations [the snippet below is NOT the entire project file]. Open this file when you start Ozone so you don't have to manually set it up every time.

void OnProjectLoad (void) {
//
// Dialog-generated settings
//
Project.SetDevice ("ATSAMD51J19");
Project.SetHostIF ("USB", "");
Project.SetTargetIF ("SWD");
// I also successfully used "Auto" and "15 MHz" as the interface speed setting
Project.SetTIFSpeed ("12 MHz");
Project.SetTraceSource ("SWO");
Project.ConfigSWO ("auto", "auto");
//
// User settings
//
// the two following lines make the ATSAMD51J19's registers visible in the debugger
Project.AddSvdFile ("$(InstallDir)/Config/CPU/Cortex-M4F.svd");
Project.AddSvdFile ("$(InstallDir)/Config/Peripherals/ARMv7M.svd");
}

Build your executable using the Arduino IDE. No extra steps required here. You can load it using the Arduino IDE or use Ozone as explained below. If you edit your program and compile it in Arduino, Ozone will detect the change and prompt you to reload.

In Ozone, go to File-> Open and navigate to your Arduino .ELF file (the executable with debug info). You can add the loading of your .ELF file in your project file too but I didn't. If you managed to hang up your Metro M4 during your last debugging session, hit its reset button to get back to a known state before loading.

Arduino usually puts .ELF files in your /TEMP directory, in a subdirectory named something like "arduino_build_803625".

Once your executable is loaded using one of these methods, you can proceed by going to the Ozone Debug menu and selecting: Start debug => attach to running program

If you have any questions, post them here and I'll answer them if I can.

[Update: I recently bought a J-Trace for Cortex-M3 and it behaves a bit differently than the J-Link Edu. When you're debugging and want to change your source and download a new .ELF file, the following method does not hang up your system and require unplugging both J-Trace and Metro M4:

1. STOP THE DEBUGGER. You don't have to exit, just stop debugging.
2. After changing source, click the Arduino IDE Download button. If it hangs, you'll have to unplug both J-Trace and M4 to unhang it. If this happens, plug in the J-Trace before the M4. I tried using my J-Trace to download new programs but though it downloads successfully, I have yet to get it to start debugging without first unhanging it.
3. If you're printing debug statements to the M4 serial port, close the Serial Monitor. I put a "while (!Serial)" at the beginning of setup() to force my program to wait at startup & make it easier to coordinate with the debugger.
4. Start the debugger using Attach to running program.
5. Set any breakpoints you must have in place before opening the Serial Monitor. If you don't, your program will run past them faster than you can set them once it starts.
6. Now, if you have Serial.begin() in setup(), your program is idling, waiting for the Serial Monitor to open. Go to the Arduino IDE, type Ctrl-Shift-M to open the Serial Monitor, and you're in business.
7. If you forget to close the Serial Monitor in step 3, don't sweat it. The debugger won't start because it's hung up in the "while (!Serial)" waiting for a new Serial Monitor to open. Close the one you left open, open a new one and start debugging.

[end of update]
Attachments
MetroM4.txt
Rename to MetroM4.jdebug and you can use this file as-is or as a starting point.
(14.7 KiB) Downloaded 107 times
Last edited by Adafruit_UMjT7KxnxP8YN8 on Wed Sep 19, 2018 7:54 pm, edited 1 time in total.

Adafruit_UMjT7KxnxP8YN8
 
Posts: 75
Joined: Tue Jul 17, 2018 1:28 pm

Re: How to use a Segger J-Link /J-Trace with Metro M4

by adafruit2 on Tue Sep 11, 2018 11:59 am

nice, thanks!

adafruit2
Site Admin
 
Posts: 18711
Joined: Fri Mar 11, 2005 7:36 pm

Re: How to use a Segger J-Link /J-Trace with Metro M4

by JoshBacigalupi on Wed Oct 24, 2018 3:39 pm

Very cool.

I would like to program and debug my ItsyBitsy Cortex M4 (ATSAMD51G19A) in the Keil uVision environment. Regardless of the IDE, is something like your setup possible with the Segger J-Link/J-Trace debugger and the ItsyBitsy via the SWD (2x5 1.27mm) Cable Breakout Board?

I'm new to debugging, so, if the above is possible, what does the setup look like. I.e., what's connected to what?

Thanks!
Josh

JoshBacigalupi
 
Posts: 9
Joined: Sun Sep 16, 2018 10:31 pm

Re: How to use a Segger J-Link /J-Trace with Metro M4

by Adafruit_UMjT7KxnxP8YN8 on Wed Oct 24, 2018 4:24 pm

Debuggingjpg.jpg
Debuggingjpg.jpg (848.38 KiB) Viewed 797 times
I don't see a SWD connector on the ItsyBitsy. AdaFruit's product page says: "ItsyBitsy M4 Express is only is only 1.4" long by 0.7" wide, but has 6 power pins, 23 digital GPIO pins (7 of which can be analog in, 2 x 1 MSPS analog out DACs, and 18 x PWM out). It's the same chip as the Adafruit Metro M4 but really really small. So it's great once you've finished up a prototype on a Metro M4 or (the upcoming) Feather M4, and want to make the project much smaller." [https://learn.adafruit.com/introducing-adafruit-itsybitsy-m4/overview].

I suspect you'll need to develop and debug on a Metro M4 Express then run your code on the ItsyBitsy.

So far as what's connected to what, the Segger J-Link plugs into a USB port on your development PC, and it comes with a cable that connects to the breakout board. You have to buy a 1 x 10-pin 2x5 Socket-Socket 1.27mm IDC (SWD) Cable - 150mm long[ID:1675] that goes from the breakout board to a 10-pin connector on the Metro M4.

See the attached pic of my debugging setup.

Adafruit_UMjT7KxnxP8YN8
 
Posts: 75
Joined: Tue Jul 17, 2018 1:28 pm

Re: How to use a Segger J-Link /J-Trace with Metro M4

by JoshBacigalupi on Wed Oct 24, 2018 4:40 pm

That helps a lot.

Thanks,
Josh

JoshBacigalupi
 
Posts: 9
Joined: Sun Sep 16, 2018 10:31 pm

Re: How to use a Segger J-Link /J-Trace with Metro M4

by jerryn on Wed Oct 24, 2018 4:45 pm

To use the J-Link with the Itsy_BItsyM4 you only need to connect the 3V,GND,SWDIO and SWCLK pins and they are all available on the board pads. SWCLK and SWDIO are on the end -- labels on the bottom. See: https://learn.adafruit.com/introducing-adafruit-itsybitsy-m4/pinouts

jerryn
 
Posts: 1027
Joined: Sat Sep 14, 2013 9:05 am

Re: How to use a Segger J-Link /J-Trace with Metro M4

by JoshBacigalupi on Wed Oct 24, 2018 7:44 pm

That's good news, jerryn!

Thanks,
Josh

JoshBacigalupi
 
Posts: 9
Joined: Sun Sep 16, 2018 10:31 pm

Please be positive and constructive with your questions and comments.