Can anyone advise or point me to a document that specifies how to set up printf to redirect to the a debugger window? I have seen this in demos, but I can't find anything in the CW 7.1 folders, sample projects or documents on it.
Basically, it seemed like printf was being set over the P&E BDM to the debugger.
What board are you using? Many of the boards are different.
If you are using a M52221DEMO, for example, all you have to do to the default project is add console_io_cf.c to it and make sure CONSOLE_IO_SUPPORT is defined to 1.
This is done by default for you in the "CONSOLE_INTERNAL_RAM" target, but not for the others.
The biggest issue with this is it is very slow -- like 5 characters per second -- you can add simple line buffering to the console printf (getting you to 5 lines per second) by adding this to your file:
Deep in the bowls of printf, the routine TRKAccessFile() is called. TRKAccessFile() sets up some registers indicating the data to be printed and then invokes trap #14. The trap #14 handler then executes a halt instruction, freezing the CPU until the Debugger intervenes. When the debugger detects that the trap has been taken, it then examines memory pointed to by the registers, and copies those characters to a debugger console window. The debugger then continues program execution past the halt. No uart is involved. Basically, you get one "file access" in the amount of time it takes to break into the debugger, examine registers, examine memory, and continue -- about 200ms. The real issue is that the new "tiny I/O" console functionality sends printf'd characters *one character at a time* to the debugger console, to save RAM, so the performance is very slow. The simple mod I gave you speeds this up to be "one line at a time", rather than "one character at a time", at the expense of a 128 byte buffer.
The reason I asked is because I tried this and tried the other method (console_io.c),
I run the code, step in, see it going to your printf, and calling the termio_putchar2, like indicated above and still I run, see it hit the printf statements, and I see no debugger output anywhere. I feel like I am missing something.
There may be a few more steps... Just to confirm it all, please check:
1. make sure in your "Link Order" project tab for the target you are building that console_io_cf.c is listed. Just because it is in the "Files" tab (which is for all targets) does not mean it is in the "Link Order" tab for your particular target.
2. make sure in the target settings for your particular target, under Language Settings -> C/C++ Preprocessor, that you see "#define CONSOLE_IO_SUPPORT 1".
3. then go to Debugger -> CF Exceptions and make sure "46 Trap #14 for Console I/O" is checked in two places.
4. make sure that your trap #14 handler executes a halt instruction, followed by an rte. You can confirm this by single stepping into the trap #14 that is in TRKAccessFile(). If you are using the default exceptions.c, this is taken care of by these lines: