Re: Debugging: Am I a dreamer. . . ?



On Apr 29, 10:21 pm, Tim Wescott <t...@xxxxxxxxxxxxxxxx> wrote:
On Tue, 29 Apr 2008 16:45:34 -0700, Tomás Ó hÉilidhe wrote:
I've been programming in C for the best part of a decade now but it's
only within the last year that I've really started doing embedded
systems programming.

When I did C programming for a personal computer, I commonly debugged my
code simply by putting in printf statements around the place to check
variable values, and also by using the instrument that lets you check
the values of variables at runtime when you're stepping through the
code.

Anyway, when I was doing my embedded systems project this year for
college, I was kind of in the dark when my board's program started to
malfunction. If I'd been using a PC, I would have used the debugger to
single-step through code to check variables' values. What I eventually
did was take the offending code and move it across to a PC, and then I
used the PC to debug it.

Anyway, here's the dream I had in my head, which may or may not be a
pipe dream:
You know the PIC16F684 chip that costs less than a dollar, well
what if they brought out the debug version of it (that costs maybe 20
dollars). The debug version would fit perfectly into the normal chip
slot, except that it would have some sort of socket on the top of it for
hooking it to a PC for doing stuff like printf's, and also maybe for
running a full debugger that will let you check variables' values?

Many chips have in-circuit debugging features, including that one. Read
the fine manual. Few require the chip-and-socket approach -- that's more
of an 80's/90's thing.

For some applications you'll find that reserving a pin (or pins) for
debugging that you can twiddle with in software instead of a printf is
more valuable than gold. Given an oscilloscope, not only will it tell
you _that_ your code executes, but if you're careful it'll tell you when
and for how long.

--
Tim Wescott



My general rule is: do not use printf() for debugging if you do not
use it in the normal embedded application (Not all embedded systems
are bare bones, no display systems.) That said I usually do not use
printf() at the point of going to real hardware. by then you should
have unit tested to the point that you KNOW there are no unhandled
failure points. (You have to KNOW this if you are developing any
medical device.)

I have worked on several systems where circuitry for a single output
register controlling a set of LEDs has proven VERY useful. I was
always amazed how much information I could get just watching the LEDs
flashing (sometimes even displaying 2things at once).

Ed

.



Relevant Pages

  • Re: Printing from kernel
    ... >area where it's unsafe to print, probably holding a lock that's needed ... Instead of messages from kernel I see the first letter ... >No. printf() is widely used in the kernel. ... It is used not only for debugging by myself, part of this output is my ...
    (freebsd-hackers)
  • Re: Debugging: Am I a dreamer. . . ?
    ... What's wrong with debugging using printf? ... "printf", which you should normally avoid in a small embedded system, ... runs is a very useful debugging technique. ... software UART for debugging output. ...
    (comp.arch.embedded)
  • Re: Debugging: Am I a dreamer. . . ?
    ... What's wrong with debugging using printf? ... runs is a very useful debugging technique. ... One thing that often seems to get overlooked is assert(). ... neat trick is the trigger behaviour. ...
    (comp.arch.embedded)
  • Re: Debugging: Am I a dreamer. . . ?
    ... When I did C programming for a personal computer, ... or debugger to remove bugs, only gives the design more bugs. ... You should never debug using printf. ... I don't mean specifically "printf", which you should normally avoid in a small embedded system, but the general idea of putting out extra information while the program runs is a very useful debugging technique. ...
    (comp.arch.embedded)
  • Re: Debugging: Am I a dreamer. . . ?
    ... systems programming. ... or debugger to remove bugs, only gives the design more bugs. ... You should never debug using printf. ... runs is a very useful debugging technique. ...
    (comp.arch.embedded)