HAL library 1.5- GPIO for STM32Fxxx

GPIO library is second mainly used library in your project. It is designed to be very easily used for initializing GPIO pins without making sure if clock is enabled or not because this will library do for you.

It can init pin as normal or alternate with passing alternate function, it can deinit pin to set it as analog input, it can read pin, set pin and more.


Read more about new HAL libraries


  • Initialize pins with single function clock,
  • Initialize pins as alternate,
  • Deinitialize pin,
  • Fast set pull resistors,
  • Read GPIO pin,
  • Set GPIO pin,


  • HAL
    • GPIO
  • TM
    • STM32Fxxx HAL
    • defines.h

Functions and enumerations


For this library is example not shown because GPIO lib is used everywhere. In future libs you will be able to see example of using this library.

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!
  • Pingback: All STM32 HAL libraries - STM32F4 Discovery()

  • naveenkumar mutthu


    when i compile using GPIO im getting error. i modified #include “stm32fxxx_hal.h” to #include “stm32f1xx_hal.h” to match my controller. and with cubemx i have modified all pins to GPIO out. and renamed pins as “GPIO_PIN_13” etc etc.

    error : #136: struct “” has no field “MODER”
    GPIOx->MODER = (GPIOx->MODER & ~(0x03 << (2 * i))) | (0x01 << (2 * i));

    error : #136: struct "” has no field “PUPDR”
    GPIOx->PUPDR = (GPIOx->PUPDR & ~(0x03 << (2 * pinpos))) | ((uint32_t)(GPIO_PuPd << (2 * pinpos)));

    error : #136: struct "” has no field “OTYPER”
    GPIOx->OTYPER = (GPIOx->OTYPER & ~(uint16_t)(0x01 << pinpos)) | ((uint16_t)(GPIO_OType << pinpos));

    error : #136: struct "” has no field “OSPEEDR”
    GPIOx->OSPEEDR = (GPIOx->OSPEEDR & ~((uint32_t)(0x03 << (2 * pinpos)))) | ((uint32_t)(GPIO_Speed << (2 * pinpos)));

    im using keil MDK 5.0
    with stm32f103 controller

    i used GPIO for working with LCD16x2 library. i have defined all pins in "define.h".
    and i dont find a solution to solve these above errors.

    can you please help me??

    thank you

    • GPIO in F1xx has different registers compared to all others. That’s why it is not supported in my lib. Use HAL or LL drivers to achieve your job.

      • naveenkumar mutthu

        just quick question.

        as you mentioned in all your libraries like it will work with only F0,F4 and F7.

        so, other devices are not supported when your library is used right?

        P.S : can you help me where i can get readymade libraries who can drive LCD, GSM etc pheripherals with all devices compatable?

        Please confirm

        thank you

        • Most libraries are available on ST (STM32Cube package), for GSM I have my own available on my Github.

          • naveenkumar mutthu

            Thank you for your feedback.

            i will check in Github and also in stm32 cubemx