Keil Logo

GENERAL: INCLUDING TEST CODE IN APPLICATIONS


Information in this article applies to:

  • C166 Version 4.20
  • C251 Version 3.20
  • C51 Version 6.20
  • µVision2 Version 2.20

QUESTION

While testing my embedded application, I need to output debugging information. Is it possible to write code that is executed only in debug mode?

ANSWER

Yes. There are several ways you can accomplish this.

Including Calls to printf in Your Application

You may use #define and #if pre-processor statements to include parts of your code in a debug version of your software. For example, you can write:

void main (void)  {
  init_serial ();         // initilize serial interface
#ifdef DEBUG
  printf ("This is a Debug Version\n");
  test_function ();
#endif
  standard_function ();
  while (1);
}

When you use µVision2 you may:

  • Enter the symbol DEBUG under Options for Target - C Compiler - Define:
  • Create different targets for the test/debug and release version as explained in µVision: MULTIPLE PROGRAMS FROM 1 SOURCE FILE SET and include the DEBUG symbol in just one of the targets.

Using the Debugger to Output Debug Information

You may set breakpoints in the debugger that output information including the values of program variables. For example, in µVision2, you may enter the following in the command window to output the value of the variable j in the debugger's command window.

bs \blinky\15 , 1, "printf(\"j = %u\\n\", (unsigned) j)"

This command sets a breakpoint on line 15 of the module named blinky. Each time the line is executed, the value of j is output to the command window.

Last Reviewed: Thursday, October 18, 2001


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.