0

Trinket M0 - Debug with j-link problem
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Trinket M0 - Debug with j-link problem

by crazypill on Thu Jan 24, 2019 1:35 pm

Hi there,
I wanted to see if anyone else is having trouble debugging the Cortex-M0+ on the Adafruit Trinket M0 with the Segger J-link EDU. I’m able to debug the Basic Feather M0 no problem but that’s a Cortex-M0. I’ve had some weird behavior with the Trinket M0 in general and wondering if perhaps I should wire up another and see if that one is faulty.

I changed all the jlink settings from the Adafruit debug example online from Cortex-M0 to Cortex-M0+ and can connect and download code to the chip. I can read and write to the chip’s registers but once I reset the chip, the debugger can’t control the target anymore and I end up in 0xdeadbeee (*mainly because the chip isn’t responding and the debugger server is erroring out). Control returns to the debugger but the chip is not halted. Any help would be appreciated.

Here is the J-link server output, followed by the gdb output:
Code: Select all | TOGGLE FULL SIZE
SEGGER J-Link GDB Server V6.40 Command Line Version

JLinkARM.dll V6.40 (DLL compiled Oct 26 2018 15:07:12)

Command line: -device Cortex-M0+ -speed auto -if SWD
-----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:                 Cortex-M0+
Target interface:              SWD
Target interface speed:        auto
Target endian:                 little

Connecting to J-Link...
J-Link is connected.
Firmware: J-Link V10 compiled Oct 26 2018 12:04:17
Hardware: V10.10
S/N: 260113337
OEM: SEGGER-EDU
Feature(s): FlashBP, GDB
Checking target voltage...
Target voltage: 3.34 V
Listening on TCP/IP port 2331
Connecting to target...Connected to target
Waiting for GDB connection...Connected to 127.0.0.1
Reading all registers
Read 4 bytes @ address 0x00000426 (Data = 0x4812BD10)
Read 2 bytes @ address 0x00000426 (Data = 0xBD10)
Received monitor command: device Cortex-M0+
Selecting device: Cortex-M0+
Received monitor command: speed auto
Select auto target interface speed (2000 kHz)
Reading all registers
Downloading 9952 bytes @ address 0x00002000
Downloading 256 bytes @ address 0x000046E0
Writing register (PC = 0x    2894)
Read 4 bytes @ address 0x00002894 (Data = 0x1C207011)
Reading 64 bytes @ address 0x00002100
Read 2 bytes @ address 0x00002124 (Data = 0x1C20)
Setting breakpoint @ address 0x00002124, Size = 2, BPHandle = 0x0001
Starting target CPU...
Debugger requested to halt target...
...Target halted (PC = 0x00000286)
Reading all registers
Removing breakpoint @ address 0x00002124, Size = 2
Read 4 bytes @ address 0x00000286 (Data = 0x4820E7FE)
Read 2 bytes @ address 0x00000286 (Data = 0xE7FE)
Received monitor command: reset
Resetting target
Setting breakpoint @ address 0x00002124, Size = 2, BPHandle = 0x0002
Starting target CPU...
ERROR: Can not read register 15 (R15) while CPU is running
Reading all registers
ERROR: Can not read register 0 (R0) while CPU is running
ERROR: Can not read register 1 (R1) while CPU is running
ERROR: Can not read register 2 (R2) while CPU is running
ERROR: Can not read register 3 (R3) while CPU is running
ERROR: Can not read register 4 (R4) while CPU is running
ERROR: Can not read register 5 (R5) while CPU is running
ERROR: Can not read register 6 (R6) while CPU is running
ERROR: Can not read register 7 (R7) while CPU is running
ERROR: Can not read register 8 (R8) while CPU is running
ERROR: Can not read register 9 (R9) while CPU is running
ERROR: Can not read register 10 (R10) while CPU is running
ERROR: Can not read register 11 (R11) while CPU is running
ERROR: Can not read register 12 (R12) while CPU is running
ERROR: Can not read register 13 (R13) while CPU is running
ERROR: Can not read register 14 (R14) while CPU is running
ERROR: Can not read register 15 (R15) while CPU is running
ERROR: Can not read register 16 (XPSR) while CPU is running
ERROR: Can not read register 17 (MSP) while CPU is running
ERROR: Can not read register 18 (xxx) while CPU is running
ERROR: Can not read register 24 (PRIMASK) while CPU is running
ERROR: Can not read register 25 (BASEPRI) while CPU is running
ERROR: Can not read register 26 (FAULTMASK) while CPU is running
ERROR: Can not read register 27 (CONTROL) while CPU is running
Removing breakpoint @ address 0x00002124, Size = 2
WARNING: Failed to read memory @ address 0xDEADBEEE
WARNING: Failed to read memory @ address 0xDEADBEEE



Code: Select all | TOGGLE FULL SIZE
pro>:/Users/alex$ arm-none-eabi-gdb -x ~/bin/gdbinit-m0+
GNU gdb (GNU Tools for Arm Embedded Processors 7-2017-q4-major) 8.0.50.20171128-git
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-apple-darwin10 --target=arm-none-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
warning: No executable has been specified and target does not support
determining executable automatically.  Try using the "file" command.
0x00000426 in ?? ()
Selecting device: Cortex-M0+
Select auto target interface speed (2000 kHz)
(gdb) file /var/folders/cr/f7t7lmb97_s3rjj7r796knq00000gp/T/arduino_build_766466/Blink.ino.elf
A program is being debugged already.
Are you sure you want to change the file? (y or n) y
Reading symbols from /var/folders/cr/f7t7lmb97_s3rjj7r796knq00000gp/T/arduino_build_766466/Blink.ino.elf...done.
(gdb) load
Loading section .text, size 0x26e0 lma 0x2000
Loading section .data, size 0x100 lma 0x46e0
Start address 0x2894, load size 10208
Transfer rate: 153 KB/sec, 5104 bytes/write.
(gdb) l loop
27     // initialize digital pin LED_BUILTIN as an output.
28     pinMode(LED_BUILTIN, OUTPUT);
29   }
30   
31   // the loop function runs over and over again forever
32   void loop() {
33     digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
34     delay(1000);                       // wait for a second
35     digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
36     delay(1000);                       // wait for a second
(gdb) b 33
Breakpoint 1 at 0x2124: file /Applications/Arduino.app/Contents/Java/examples/01.Basics/Blink/Blink.ino, line 33.
(gdb) mon reset
Resetting target
(gdb) c
Continuing.

Program received signal SIGTRAP, Trace/breakpoint trap.
0xdeadbeee in ?? ()
(gdb) bt
#0  0xdeadbeee in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb)


Here's how the board is connected:
IMG_9532.jpg
Here's how the board is connected
IMG_9532.jpg (823.94 KiB) Viewed 85 times

crazypill
 
Posts: 4
Joined: Sat Jan 05, 2019 1:22 am

Re: Trinket M0 - Debug with j-link problem

by adafruit_support_mike on Sun Jan 27, 2019 6:19 am

All of our M0 boards use the SAMD21, which has an Arm M0+ microcontroller. The Feather M0 and Metro M0 use the SAMD21G, while the Trinket M0 uses the SAMD21E.

The differences are in the number and arrangment of the peripherals. The microcontrollers themselves are the same.

adafruit_support_mike
 
Posts: 55962
Joined: Thu Feb 11, 2010 2:51 pm

Re: Trinket M0 - Debug with j-link problem

by crazypill on Sun Jan 27, 2019 10:20 pm

Thank you for getting back to me- I initially assumed the same thing and had the debugger setup identically for how I am able to debug the Feather M0. This didn't work for me so I did some digging and it seemed like your website was saying the Trinket M0 was a Cortex-M0+. So I switched everything over and got the exact same results (which I posted). Here is the output with it set to Cortex-M0:

Code: Select all | TOGGLE FULL SIZE
pro>:/Users/alex$ jlink
SEGGER J-Link GDB Server V6.40 Command Line Version

JLinkARM.dll V6.40 (DLL compiled Oct 26 2018 15:07:12)

Command line: -device Cortex-M0 -speed auto -if SWD
-----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:                 Cortex-M0
Target interface:              SWD
Target interface speed:        auto
Target endian:                 little

Connecting to J-Link...
J-Link is connected.
Firmware: J-Link V10 compiled Oct 26 2018 12:04:17
Hardware: V10.10
S/N: 260113337
OEM: SEGGER-EDU
Feature(s): FlashBP, GDB
Checking target voltage...
Target voltage: 3.34 V
Listening on TCP/IP port 2331
Connecting to target...Connected to target
Waiting for GDB connection...Connected to 127.0.0.1
Reading all registers
Read 4 bytes @ address 0x00000908 (Data = 0x41981E43)
Read 2 bytes @ address 0x00000908 (Data = 0x1E43)
Received monitor command: device Cortex-M0
Selecting device: Cortex-M0
Received monitor command: speed auto
Select auto target interface speed (2000 kHz)
Reading all registers
Downloading 9952 bytes @ address 0x00002000
Downloading 256 bytes @ address 0x000046E0
Writing register (PC = 0x    2894)
Received monitor command: reset
Resetting target
Starting target CPU...
ERROR: Can not read register 15 (R15) while CPU is running
Reading all registers
ERROR: Can not read register 0 (R0) while CPU is running
ERROR: Can not read register 1 (R1) while CPU is running
ERROR: Can not read register 2 (R2) while CPU is running
ERROR: Can not read register 3 (R3) while CPU is running
ERROR: Can not read register 4 (R4) while CPU is running
ERROR: Can not read register 5 (R5) while CPU is running
ERROR: Can not read register 6 (R6) while CPU is running
ERROR: Can not read register 7 (R7) while CPU is running
ERROR: Can not read register 8 (R8) while CPU is running
ERROR: Can not read register 9 (R9) while CPU is running
ERROR: Can not read register 10 (R10) while CPU is running
ERROR: Can not read register 11 (R11) while CPU is running
ERROR: Can not read register 12 (R12) while CPU is running
ERROR: Can not read register 13 (R13) while CPU is running
ERROR: Can not read register 14 (R14) while CPU is running
ERROR: Can not read register 15 (R15) while CPU is running
ERROR: Can not read register 16 (XPSR) while CPU is running
ERROR: Can not read register 17 (MSP) while CPU is running
ERROR: Can not read register 18 (xxx) while CPU is running
ERROR: Can not read register 24 (PRIMASK) while CPU is running
ERROR: Can not read register 25 (BASEPRI) while CPU is running
ERROR: Can not read register 26 (FAULTMASK) while CPU is running
ERROR: Can not read register 27 (CONTROL) while CPU is running
WARNING: Failed to read memory @ address 0xDEADBEEE


And here's gdb output:
Code: Select all | TOGGLE FULL SIZE
pro>:/Users/alex$ arm-none-eabi-gdb -x ~/bin/gdbinit-m0
GNU gdb (GNU Tools for Arm Embedded Processors 7-2017-q4-major) 8.0.50.20171128-git
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-apple-darwin10 --target=arm-none-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
warning: No executable has been specified and target does not support
determining executable automatically.  Try using the "file" command.
0x00000908 in ?? ()
Selecting device: Cortex-M0
Select auto target interface speed (2000 kHz)
(gdb) file /var/folders/cr/f7t7lmb97_s3rjj7r796knq00000gp/T/arduino_build_698593/Blink.ino.elf
A program is being debugged already.
Are you sure you want to change the file? (y or n) y
Reading symbols from /var/folders/cr/f7t7lmb97_s3rjj7r796knq00000gp/T/arduino_build_698593/Blink.ino.elf...done.
(gdb) load
Loading section .text, size 0x26e0 lma 0x2000
Loading section .data, size 0x100 lma 0x46e0
Start address 0x2894, load size 10208
Transfer rate: 153 KB/sec, 5104 bytes/write.
(gdb) mon reset
Resetting target
(gdb) c
Continuing.

Program received signal SIGTRAP, Trace/breakpoint trap.
0xdeadbeee in ?? ()
(gdb)


I'm just trying to debug the Blink example with Arduino IDE 1.8.8 on MacOS X 10.14. Thanks again for your help!!

crazypill
 
Posts: 4
Joined: Sat Jan 05, 2019 1:22 am

Re: Trinket M0 - Debug with j-link problem

by adafruit_support_mike on Mon Jan 28, 2019 5:21 am

As a sanity check, make sure your connections to SWCLK and SWDIO aren't swapped.

Assuming those are good, take a look at this tutorial to see if anything looks relevant:

https://learn.adafruit.com/debugging-th ... b/overview

It's kind of a mixed bag, covering OpenOCD and GDB, but it has details relevant to getting both systems working.

adafruit_support_mike
 
Posts: 55962
Joined: Thu Feb 11, 2010 2:51 pm

Re: Trinket M0 - Debug with j-link problem

by crazypill on Tue Jan 29, 2019 10:52 pm

Thank you for following up- this was helpful. I tried those steps and it still failed the same way. However this time I got different errors! Yay:

Code: Select all | TOGGLE FULL SIZE
WARNING: CPU could not be halted
ERROR: ResetTarget(): PCode returned with error code -1


So I tried manually halting the MPU:
Code: Select all | TOGGLE FULL SIZE
load
mon reset
mon halt


Then I set a breakpoint in the init() code because what seems to be happening is that the debugger is unable to halt the MPU. Setting this breakpoint seems to help, then once I hit the first breakpoint, then I set another for inside of loop() and that worked!!! Holy moly!

However when I tried it again before posting this I noticed that this doesn't always work- it seems the real problem is that I can't seem to consistently halt the MPU... While it was locked up, I managed to break in and noticed this but most likely this is a red-herring:

Code: Select all | TOGGLE FULL SIZE
0x00003448 in USBDeviceClass::setAddress (this=this@entry=0x20000767 <USBDevice>, addr=6)
    at /Users/alex/Library/Arduino15/packages/adafruit/hardware/samd/1.2.9/cores/arduino/USB/USBCore.cpp:422
422      while (!usbd.epBank1IsTransferComplete(0)) {}


I need to try debugging with the Feather M0 again and see if I have these same issues- it just seems like inconsistent behavior. Maybe I need to check my soldiering... thanks again for your help- at least it sorta works now- that's a huge step forward!

crazypill
 
Posts: 4
Joined: Sat Jan 05, 2019 1:22 am

Re: Trinket M0 - Debug with j-link problem

by adafruit_support_mike on Wed Jan 30, 2019 4:15 am

I'm glad to hear you're at least getting some response. Good luck!

adafruit_support_mike
 
Posts: 55962
Joined: Thu Feb 11, 2010 2:51 pm

Please be positive and constructive with your questions and comments.