It is currently Wed Jul 30, 2014 3:55 am



Post new topic Reply to topic  [ 30 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: A new and easier way to debug chipKIT sketches in MPLAB
PostPosted: Thu Oct 13, 2011 10:01 pm 
Offline

Joined: Tue Sep 13, 2011 4:40 pm
Posts: 175
As I was developing the Network Shield libraries, debugging sketches was an absolute necessity. Some of you have been using a procedure I outlined in “Debugging chipKIT with MPLAB.pdf”. While this allowed for the debugging of sketches which is a tremendous help, the process is clumsy at best; and packed with pitfalls. As I became more familiar with MPIDE and MPLAB I concluded there had to be better way. With a lot of help from a friend at Microchip we were able to create a much better debug process. In short what we are doing is having MPIDE build a debug image in the same way MPLAB 8 would have, then importing that image into MPLAB 8 and debugging it as if MPLAB built the image. Here we are using MPIDE as a replacement compiler / linker for MPLAB. As a result, MPLAB is debugging as it usually does and things just work better.

Attached to this posting is a document (“Debugging chipKIT MPIDE Sketches with MPLAP.pdf” -- zipped) describing the process and a .zip file (“MPIDE_MPLAB_Debug.zip”) that you will have to uses to include some new linker scripts in MPIDE. This process will replace you boards.txt, but it only adds 2 new boards to your MPIDE environment, it does not modify existing board entries (well with the exception of fixing a bug in the “mega_pic32.board” entry). If you rather, you can just cut and paste the 2 new entries into your existing boards.txt Read the document first, it will tell you how to install and what all is involved.

While I have been using this process with great success for a few weeks now, this is my first attempt to formalize the process. So this is all “hot off the presses”. Please give me your comments / corrections. I do not know if this will ever be rolled into MPIDE or not, I think a lot of that depends on what people think of it.

**********************************************
UPDATE as of 10/28/2011:
**********************************************

I found a bug with the clock speeds when debugging. I inadvertently set the peripheral clock div to 8 instead of 1 so when debugging your clock timers were running 8 times slower than they should. Replace your linker scripts with the new ones updated and attached to this posting.

I bundled both the new and old debug documents in the one attached zip file. PLEASE READ the “Debugging chipKIT MPIDE Sketches with MPLAP.pdf” before attempting to debug.

I also included a crude video of debugging the sample Blink sketch with an Uno32, and then show restoring the Uno32 bootloader. This is the same video as included in the post below, but I duplicated it here for convenience.

KeithV
Digilent


Attachments:
File comment: A raw video that shows how to debug the Blink sketch and reprogram the bootloader.
ScreenCapture_10-25-2011 10.47.34 AM.zip [3.7 MiB]
Downloaded 638 times
File comment: PLEASE READ BEFORE ATTEMPING TO DEBUG!

This conatains both the original and new debug documents.

Debugging chipKIT MPIDE Sketches with MPLAP.zip [643.2 KiB]
Downloaded 639 times
File comment: Boards.txt & Linker Scripts.

Updated to correct the peripheral clock speed.

MPIDE_MPLAB_Debug.zip [12.31 KiB]
Downloaded 480 times

_________________
KeithV
Digilent


Last edited by KeithV on Mon Oct 31, 2011 3:36 pm, edited 5 times in total.
Top
 Profile  
 
 Post subject: Re: A new and easier way to debug chipKIT sketches in MPLAB
PostPosted: Fri Oct 14, 2011 1:49 am 
Offline

Joined: Wed Jun 15, 2011 7:04 am
Posts: 22
Hi, Thanks for these instructions. They look promising. I'm not clear on whether another tool like PICkit 3 is required for debugging. Also, this procedure will erase the bootloader, right?


Top
 Profile  
 
 Post subject: Re: A new and easier way to debug chipKIT sketches in MPLAB
PostPosted: Fri Oct 14, 2011 4:24 am 
Offline

Joined: Tue Sep 13, 2011 4:40 pm
Posts: 175
For the Max32 and Uno32 you will need the PICkit3. Yes, this will erase the bootloader, but there are instruction in the document on how and where to reinstall the produciton bootloader.

_________________
KeithV
Digilent


Top
 Profile  
 
 Post subject: Re: A new and easier way to debug chipKIT sketches in MPLAB
PostPosted: Sun Oct 16, 2011 5:12 pm 
Offline

Joined: Sun Jul 24, 2011 12:12 am
Posts: 115
Excellent Kieth, far better than the earlier version.

Unfortunately I have loaned someone my ICD3, but as soon as I get it back I look forward testing out this method.

Cheers
Chris


Top
 Profile  
 
 Post subject: Re: A new and easier way to debug chipKIT sketches in MPLAB
PostPosted: Thu Oct 20, 2011 10:07 am 
Offline

Joined: Tue Sep 13, 2011 9:44 pm
Posts: 14
I've just got all the bits together to try out this method but I have hit one problem right away - I can't get the hex file address from the verbose output. By the time the verbose output stops, all I have in the readout is a long list of red entries which looks like the end of the uploaded data to the board, finishing with "avrdude done. Thank you.". There is no sign of any addresses for the files generated. I'm using the 22nd August version.

I've also tried using search in Win7 for recently written files but haven't found anything that looks like a likely candidate so far.

Jim.


Top
 Profile  
 
 Post subject: Re: A new and easier way to debug chipKIT sketches in MPLAB
PostPosted: Thu Oct 20, 2011 10:21 am 
Offline

Joined: Tue Sep 13, 2011 9:44 pm
Posts: 14
JimG wrote:
I've just got all the bits together to try out this method but I have hit one problem right away - I can't get the hex file address from the verbose output. By the time the verbose output stops, all I have in the readout is a long list of red entries which looks like the end of the uploaded data to the board, finishing with "avrdude done. Thank you.". There is no sign of any addresses for the files generated. I'm using the 22nd August version.

I've also tried using search in Win7 for recently written files but haven't found anything that looks like a likely candidate so far.

Jim.


Take it all back. I just did a bit more digging around and found that my chip select had somehow reverted to the basic Uno and was not set to the Uno -Debug. I've now got the hex address of the file. :)

Jim.


Top
 Profile  
 
 Post subject: Re: A new and easier way to debug chipKIT sketches in MPLAB
PostPosted: Thu Oct 20, 2011 3:52 pm 
Offline

Joined: Tue Sep 13, 2011 4:40 pm
Posts: 175
Jim,

For debugging you do not want to use the .hex, you want to use the .elf, the .hex does not have all of the debug information in it. The .elf contains both the .hex and debug information. This is outlined in the document.

Good luck, let me know how it goes.

_________________
KeithV
Digilent


Top
 Profile  
 
 Post subject: Re: A new and easier way to debug chipKIT sketches in MPLAB
PostPosted: Thu Oct 20, 2011 4:42 pm 
Offline

Joined: Tue Sep 13, 2011 9:44 pm
Posts: 14
KeithV wrote:
For debugging you do not want to use the .hex, you want to use the .elf, the .hex does not have all of the debug information in it. The .elf contains both the .hex and debug information. This is outlined in the document.

Good luck, let me know how it goes.


Mixed results. :)

I'm using the latest version of MPLAB downloaded off the Microchip web site - 8.76. I'm also using the Blink program as the test - I can change the delay times and re-compile to give an easily identifiable new program from the LEDs operation on the board - just to make sure I am actually uploading a new program.

MPLAB runs up and recognises the PicKit3. I also can import the .elf file and debug/program it into the Uno. I also load the .pde file but I cannot get it to set breakpoints. When I double click on a line to set a breakpoint, I only get a hollow red ring in the left hand margin and when I debug/run, I get an error message saying

"One or more breakpoints could not be resolved...Select breakpoints from the debugger menu for details"

When I select the breakpoint menu, no breakpoints are shown.

If I get rid of the message, the program runs. If I halt it, a debug window appears showing the program stopped at a line (usually in one of the delay loops in Blink). If I try to Step Through or over, the whole lot appears to hang and I can only get control back by doing a Debug/reset.

The only way I can get the filled red ring with the white B to appear on the left hand margin is to set my selected tool to "None".

Also, the bootloader I reload onto the Chipkit only seems to let me compile sketches, but doesn't run them. This bootloader is downloaded from the Digilent site and is dated 19th August.

So good in parts - and I'm stuck with a Chipkit which will only run under PicKit3 control with no debugging. :)

All good fun.

Jim.

PS - What a miserable forum - only allows up to two smilies.


Top
 Profile  
 
 Post subject: Re: A new and easier way to debug chipKIT sketches in MPLAB
PostPosted: Fri Oct 21, 2011 6:31 am 
Offline

Joined: Mon May 23, 2011 6:38 am
Posts: 96
Location: Chandler, Arizona
Quote:
When I double click on a line to set a breakpoint, I only get a hollow red ring in the left hand margin

I believe that mpide copies the source files to a temporary directory when compiling them. That means that the image is associated with the files in the temporary location rather than in the original location. You might be able to set breakpoints in those temporary files.

Quote:
Also, the bootloader I reload onto the Chipkit only seems to let me compile sketches, but doesn't run them.

Make sure that you are programming the bootloader from the programmer menu rather than the debugger menu. When you program from the debugger menu, the debug tool programs the device in background-debug mode and and then the device expects a debugger to control it.

P.S. You can now use up to 3 smilies in a post :D :lol: ;)

_________________
Jason Kajita
Microchip Technology
Follow me on Twitter


Top
 Profile  
 
 Post subject: Re: A new and easier way to debug chipKIT sketches in MPLAB
PostPosted: Fri Oct 21, 2011 8:57 pm 
Offline

Joined: Tue Sep 13, 2011 9:44 pm
Posts: 14
jasonk wrote:
I believe that mpide copies the source files to a temporary directory when compiling them. That means that the image is associated with the files in the temporary location rather than in the original location. You might be able to set breakpoints in those temporary files.

I'll go looking for the files in the temp location - thanks for the pointer
Quote:
Make sure that you are programming the bootloader from the programmer menu rather than the debugger menu. When you program from the debugger menu, the debug tool programs the device in background-debug mode and and then the device expects a debugger to control it.

I'm pretty sure I used the programmer menu, but I haven't been able to check things out again aince I find that I cant upload to the Chipkit since MPIDE can't get access to the virtual Com port. If MP LAB and the PicKit3 also use a virtual com port on the USB link, then I think that I've got a clash between the MPIDE and MPLAB. I've been over the PC (it's a Win7 Netbook) for any other com port usage and can't find anything. The MPIDE/Chipkit worked well until I installed MPLAB and used Pickit3. Further investigation will have to wait till next week since I'm going to be doing other things over the weekend.
Quote:
P.S. You can now use up to 3 smilies in a post

Your generosity astounds me, but I've got to remove your quoted ones to get my three in. Shouldn't ones in quotes be ignored? . :) :) :)

Jim


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 30 posts ]  Go to page 1, 2, 3  Next

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Theme designed by stylerbb.net © 2008
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All times are UTC [ DST ]