I/O Retargeting  Version 1.2.0
User Code Templates for I/O Retargeting using ARM Compiler
 All Files Macros Pages
Retarget STDOUT via Event Recorder

Copy the printf Redirect Example application to your PC using Pack Installer. This simple application is already set to redirect printf output on an ARM Cortex-M0 to the Event Recorder.

To retarget STDOUT to the Event Recorder in a user application, these steps are required:

  1. In the Manage Run-Time Environment window, set the component Compiler:I/O:STDOUT to use Variant EVR.
  2. Select the component Compiler:Event Recorder or use the Resolve button.
    er_comp_selection.png
  3. In the user code, include EventRecorder.h and call the EventRecorderInitialize() function in main():
    #include "cmsis_os2.h" // ARM::CMSIS:RTOS2:Keil RTX5
    #include "stdio.h"
    #include "EventRecorder.h" // Keil.ARM Compiler::Compiler:Event Recorder
    typedef struct {
    uint32_t hi;
    uint32_t low;
    } MyType;
    MyType mysymbol;
    int main(void) {
    int i;
    EventRecorderInitialize(EventRecordAll, 1);
    while (1) {
    for( i=0; i<=30; i++ ) {
    printf("The value of i is %d\n", i);
    mysymbol.hi = i*i;
    mysymbol.low = i;
    }
    }
    }
  4. (For simulation only!) Open the target options dialog and add a Debug.ini file to simulate the DWT Cycle Counter:
    MAP 0xE0001000, 0xE0001007 READ WRITE
    signal void DWT_CYCCNT (void) {
    while (1) {
    rwatch(0xE0001004);
    _WWORD(0xE0001004, states);
    }
    }
    DWT_CYCCNT()

Build and run the project. Open the Debug (printf) Viewer window using View - Serial Windows - Debug (printf) Viewer. The printf output will be shown here:

debug_printf_output.png
Note
If you are using the Event Recorder window at the same time, you will notice that it also shows the printf output, just with hexadecimal display:
er_printf_output.png