• AVR Freaks

PIC handheld debugger - how I did it

Author
jarin
Super Member
  • Total Posts : 848
  • Reward points : 0
  • Joined: 2005/05/23 13:50:02
  • Status: offline
2009/07/05 10:47:22 (permalink)
3.5 (2)

PIC handheld debugger - how I did it

Hi all friends,
 
This will be a longer story, story about writing a lots of code, dreaming, sleepless nights, building a complete handheld PIC debugger (working on the same basis as PicKit2 or ICD2) and also a story about how Microchip thought that their customer is idiot. Unlike most of posts, it will not include any complain or ask for a help with some kind of problem, just reading for interested ones...
 

...for a long time, I dreamt about a small device, which could be programmed in some programming language, a device which could be taken everywhere, that would fit my hand portable and independent from electrical network, etc. While there are lots of PDA class computers, smart (whatever it means) phones and small netbooks, which could serve for this, all that doesn’t exhibit one important feature - to be DIY hand made. That time (I was maybe 14 or 15 years old) I had no clue about microcontrollers nor microprocessors so all those thoughts remained just dreams.
 
Now things slightly changed. While studying university I did a small device, consisting of 8052 basic module (compressed into one 89C51RD2 device, really single-chip solution) with 18F2620 with LCD and keypad display serving as terminal, plus some other components (PSU, RS232 interface etc) forming a small computer-like device, able to program itself in BASIC. A lot of people asked me, what is it good for... well, for nothing. There is no real reason for doing something like that, except of good feeling after completing a device, which really works, stretching a brain, hobby or whatever you call it. But after all, I felt unsatisfied with that and want something more.
I took a 18F2620 (yes, my favorite, when it comes to 18F family), added a keypad and display and wrote a small program, which enabled me to change a portion of RAM – all done in means of hexadecimal numbers, then I could burn this image into FLASH and jump at this address – sort of monitor program, like WOZMON for Apple1 computer. Writing in machine code could be interesting as well as annoying and slow, so I felt something like small assembler would be great. First I looked for assembler, which could fit into a few kilobytes of RAM, but how wrong I was! I decided to write my own. I won’t bother you with this task, it took me a few weeks to write a small assembler for 18F devices, which could fit into RAM of PIC18F2620, after leaving a 2kB of RAM for program buffer! It was a pretty poor-featured assembler, but worked after all.
Well, nice tool-chain on chip... editor, assembler and burner. Debugger would be nice, but who knows, how to? Except of Microchip guys, probably nobody. There is NO specification for on-chip debug module contained in every single PIC18.
Fortunately, in that time I found book, which was miraculous for me... Coin-Cell-Powered Embedded design by John Peatman. To be honest, most exciting for me wasn’t that designs, covered in book, as I found it quite usual for me, but the mention about debug mode in monitor (QwikBug), which serves as basis for those project really got me. I downloaded sources and started to study. I was unsure about a few things, so I nicely asked Microchip, whether they could send me a description of debug mode for 18F PICs. First of all they treated me like a complete idiot (just got response that resources needed by ICD2 debugger can be found somewhere in help – ie. not what I asked) and when I asked again, they responded that they don’t have any debugging specification and my support ticked was closed. Great support, I must admit! Well, help yourself, little man.
So I returned back into studying sources for QwikBug, disassembling hex-binaries from PicKit2 directory (debug executives for various PICs) and ICD2 as well, studying sources for PicKit2, and .xml files. I also wrote to John Peatman, who gave me a few valuable comments. This was still incomplete source. After a long, long and again long days and nights spent with this and after a unbelievable amount of experiments I finally got that damned (see Note 1, bottom) PIC to enter debug mode by itself.
Then I found out that debugging PIC by itself wouldn’t be easy, and if it would be easy, then it wouldn’t be useful and if it even would be useful, it will not be useful very much. So I decided to decline my way of single-chip tool-chain and soldered another PIC into my breadboard, as a slave device.
 
Then started another long story, consisting of writing debug executive for slave PIC and complete debug engine for master PIC. It took me a lot of time to get functional couple debugger-target and I must admit that this, along with reverse engineering of debug specifications for PIC18 was the most challenging task I ever did in my short life (25 years old now) – I started with a few incomplete information all around and finished with working system.
 
Then came some small “cosmetic” changes, like porting whole editor-assembler-burner-debugger into dsPIC33FJ128GP802 – just because of more RAM, more horse power (for assembler and debugger), adding a bigger display, writing a GUI for debugger and so on. After all this my new PIC18 debugger is done. If you wish to know, how it looks and how it works, look at this PDF http://zbernica.chytrak.cz/files/hdm_desc.pdf (size about 4 megabytes) there is a few images and comments.
 
Currently it supports just PIC18F4620 (2620, 4610 and 2610 in theory), I’m planning to add support for another PIC MCUs, for another members of 18Fxxxx family it would be quite straightforward, for 18FxxJxx it would be somehow more complicated (another programming specifications). PIC16F probably will not be supported, as I’m lazy to redesign assembler and what is more, it seems that debugging various of those MCUs is much more diverse than for 18F. 16-bit PIC definitely will not be supported, as I don’t have a clue about debugging of them, as well as changes to assembler would be really dramatic (lots of opcodes and addressing modes).
Only single-supply ICSP is supported (using PGM), but it would be easy to change it into high-voltage ICSP, but I was lazy to include Vpp supply on board.
 
Well, and there comes point of this entire story.
 
My question is, whether there would be a demand for description of this gadget? There would be a hell lot of writing (description of debug mode, how to enter it, all diagrams, timings, how debug executive works, how I did it, how it could be done in other ways etc... I expect it to be sized like a MSEE final thesis), considering the fact this is not paid work :-) and I would like to know, whether it will not be just for nothing.
Another thing is that I will probably attend a local design contest, so I have to squeeze it into a small plastic case (and design PCB etc...), in order to look reasonably, so this will take me a lot of time and I better describe complete version.
 
There is only official debug specification for PIC16F87x from Microchip, so this would be a first attempt to give a more-less complete description of debug mode for PIC18 family.
I’m sorry about the fact that this specification (I keep in my head and in my source codes) is a result of reverse engineering. It seems that Microchip will better support lazy students desperately seeking for help why is their LED not blinking (usual cases: wrong oscillator, bad code etc...) rather than serious developers looking for information regarding “deeper“ aspects of PIC.
 
Now I’m expecting response, whether is there a demand for description of device, or just debug mode or nothing at all.


------------------------------
EDIT:
Note 1: seems like forum engine doesn't allow me to use word damned, I mean D.A.M.N.E.D. but it really captures reality, in this case, whether it is a "good" or "bad" word.
post edited by jarin - 2009/07/05 10:57:00

Jaromir Sukuba, Bratislava, Slovakia
http://jaromir.xf.cz/  - open source PIC18 debugger.
#1

19 Replies Related Threads

    MBedder
    Circuit breaker
    • Total Posts : 6974
    • Reward points : 0
    • Joined: 2008/05/30 11:24:01
    • Location: Zelenograd, Russia
    • Status: offline
    RE: PIC handheld debugger - how I did it 2009/07/05 12:16:05 (permalink)
    0
    I seem to join those who asked you - what is it good for?gringringrin
    #2
    jarin
    Super Member
    • Total Posts : 848
    • Reward points : 0
    • Joined: 2005/05/23 13:50:02
    • Status: offline
    RE: PIC handheld debugger - how I did it 2009/07/05 13:51:31 (permalink)
    0
    ORIGINAL: MBedder

    I seem to join those who asked you - what is it good for?gringringrin


    Is there really need for reason? grin
    It's a mental excersise as well as realizing an old dream. That tool, if it is tool at all, is not very useful, but that is not point.

    I do another goofy and pointless things in my spare time. Like building CPU from TTL logic, implementing a virtual machine into another MCU or trying to understand women's logic.

    Jaromir Sukuba, Bratislava, Slovakia
    http://jaromir.xf.cz/  - open source PIC18 debugger.
    #3
    Stefan Uhlemayr
    Super Member
    • Total Posts : 4292
    • Reward points : 0
    • Joined: 2005/05/12 12:25:46
    • Location: Germany
    • Status: offline
    RE: PIC handheld debugger - how I did it 2009/07/05 14:05:46 (permalink)
    0
    ORIGINAL: jarin

    ORIGINAL: MBedder

    I seem to join those who asked you - what is it good for?gringringrin


    Is there really need for reason? grin
    It's a mental excersise as well as realizing an old dream. That tool, if it is tool at all, is not very useful, but that is not point.
    At least, its an impressive lesson to learn the (secret??? sad) internals of PIC's. If its really this bad documented as you describe, I wonder a little bit, how third parties (like mikroelektronika) were able to build their own debuggers?
    ORIGINAL: jarin

    ... or trying to understand women's logic.
    Hard, really hard - sometimes even impossible. wink

    Greetings,
    Stefan
    #4
    MBedder
    Circuit breaker
    • Total Posts : 6974
    • Reward points : 0
    • Joined: 2008/05/30 11:24:01
    • Location: Zelenograd, Russia
    • Status: offline
    RE: PIC handheld debugger - how I did it 2009/07/05 14:19:38 (permalink)
    0
    ...trying to understand women's logic.
    When I was 25 I had no spare time to invent and build unnecessary gadgets - learning women's logic took all that spare time awaygringringrin
    #5
    Stefan Uhlemayr
    Super Member
    • Total Posts : 4292
    • Reward points : 0
    • Joined: 2005/05/12 12:25:46
    • Location: Germany
    • Status: offline
    RE: PIC handheld debugger - how I did it 2009/07/05 14:45:54 (permalink)
    0
    ORIGINAL: MBedder

    ...trying to understand women's logic.
    When I was 25 I had no spare time to invent and build unnecessary gadgets - learning women's logic took all that spare time awaygringringrin
    And, have you had success? grin

    My wife thoughts about this (she told me now with smile): Hey men, never try to understand women's logic. My god, you may have success... (Не пытайтесь понять женщину, а то, не дай бог, еще поймете!)wink
    #6
    MBedder
    Circuit breaker
    • Total Posts : 6974
    • Reward points : 0
    • Joined: 2008/05/30 11:24:01
    • Location: Zelenograd, Russia
    • Status: offline
    RE: PIC handheld debugger - how I did it 2009/07/05 14:58:03 (permalink)
    0
    ORIGINAL: Stefan Uhlemayr

    And, have you had success? grin
    How do you think - is a 35 years long marriage a success or not?gringrin 
    #7
    Stefan Uhlemayr
    Super Member
    • Total Posts : 4292
    • Reward points : 0
    • Joined: 2005/05/12 12:25:46
    • Location: Germany
    • Status: offline
    RE: PIC handheld debugger - how I did it 2009/07/05 15:04:36 (permalink)
    0
    ORIGINAL: MBedder

    How do you think - is a 35 years long marriage a success or not?gringrin
    My congratulations! Our way isn't this long up to now, but we're driving fine...Smile
    #8
    xiaofan
    Super Member
    • Total Posts : 6247
    • Reward points : 0
    • Joined: 2005/04/14 07:05:25
    • Location: Singapore
    • Status: offline
    RE: PIC handheld debugger - how I did it 2009/07/05 15:21:59 (permalink)
    0
    Very interesting work!

    Have you looked at Piklab code? It also aims to support debugging of PIC18F and PIC16F with ICD 2.
    http://piklab.sourceforge.net/devices.php

      USB_Links and libusb
    #9
    jarin
    Super Member
    • Total Posts : 848
    • Reward points : 0
    • Joined: 2005/05/23 13:50:02
    • Status: offline
    RE: PIC handheld debugger - how I did it 2009/07/05 16:47:14 (permalink)
    0
    ORIGINAL: Stefan Uhlemayr
    At least, its an impressive lesson to learn the (secret??? sad) internals of PIC's. If its really this bad documented as you describe, I wonder a little bit, how third parties (like mikroelektronika) were able to build their own debuggers?


    As far I know, all debuggers on market are more or less good copied clones of ICD2 or PicKit2. Web is full of such as circuits. No invention, no fun.


    Jaromir Sukuba, Bratislava, Slovakia
    http://jaromir.xf.cz/  - open source PIC18 debugger.
    #10
    jarin
    Super Member
    • Total Posts : 848
    • Reward points : 0
    • Joined: 2005/05/23 13:50:02
    • Status: offline
    RE: PIC handheld debugger - how I did it 2009/07/05 16:52:25 (permalink)
    0
    ORIGINAL: xiaofan

    Very interesting work!

    Have you looked at Piklab code? It also aims to support debugging of PIC18F and PIC16F with ICD 2.
    http://piklab.sourceforge.net/devices.php


    I haven't look at it.
    Why should I do, when I have my own debugger? grin

    But seriously, I was thinking of adding RS232 or USB interface along with a group of some simple commands in order to make all debugging actions accesible from a PC side... then it would be possible to omit keyboard and display and your REALLY open source debugger is here!

    Jaromir Sukuba, Bratislava, Slovakia
    http://jaromir.xf.cz/  - open source PIC18 debugger.
    #11
    jarin
    Super Member
    • Total Posts : 848
    • Reward points : 0
    • Joined: 2005/05/23 13:50:02
    • Status: offline
    RE: PIC handheld debugger - how I did it 2009/07/05 16:57:40 (permalink)
    0
    ORIGINAL: MBedder

    ...trying to understand women's logic.
    When I was 25 I had no spare time to invent and build unnecessary gadgets - learning women's logic took all that spare time awaygringringrin


    What version of multitasking kernel did you have? I may have newer version, so I manage to do that at once... grin

    Jaromir Sukuba, Bratislava, Slovakia
    http://jaromir.xf.cz/  - open source PIC18 debugger.
    #12
    Picant
    Starting Member
    • Total Posts : 53
    • Reward points : 0
    • Joined: 2003/11/07 12:44:56
    • Status: offline
    RE: PIC handheld debugger - how I did it 2009/07/05 22:39:54 (permalink)
    0
    Congratulations! Very nice work. I sent you a PM about the subj. Please take a look.

    Regards,
    Pavel
    #13
    LinuxMichi
    Junior Member
    • Total Posts : 102
    • Reward points : 0
    • Joined: 2008/11/09 20:23:55
    • Location: Germany/Kehl
    • Status: offline
    RE: PIC handheld debugger - how I did it 2009/12/01 05:56:39 (permalink)
    0
    Hallo Stefan,

    ORIGINAL: Stefan Uhlemayr
    At least, its an impressive lesson to learn the (secret??? sad) internals of PIC's. If its really this bad documented as you describe, I wonder a little bit, how third parties (like mikroelektronika) were able to build their own debuggers?

    Greetings,
    Stefan


    I think you have two options:

    1) Buy a bunch of actions to get into the Enterprise
    2) Hire a Jobless spion and let them get it...

    I have asked myselv a couple of times... There are many Enterprises making debuger and such, but If I askes a manufacturer for the specs, they have never respond to it. This sucks!

    Greetings
    Michelle

    Low Energie Electronic Developmentand Renewable Energies
    Autonomous Energy Supply Systems
    electronica@tdnet
    #14
    zwizwa
    New Member
    • Total Posts : 10
    • Reward points : 0
    • Joined: 2008/08/06 00:06:01
    • Location: 0
    • Status: offline
    Re:PIC handheld debugger - how I did it 2010/09/24 01:04:07 (permalink)
    0
    jarin

    Hi all friends,
     
    This will be a longer story, story about writing a lots of code, dreaming, sleepless nights, building a complete handheld PIC debugger (working on the same basis as PicKit2 or ICD2) and also a story about how Microchip thought that their customer is idiot. Unlike most of posts, it will not include any complain or ask for a help with some kind of problem, just reading for interested ones...
     


    I like it!
    I'm also interested in anything you figured out about the debugger.
    I would like to add this functionality to the Staapl macro-assembler-on-steroids ( http://zwizwa.be/staapl ) which is currently very 18F specific.
    Please contact me on tom@my.domain

    #15
    Interrupt
    Super Member
    • Total Posts : 200
    • Reward points : 0
    • Joined: 2008/07/06 05:16:55
    • Location: Australia
    • Status: offline
    Re:PIC handheld debugger - how I did it 2010/09/24 07:15:20 (permalink)
    0
    women's logic


    Oxymoron???
    #16
    ytlee
    Super Member
    • Total Posts : 1135
    • Reward points : 0
    • Joined: 2003/11/07 12:44:25
    • Status: offline
    RE: PIC handheld debugger - how I did it 2010/09/24 10:19:50 (permalink)
    0
    MBedder

    ORIGINAL: Stefan Uhlemayr

    And, have you had success? grin
    How do you think - is a 35 years long marriage a success or not?gringrin 


    No, it only means
     
    1. you were slow to realize your mistake
    2. your study subject was too smart
     
    how is that for the male ego?
    #17
    jarin
    Super Member
    • Total Posts : 848
    • Reward points : 0
    • Joined: 2005/05/23 13:50:02
    • Status: offline
    RE: PIC handheld debugger - how I did it 2011/03/19 00:07:35 (permalink)
    0
    This thing got open-sourced in its pre-alpha version.
    http://jaromir.xf.cz/hdeb/hdeb.html

    Jaromir Sukuba, Bratislava, Slovakia
    http://jaromir.xf.cz/  - open source PIC18 debugger.
    #18
    recursos
    Super Member
    • Total Posts : 674
    • Reward points : 0
    • Joined: 2006/01/20 03:50:18
    • Location: Portugal\Carcavelos
    • Status: offline
    RE: PIC handheld debugger - how I did it 2011/03/19 03:07:51 (permalink)
    0
    Hi jarin,
    I like it.
    Rec

    #19
    Joseph Watson
    New Member
    • Total Posts : 9
    • Reward points : 0
    • Joined: 2014/05/09 22:05:24
    • Location: 0
    • Status: offline
    RE: PIC handheld debugger - how I did it 2014/07/10 18:31:13 (permalink)
    -2 (1)
    Hi Jarin,
     
    I like your story. I have seen where you have written that since the debugger accesses the target device via RB6, RB7, and MCLR that the debugger must also be a programming device (as in ICSP programming). It does make sense since those signals are available on an ICSP connection. So I see where this is possible but I often use a bootloader to load code into PIC18F2550 chips.
     
    1. Is there some inherent reason why a bootloader cannot be used to store programs to be debugged in the target device?
     
    2. Is there some reason why a bootloader cannot be used to install the Debug Vector (DV) and some type of Debug Executive (DE) ?
     
    Thanks,
    Joe
     
    #20
    Jump to:
    © 2021 APG vNext Commercial Version 4.5