printf and runtime code

My team and I like to use printf() statements while debugging our code.  This prints to the console in CCES.

This can be slow, but usually tolerable for debugging problems or for test code that exists for board level checkout etc.

My question is, what happens when the emulator is not connected?  Does printf try to write out the JTAG port anyway?  Do I need to make sure that I remove the printf statements from any operational code that needs to run in real-time?  If a function detects and error and then tries to print, does it waste alot of clock cycles?

  • 0
    •  Analog Employees 
    on Dec 4, 2019 11:28 AM over 1 year ago

    For SHARC and Blackfin cores, output to the CCES console is implemented with a so-called "primitive write" operation, which takes a character buffer and its length as its arguments. Glossing over implementation details, printf() basically processes its arguments into one or more primitive write operations, depending on buffering mode.

    The primitive write is implemented with a breakpoint called __primio. When connected to a debug session, the target is halted on the breakpoint, the buffer and length are fetched from the target memory and written to the console, and the target resumes. Most of the overhead is in the halting and resuming of the target.

    Without a debug session, it will simply run through the breakpoint and hence write operations have no effect. However, there nevertheless still is some overhead due to the printf() processing, so guarding out debug output might be worthwhile for the release build. This can also save a fair amount of code space if all the I/O operations can be guarded out.