Skip to main content
Version: 4.16

10. Physical Buttons


Physical buttons can function as external events usable as triggers from the TouchGFX Designer during application development, or simply used as events in the application backend.

Skip this step if physical buttons are not relevant for your board bring up.


The goal of this section is to develop code that can be used in subsequent TouchGFX HAL- and/or application development.


Here are the verification points for this section:

Verification PointRationale
MCU is configuredMCU GPIOs must be configured to read the state of connected physical buttons.
Connected GPIO can be readOnce code has been developed to read the physical button state from a GPIO this can be used in sub-sequent TouchGFX HAL development.
Reading performs as expectedPolling is a part of application render time. If polling takes too long this should be moved to a different thread or made interrupt based.


  • Physical buttons must be connected to GPIOs on the MCU


The following images show how the schematics might look for a physical button and how it is connected to the MCU

In CubeMX GPIO Port C Pin 13 (PC13) can be configured as an input and configured as a pull-down in the GPIO section of the System Core category.

The code generated by CubeMX will setup the appropriate GPIO port(s) which can now be read:

uint8_t key;
key = 1;

Performance is as expected#

Polling the state of physical buttons should be possible within 1 ms if the code is executed in the same thread as the TouchGFX Application. If not fast enough, consider moving the code to a separate task, at a later stage or making it interrupt based.