Keil Logo

I/O Ports

µVision3 defines a VTREG for each I/O port: i.e. PORTA. Do not confuse these VTREGs with the Peripheral Registers for each port (i.e. PIOA_OSR). The Peripheral Registers can be accessed inside the CPU memory space. The VTREGs are the signals present on the pins.

With µVision3, it is easy to simulate input from external hardware. If you have a pulse train coming into a port pin, you can use a signal function to simulate the signal. For example, the following signal function inputs a square wave on PORTA pin 0 with a frequency of 1000Hz.

signal void one_thou_hz (void) {
  while (1) {                      /* repeat forever       */
    PORTA |= 1;                    /* set PORTA bit 0      */
    swatch (0.0005);               /* delay for .0005 secs */
    PORTA &= ~1;                   /* clear PORTA bit 0    */
    swatch (0.0005);               /* delay for .0005 secs */
  }                                /* repeat               */
}

The following command starts this signal function:

one_thou_hz ()

Refer to µVision3 Debug Functions for more information about user and signal functions.

Simulating external hardware that responds to output from a port pin is only slightly more difficult. Two steps are required. First, write a µVision3 user or signal function to perform the desired operations. Second, create a breakpoint that invokes the user function.

Suppose you use an output pin (PORTA bit 0) to enable or disable an LED. The following signal function uses the PORT2 VTREG to check the output from the CPU and display a message in the Command window.

signal void check_pA0 (void) {
  if (PORTA & 1)) {                            /* Test PORTA bit 0 */
    printf ("LED is ON\n"); }                  /* 1? LED is ON */
  else { /* 0? LED is OFF */
    printf ("LED is OFF\n"):
  }
}

Now, you must add a breakpoint for writes to port 1. The following command line adds a breakpoint for all writes to PORT2.

BS WRITE PORT2, 1, "check_p20 ()"

Now, whenever your target program writes to PORT2, the check_P20 function prints the current status of the LED. Refer to Breakpoints for more information about setting breakpoints.

  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.