Library 57- Buttons for STM32F4xx

I had some free time so I made a new library for web. It can handle buttons, connected to your STM32F4xx device.

It supports basically unlimited number of buttons with different triggering. Currently, callback functions can be called on these events:

  • Button on pressed: Called directly when button is pressed
  • Button normal press: Called when button is released after specific amount of time
  • Button long press: Called when button is pressed for specific “long” amount of time

It uses malloc() to allocate memory, so you have to make sure that your heap is big enough. It also allows you to select state when button is pressed, high or low.

Currently, it does not support double click event but this will be done (I hope) in near future.

You just have to make sure, that your button is properly connected to STM device with capacitor and pull resistor!



  • Supports buttons connected to STM32F4xx
  • Support different button trigger events


    • STM32F4xx
  • TM
    • TM GPIO
    • TM DELAY
    • defines.h

Library uses some predefined constants which can be changed in your defines.h file:

Functions and enumerations


Example below is done for Nucleo or Discovery board. 2 buttons on specific pins are initialized for use. Output is on PA2 for USART.

Project is available on my Github account, download library below.


Owner of this site. Application engineer, currently employed by STMicroelectronics. Exploring latest technologies and owner of different libraries posted on Github.

You may also like...