HAL library 2- LEDS and BUTTON for STM32 boards

Next library in series in disco library for controlling leds and reading button state on various STM32F0, STM32F4 and STM32F7 boards.
Supported boards:

  • STM32F401-Discovery
  • STM32F4-Discovery
  • STM32F411-Discovery
  • STM32F429-Discovery
  • STM32F439-EVAL,
  • STM32F401-Nucleo
  • STM32F411-Nucleo
  • STM32F446-Nucleo
  • STM32F091-Nucleo
  • STM32F7-Discovery


Read more about new HAL libraries


  • Set LED state
  • Read LED state
  • Read button state


  • HAL
  • TM
    • STM32Fxxx HAL
    • defines.h

Library required settings

In order to tell which board you use, you have to set some defines for it. These defines are also used in other libraries to automatically identify used board. For example, my SDRAM library checks for board define to know how to init SDRAM settings for different boards. So, in your defines.h configuration file, set one define according to these available:

When using my examples for Keil uVision, you won’t see these defines in defines.h file. They are set in “Options for Target” in IDE!

Functions and enumerations


Example is available on Github, download all libraries below.

TM STM32 Libraries

STM32 libraries based on STM32Fxxx HAL drivers.


Owner of this site. Also electronic enthusiasts, web developer, 3D printer fan, handball player and more. Big fan of STM32F4 devices. In anticipation of the new Discovery board for STM32F7 lines.

You may also like...

Read before commenting!

Before you make a new comment, make sure you agree with things listed below:

  • - Read post to make sure if it is already posted what you are asking for,
  • - Make sure you have the latest version of libraries used in your project,
  • - Make a clean and grammatically correct written message,
  • - Report as many details as possible, including what have you done so far,
  • - Do NOT post any code here. Use Pastebin,
  • - Do NOT post any error codes here. Use Pastebin,
  • - Specify STM32Fxxx family and used Discovery/EVAL/Nucleo or custom made board,
  • - Make sure your clock is set correct for PLL,
  • - If you are using my HAL drivers, please check this post how to start.
Comment will be deleted on breaking these rules without notification!