How to design the GPIO circuitry

This article describes how to practically interface the General Purpose Input Output lines of the Roadrunner to the external world with the hardware needed to protect the internal device by the possible ESD and EMI present in an industrial environment.


The Microchip SAMA5D27 MCU used by the Roadrunner SOM, has a Parallel Input/Output Controller (PIO) to configure and control all the available GPIO lines. The PIO manages up to 128 fully programmable input/output lines. Each I/O line may be dedicated as a general purpose I/O or be assigned to a function of an embedded peripheral. Look at the Roadrunner pinout to learn how the MCU GPIOs are mapped on the two, one hundred contacts, connectors of the SOM.

A general description of the features available as extracted from the SAMA5D2 Series datasheet:

34.2 Embedded Characteristics

  • Up to 128 Programmable I/O Lines
  • Multiplexing of up to Seven Peripheral Functions per I/O Line
  • For each I/O Line (whether assigned to a peripheral or used as general purpose I/O)
    • Input Change Interrupt
    • Programmable Glitch Filter
    • Programmable Debouncing Filter
    • Multi-drive Option Enables Driving in Open Drain
    • Programmable Pull-Up/Pull-Down on Each I/O Line *Pin Data Status Register, Supplies Visibility of the Level on the Pin at Any Time
    • Programmable Event: Rising Edge, Falling Edge, Both edge, Low-Level or High-Level
    • Configuration Lock by the Connected Peripheral
    • Security management of each I/O line
    • Programmable Configuration Lock (Active Until Next VDDCORE Reset) to protect Against Further Software Modifications (intentional or unintentional)
  • Register Write Protection against unintentional software modifications:
    • One Configuration Bit to Enable or Disable Protection of I/O Line Settings
    • One Configuration Bit to Enable or Disable Protection of Interrupt Settings
  • Synchronous Output, possibility to set or clear simultaneously up to 32 I/O Lines in a Single Write
  • Programmable Schmitt Trigger Inputs
  • Programmable I/O Drive

Each I/O line is designed with an embedded pull-up resistor and an embedded pull-down resistor. Each I/O can be independently programmed in Open-Drain mode. This feature permits several drivers to be connected on the I/O line Which is driven low only by each device. An external pull-up resistor (or enabling of the internal one) is generally required to guarantee a high level on the line. Optional input glitch and debouncing filters are independently programmable on each I/O line. It is possible to configure each input for the Schmitt trigger. Each I/O group can be programmed to generate an interrupt when it detects an edge or a level on an I/O line.

Hardware interfacing

If the I/O lines need to be connected to external sensors or actuators of any kind, wired in home, office or whatever else industrial environment together with many other installations, a great care has to be applied on protecting the MCU pins from ESD and EMI.


In this example the TVS, together with the series resistor, protects the I/Os from any voltage that could be dangerous for the MCU. Low pass RC filters out the high frequency noise. In this case a pull-up resistor is required to connect a simple switch, but a pull-down too may be used if the external device is capable of rising the voltage level. Finally, the mosfet offers an even greater level of division from the outside, also driving a status LED. The internal ground is isolated by the inductor that can be used by many other inputs as a common, filtered return for all of them.


On the output side too a mosfet is used in this example to design an open-drain circuit that shorts to a common return the externally powered load. An LC, to keep low the resistance to ground, composes usual low pass filter here.

Related links

Guido Ottaviani - -