Debug chipKIT Sketches in MPLAB X IDE

Source Debugging in MPLAB X IDE
Source Debugging in MPLAB X IDE

Say goodbye to the Serial Monitor debugging with Serial.println()! Microchip has released a chipKIT Platform Sketch Importer for MPLAB X IDE in their latest version, v3.10. This importer is a plug-in that allows for source debugging of chipKIT sketches directly within MPLAB X IDE. This plug-in is installable via the MPLAB X plug-in portal under the Tools menu. The only other requirement is a separate install of the latest beta release of UECIDE–an alternative to MPIDE–since the desired sketch must first be created in UECIDE and built in that environment at least once. Subsequent builds and full source-debugging are then supported within MPLAB X IDE.

Hooray!!

VN:F [1.9.22_1171]
Rating: 5.3/10 (8 votes cast)
VN:F [1.9.22_1171]
Rating: +2 (from 2 votes)

MPIDE vs MPLAB IDE

MPLAB X IDE Debugging Environment
MPLAB X IDE: In a debugging environment, you can put a breakpoint wherever you want to stop the code from running. On the bottom of the window, you can see the variable tab where you are able to create watch variables. If you create a watch variable, you can see the values change between each step.

If you’re like me, mixing up things that sound alike is not difficult to do. For example, I can easily mix up chipKIT and PICkit, especially if I’m tired and I’m not thinking well. MPIDE and MPLAB IDE are a close second; they just sound too much alike. So it’s not difficult to see that if the names mix you up and you don’t really know that much about either of them, you might wonder what distinguishes the two and why you’d want to use one over the other. For a quick summary of the differences between using MPIDE (Multi-Platform IDE) and MPLAB X IDE check out this MPIDE vs MPLAB IDE blogpost by Digilent.

However, I would like to preface that article with the following points. Since MPIDE was ported from the original Arduino IDE, and since Arduino was meant to be simple and easy to use, there wasn’t a whole lot of functionality built into the IDE from the beginning. It simply works as an editor allowing you to compile your code and program it to your target board (via the bootloader). Debugging was not built into Arduino IDE, but most people use “printf()” statements and the Serial Monitor to help debug their programs/sketches. Microchip’s MPLAB X IDE, however, has always been a debugging environment in addition to being an editor and integrating a compiler.

That being said, good luck not mixing them up now!

VN:F [1.9.22_1171]
Rating: 6.3/10 (6 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Dr Duino Debugger is chipKIT Compatible


Congratulations to Guido Bonelli for his successful Dr Duino Kickstarter Project!

In this EETimes article, Max Maxfield says that chipKIT Uno32 is compatible with Dr. Duino, a very versatile shield whose purpose is to provide debugging capabilities. This little board is stackable, it comes with switches, LEDs, pots, and much more all conveniently accessible outside of the standard Arduino footprint (not hidden away underneath the stacks of shields), and its open cutout in the center provides access to the board attached below it.

Read more about this neat little board at the two links above and at drduino.com.

VN:F [1.9.22_1171]
Rating: 10.0/10 (1 vote cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Debugging with ejtagproxy and GDB

Debugging without MPLAB is possible through ejtagproxy. You need a compatible ICSP adapter, like PICkit2 or PICkit3 (full list of compatible adapters is available on project homepage). Note that you can’t use PICkit2 with MPLAB, but it works with ejtagproxy. Obtain source, build. Obtain stock GDB source. Configure with –target=mipsel-elf32 . Build. Start ejtagproxy:
$ ejtagproxy
GDB proxy for Microchip PIC32 processors, Version 1.0.25
Copyright (C) 2012 Serge Vakulenko

EJTAGproxy comes with ABSOLUTELY NO WARRANTY; for details
use `--warranty' option. This is Open Source software. You are
welcome to redistribute it under certain conditions. Use the
'--copying' option for details.
ejtagproxy: waiting on TCP port 2000
Start GDB and point it to ELF file of your application:
$ pic32-gdb ~/repos/chipKIT-minimal-application/src/main.elf
(gdb)
Set the target to ejtagproxy:
(gdb) target remote localhost:2000
You should notice that ICSP adapter is now connected to target board. On my chipKIT Max32 this also results in board reset. The ejtagproxy willl print something like:
adapter: PICkit2 Version 2.32.0
processor: Microchip PIC32MX795F512L
processor: reset occured
hardware: 6 breakpoints, 2 watchpoints
oscillator: internal Fast RC
And GDB will connect to target:
Remote debugging using localhost:2000
0xbfc00000 in ?? ()
(gdb)
Now you can set breakpoints, watchpoints, etc. and run the application.
(gdb) break main
Breakpoint 1 at 0x9d00136c: file main.c, line 12.
(gdb) c
Continuing.
Unfortunately, when ejtagproxy is connected to target board everything is much slower than normally, so you have to wait a moment…
Breakpoint 1, main () at main.c:12

12			loop();
As you can see breakpoint was successfully activated in main() function. Now it’s possible to do further analysis:
(gdb) i reg
         zero       at       v0       v1       a0       a1       a2       a3
R0   00000000 ffbfffff ffffffff ffffffff 00000000 00000000 a000001c bf800000 
           t0       t1       t2       t3       t4       t5       t6       t7
R8   9d0011f0 00000000 00000020 04000000 00000000 00000000 00000000 00000000 
           s0       s1       s2       s3       s4       s5       s6       s7
R16  00000000 00100000 00000000 00000000 00000000 00000002 00000000 00000000 
           t8       t9       k0       k1       gp       sp       s8       ra
R24  00000000 00000000 00000000 00000000 a00081f0 a001ffe8 a001ffe8 9d001208 
           sr       lo       hi      bad    cause       pc
     00100000 00000019 00000001 cc37facd a0800034 9d00136c 
          fsr      fir
     can't read register 160 (fsr)
(gdb) disassemble 
Dump of assembler code for function main:
  0x9d00135c <+0>:	addiu	sp,sp,-24
  0x9d001360 <+4>:	sw	ra,20(sp)
  0x9d001364 <+8>:	sw	s8,16(sp)
  0x9d001368 <+12>:	move	s8,sp
=> 0x9d00136c <+16>:	jal	0x9d001328 <loop>
  0x9d001370 <+20>:	nop
  0x9d001374 <+24>:	j	0x9d00136c <main+16>
  0x9d001378 <+28>:	nop
End of assembler dump.
(gdb) stepi
loop () at main.c:1
1	void loop(void) {
(gdb) disassemble 
Dump of assembler code for function loop:
=> 0x9d001328 <+0>:	addiu	sp,sp,-16
  0x9d00132c <+4>:	sw	s8,12(sp)
  0x9d001330 <+8>:	move	s8,sp
  0x9d001334 <+12>:	li	v0,1
  0x9d001338 <+16>:	sw	v0,0(s8)
  0x9d00133c <+20>:	lw	v0,4(s8)
  0x9d001340 <+24>:	addiu	v0,v0,2
  0x9d001344 <+28>:	sw	v0,4(s8)
  0x9d001348 <+32>:	move	sp,s8
  0x9d00134c <+36>:	lw	s8,12(sp)
  0x9d001350 <+40>:	addiu	sp,sp,16
  0x9d001354 <+44>:	jr	ra
  0x9d001358 <+48>:	nop
End of assembler dump.
(gdb)
VN:F [1.9.22_1171]
Rating: 8.0/10 (1 vote cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)