Keil Logo

User Functions

User Functions are created by the developer and can be used for debugging within the µVision Debugger. Create user functions directly in the Command window or with the function editor. Refer to Creating Functions for details. System Variables can be used in user functions.

User functions begin with the keyword FUNC and are defined as follows:

FUNC return_type fname (parameter_list) {
  statements
}

Where

return_type Is the type of the value returned by the function and can be: bit, char, float, int, long, uchar, uint, ulong, void. If no return type is specified, then the type int is assumed.
fname Is the name of the function.
parameter_list Is the list of arguments passed to the function. Each argument must have a type and a name. If no arguments are passed to the function, use void for the parameter_list. Multiple arguments are separated by commas.
statements Are instructions the function carries out.
{ } Are the opening and closing brace. The function definition is complete when the number of opening braces is balanced with the number of closing braces.

Example

The following user function displays the contents of several CPU registers.

FUNC void MyRegs (void) {
  printf ("---------- MyRegs() ----------\n");
  printf (" R4 R8 R9 R10 R11 R12\n");
  printf (" %04X %04X %04X %04X %04X %04X\n",
            R4,  R8,  R9,  R10, R11, R12);
  printf ("------------------------------\n");
}

Invoke the function by typing the function name into the Command window.

MyRegs()

The function output could be:

---------- MyRegs() ----------
 R4   R8   R9   R10  R11  R12
 B02C 8000 0001 0000 0000 0000
------------------------------

As an alternative, define a Toolbox button to invoke the user function:

DEFINE BUTTON "My Registers", "MyRegs()"

Restrictions

  • µVision does not check every return path for a valid return value. Make sure to return the proper type for each return branch.
  • User functions should not invoke Signal Functions or the built-in function twatch.
  • The value of a local object is undefined until a value is assigned to it.
  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.