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:
- In the Manage Run-Time Environment window, set the component Compiler:I/O:STDOUT to use Variant EVR.
- Select the component Compiler:Event Recorder or use the Resolve button.
- In the user code, include
EventRecorder.h
and call the EventRecorderInitialize()
function in main(): #include "cmsis_os2.h"
#include "stdio.h"
#include "EventRecorder.h"
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;
}
}
}
- (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:
- 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: