Content originally posted in LPCWare by kjhuebner on Sat Sep 25 09:31:23 MST 2010
:DAfter twenty years of writing software and with an MS in computer science, I still prefer printf debug statements in a program -- for reasons I'll mention later.
[B]My problem is Code Red's LPC-Link (which can be used to do a printf output to the LPCXpresso IDE console) corrupts the periodicity of interrupts.[/B]
Setup:
-------
My current goal is to convert an Atmega32 program into an LPC1114 program. So my foray into the Cortex0 world is to write some interrupt code and understand the best approach for debugging in the LPCXpresso IDE.
So I wrote some test code...
I first defined a 32bit timer-based interrupt to run at 2Khz. The interrupt handler only toggles an IO pin high and low, then exits. The handler contains NO printf().
Then in the main() loop I put a printf() for debugging purposes.
However, when tested, I found that when printf was compiled in main(), the handler ran haphazardly and aperiodic. Removing the printf, the interrupt ran a perfect 2Khz.
My hunch: No doubt Code Red's libraries establish one or more interrupts that take precedence over my application's timer interrupt. Why things are so draconian I don't know.
Possible Solutions
---------------------
1. Redefine interrupt priorities. I'm not sure of the feasibility of this, since I determined that my timer interrupt priority level=0 already, which is the highest priority.
2. Forgo LPC Link/semi-hosting and add a compact UART library with a printf function. If anyone is aware of a library for me, please let me know. I would prefer a library that adds no more than 4-6K as I want to keep a minimum debug overhead.
3. Configure the compact Redlib library to use UART, rather than pipe output to the LPC-Link feature. Code Red's printf library (integer based) is wonderfully compact and ideal for debug purposes, but how do I reconfigure it?
If anyone has any ideas for me -- or if the Code Red support team could lend me their wisdom -- I would much appreciate the help.
Thanks!
Ken Huebner
Software Engineer
As for explaining what's so great about printf(), here's my reasons:
[B][I]:cool:Why is printf() is still the best debugging technique?[/I][/B]
Its simple to use, but more importantly...
I am able to monitor signals and values in real-time.
I am able to review and analyze a debug trace for hours on end if I need to.
I am able to copy and paste a debug trace and keep a historic record, for days or months.
Case in point:
I recently wrote a very sophisticated software module that reads a 3-axis accelerometer. I would never have never been able to interpret what was happening with this device in realtime using only a hardware based debugger. God help the soul that relies solely a hardware based debugger. I very much needed a historic log of dozens of parameters and sequence of events over many seconds of operation over many spatial movements. Only printf() can effectively give me this ability.
So my hope is this: I hope that developers and the Code Red support team recognize that getting printf() to work without creating contention issues with the most basic of functions, such as timer interrupts is crucial to my work, and to the work of other developers like me.