C-RUN in stand-alone mode

Runtime analysis in stand-alone mode

C-RUN is a runtime analysis tool which works as an add-on to IAR Embedded Workbench for ARM. C-RUN can detect possible errors such as overflow, boundary errors and memory usage errors.

The error messages are displayed in the debug window. However, C-RUN messages can be redirected to any communication channel, and messages can be captured in the field test and checked after the test.

Redirect the C-RUN message to Terminal I/O

C-RUN messages are transferred to PC via semi-hosting which is a hidden process. Source code for C-RUN message is provided under <EWARM>\arm\src\lib\crun. Before make C-RUN works in a stand-alone, let’s see the messages in Terminal I/O.

Add ReportCheckFailedStdout.c to your workspace

Copy ReportCheckFailedStdout.cunder \crun to your workspace.

The file can be read-only attribute. Then remove the attribute from the Windows property. Also, add the file to IAR Embedded Workbench for ARM workspace.

Redirect C-RUN message stdout

Change Linker configuration to redirect the C-RUN error message. As a default, __iar_ReportCheckFailedis called. Specify redirect to __iar_ReportCheckFailedStdout which is defined in ReportCheckFailedStdout.c.

__interwork void __iar_ReportCheckFailedStdout(void * d)
{

char buf[200] = {0};
char *b = buf;

 uint32_t const *data = (uint32_t const *)d;
int nr = data[0] >> 24;

  b = putstring(b, "CRUN_ERROR:");
for (int i = 0; i < nr; ++i)
{     *b++ = ' ';
    b = puthex(b, data[i]); 
  }
  *b++ = '\n';
  __write(_LLIO_STDOUT, (unsigned char const *)buf, (size_t)(b - buf));   if (__iar_ReportCheckFailedStdoutAbort)     abort();
}

Open [Project Option] and set Linker > Extra Options. --redirect __iar_ReportCheckFailed=__iar_ReportCheckFailedStdout>

Run debug with C-RUN

Before you start a debug session, please make sure that you have enabled the specific C-RUN options you would like to detect. Choose Rebuild All and Click Download and Debug Then, open View > Terminal I/O windows and click Go.

If C-RUN detects errors messages, they will be sent to Terminal I/O.

We can now see C-RUN messages in Terminal I/O Window, one line per each message. The messages are raw data andcspybat.exe can show you the message.

Parse the C-RUN raw data with cspybat.exe

cspybat.exe is a tool used for debug batch test. It can also be used as C-RUN raw data parser.

Modify the bat file

Each time the project is build, ***.cspy.bat file is created under settings folder of your project. Open the file with an Editor application. Append -–rtc_filter after --rtc_enableand save the file.

Launch the bat file from command prompt

Open command prompt and move to the settings folder. Type or select with TAB key the bat file.

Then add the.out file path.

In this example, I have copied c.out file to the settings folder to simplify the path, but you could also specify the absolute path. Then press enter.

Now cspybat is waiting for the C-RUN raw data message.

Parse the raw data messages

Paste the message that we got in Terminal I/O. Please remember the message should be sent by one line.

Press Enter, then the parsed messages will be shown as below.

Now we can see Inter conversion failed at main.c Line 16. We can see the similar information as in the ordinary C-RUN messages windows.

Note: call-stack is not included in the CRUN raw data.

Redirect C-RUN message to UART

The C-RUN messages can also be redirected to other communication channel. We can simply edit _iar_ReportCheckFailedStdout()

Edit _iar_ReportCheckFailedStdout()

Open ReportCheckFailedStdout.c in IAR Embedded Workbench for ARM. 

__interwork void __iar_ReportCheckFailedStdout(void * d)
{
  char buf[200] = {0};
  char *b = buf; 

uint32_t const *data = (uint32_t const *)d;
  int nr = data[0] >> 24; 

b = putstring(b, "CRUN_ERROR:");
  for (int i = 0; i < nr; ++i)
  {
    *b++ = ' ';
    b = puthex(b, data[i]); 
  }
  *b++ = '\n';   __write(_LLIO_STDOUT, (unsigned char const *)buf, (size_t)(b - buf));   

  if (__iar_ReportCheckFailedStdoutAbort)
    abort();
}

buf contains C-RUN messages. It is send by __write function. Now, let’s comment-out __write and call the serial send function.

ser_printf() is defined in the other place. UART must be set up before C-RUN send messages.

You can also modify to redirect the C-RUN messages to SPI, I2C or stores in RAM or flash memories.

Run the project and commutate with terminal application

Open the terminal application such as Tera Term and then do Download and Debug.

C-RUN error messages will be displayed in Tera Term. The very first ‘A’ was sent from a normal application code.

Run the board in stand-alone mode

Plug-off the power and remove ICE from the board, then turn on the board. You should now see the C-RUN message in your terminal application.

Now we can collect C-RUN detect messages in the field test without ICE. Off course, the detected messages can be parsed with cspybat.exe as previous process.

Note: Debugger > Download > Use flash loader(s) checkbox needs to be unchecked when you create the bat file. Just uncheck and close workspace will update the bat file.

Conclusion

C-RUN is a very handy and useful runtime analysis add-on. With the technique explained in this article, you can also apply C-RUN in your field test.

This article is written by Kyota Yokoo, Field Applications Engineer at IAR Systems in Tokyo, Japan.

© IAR Systems 1995-2016 - All rights reserved.