Using GPIOs in real-time capable applications

Azure Sphere supports GPIOs (general-purpose input/output). A GPIO is a type of programmable digital pin on an integrated circuit. GPIOs don't have predefined functionality and their behavior can be customized by an application. Some common uses for GPIOs are to change the state of hardware devices, control LEDs, and read the state of switches.

This topic describes how to use GPIOs in a real-time capable application (RTApp). For information about using GPIOs in high-level applications, see Using GPIOs in high-level applications.

An RTApp can use any of the GPIOs on the Azure Sphere device. The following operations are supported for GPIO:

  • Read input
  • Set output to high or low
  • Poll software interrupts

Note

The Azure Sphere OS does not reset peripherals on start-up. Your applications should ensure that peripherals are in a known-good state on startup and after restart.

MT3620 support for GPIOs on the real-time cores

On the MT3620, most GPIOs are mapped to real-time cores in blocks of four, starting with GPIO 0; however, ISU blocks 0 - 4 have five GPIOs. As a result, RTApp GPIO requests may fail if a high-level application (or another RTApp) requests a GPIO in the same block. For example, if a high-level app requests GPIO 8 and an RTApp requests GPIO 9, the second app returns an error at deployment.

Each LED on the MT3620 RDB maps to three GPIOs: one each for red, green, and blue channels.

For register base addresses, interrupt numbers, clock rate, sampling frequency, and other details about the MT3620, see the MT3620 Datasheet and the MT3620 M4 User Manual; if questions remain, you can request details from Avnet by emailing Azure.Sphere@avnet.com.

GPIO Requirements

Your application code needs a way to identify the GPIO and its registers. You can find the register base address in the manufacturer's hardware documentation. Before your RTApp can use a GPIO, it must initialize the blocks that it is going to use. Initialization is required only once for each block that the app uses.

For details about the MT3620, see MT3620 support for GPIOs on the real-time cores.

Application manifest settings

To use a GPIO, an RTApp must list it in the Capabilities section of the application manifest. Identify the GPIO by using the "AppManifestValue" that is defined for it in the JSON file for the target hardware. For example, the following line reserves GPIOs 8 and 12:

"Capabilities": {
 "Gpio": [ 8, 12 ]
}

The GPIO sample application

The GPIO sample demonstrates how to use GPIOs in an RTApp. The README files provide details and instructions.