All STM32 HAL libraries

In this section, I will write all libraries based on HAL drivers from ST.

If you see this first time, make sure you read this post first about how structure of my libs looks like!


All my softwares are published under MIT license. This means that you are allow to modify, share and use my source and other stuff in personal or commercial use. If you modify source code, it has to stay under GNU GPL v3 license too. I reserve a right to shut down this website at any time.

If you want, you can make a donation to my Paypal account and support my work in future. Paypal link is below.



All examples for Keil uVision can be downloaded from my Github repository.

Libraries API

I’ve added doxygen documentation on my site for HAL based libraries. It is available on this link where you can find descriptions for used functions in my libraires.

All libraries

Libraries listed below are currently tested on F7 and F4 series and works OK. If you find any bug, please report it to me.

I’m not responsible for any damage you will do using my libraries. You at your own risk!

RCC For setting up clock control for your board, supporting internal or external clock, support for enabling I and D cache for F7 series.
GPIO For controlling GPIO pins.
DELAY For delay functions using Systick and DWT counter
EXTI For external interrupts in GPIO pins
DISCO For leds and buttons on STM32Fxxx boards
ONEWIRE For onewire based devices like DS18B20
DS18B20 For controlling/reading DS18B20 temperature sensor
USART For communication with UART protocol
SPI For SPI communication
GENERAL General library for different stuff
CRC CRC calculation unit
SDRAM Fir SDRAN communication on F429-Disco, F439-Eval and F7-Disco boards
LCD Single library for F7-Disco, F439-Eval and F429-Disco LCD boards using LTDC and DMA2D
BUTTON For controlling multiple buttons
FFT For FFT calculations
HD44780 For LCD display
I2C For I2C communication
IWDG For independent watchdog timer
RNG For true random number generator
CPU LOAD For measuring CPU load using sleep mode and DWT counter
FATFS For interfacing SDCARD with SDIO/SDMMC or SPI communication interface
USB USB Host and Device library
BOR For setting brown-out detection levels
TOUCH For controlling touch on F7-Disco and F439-Eval boards
RTC For internal Real-Time-Clock timer
NRF24L01+ For 2.4GHz NRF24L01+ transceiver
PVD Power voltage detector for STM32Fxxx
IDENTIFICATION Detect used STM32Fxxx device where program is running
DAC Output analog voltage
ADC Read analog voltage
MPU6050 Operate with MPU6050 accelerometer and gyroscope
DMA Operate with MPU6050 accelerometer and gyroscope
USART DMA Operate with MPU6050 accelerometer and gyroscope
SPI DMA Operate with MPU6050 accelerometer and gyroscope
DSP FILTERS For DSP signal processing
GPS For reading GPS module
AHRS IMU For calculating roll, pitch and yaw values from motion sensor
STRING For creating strings
ROTARY ENCODER For controlling up to 16 rotary encoders using external interrupts
AM2301 For temperature and humidity sensor (DHT-21)
SSD1306 For controlling SSD1306 LCD driver via I2C

Download libraries

Download is available in a single pack for all libraries. There will be no single downloads.

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!
  • John Doe

    Hi, WHat is the difference between this download link for your hal libraries and what is on github, which is a much bigger archive? Am I misunderstanding something?

    • Here are only my lib files. On github are also examples.

  • Артем Тихонович

    Hi! Thank you very much! Excelent work! Do you have some plans to make libs for STM32F1 series? Or may be it works in current variant? I will test it with 32f1.

    • No, I don’t have that in mind. I don’t see an option when F1 should be used.

      • LB IN HB

        The stm32f107 is interesting as a less expensive option with Ethernet. On mouser here in the US, it is about $4 cheaper than the stm32f407.

        • Only for that, I’m not ready to do libs availability for old series F1.

  • Murtaz Naqvi

    Hi! Thanks you very much! These are very useful! Dude i have a problem i am making an E-reader using stm32f4 for which i am using a 256mb sdram. I am confused about DMA or FMC can you help me out which one to use regarding to my project.

    • Hello,

      for start, you definitelly need FMC for SDRAM controlling. After that, you can use DMA for memory to memory conversion (reading/writing process).
      Remember, only DMA2 can do memory to memory conversion.

      • Murtaz Naqvi

        Thanks you very much! I really appreciate it.

  • fmc159

    Hello, I wonder if you could advise someone very new to the STM32 family! I have happily compiled and flashed some of your examples, but others (eg. no. 9 the GPIO example) won’t build in KEIL as they go over the free version size limit. I don’t suppose there is anything I can do to reduce project size? I am just surprised that such simple examples would require so much space, but I am guessing it’s the cost of choosing the larger HAL library.

    • Hi,

      Try to remove all libs fron project which are not needed and try again.
      Another option is to use free gcc compiler.

      • fmc159

        Yes, I think I’ll look to move to Coocox and GCC. Huge thanks for the quick reply!

  • Rafael Dias

    I’m studying the Standard Peripheral Library and the HAL from STMicroelectronics. These are good libraries but, sometimes, a little confusing about how to use the functionalities.
    I found your project and I liked it a lot.

    My question is about the motivation of write your own Hardware Abstraction Layer. I think that the main motivation maybe is because there are some bugs in the StdPeripheral Library (like a bug that I founded in the USART library), but I would to know what do you think about the ST libraries.

    Not to mention that implementing your own library, you can learn a lot about the SMT32F architecture.

    • Hi, creating own hal drivers is great idea, but there is a lot of mcus and you wont use always the same one for which you have drivers.

      Let me know which bug you have found in usart lib for std periph.

      • Rafael Dias

        I found two bugs: one was related to the Baud Rate configuration. In the 1.0.0 version of the STD Peripheral Library from STMicroelectronics I was putting a invalid value on the baud rate generator register. I identified this problem when I did a test project to write something on the serial port. I created the project with the keil IDE, put the STD Peripheral library and wrote the source code. After removing of all the errors and warnings, by measuring the output baudrate I had a value totally different from the configured value. After a day reading the source code from STD Library and looking at the datasheet I found the error.
        The another problem that I had was related to the creation of two instances of USART interface. In the same project of the previous item, when I created the second instance (each instance of a different USART link, i.e, COM1 and COM2), the hardware issued a Fault exception. In the same time I had to change the microcontroller family from STM32 to a TivaWare from Texas Instruments. This was a management decision for questions of cost and team expertise.

        So, because the changing os microcontroller family I could not fix this last problem.

        Nowadays I’ll work again with the STM32F4 family and the question that started this is because I will not be happy if I start to use the std peripheral library and have problems with code errors

        • Ouuh, don’t worry. You used that then about 2 or 3 years ago?
          Now is version 1.5.1 out for these drivers and there is no bug.

          HAL drivers are buggy. I don’t like them, but if I want to be “in time” with ST and their software, I have to use them. I hope they will make stable versions soon. Now is about 1.5 year of HAL drivers for F4 series and there is still no fully stable version out.

          But for F7 lines and L4 new lines, there is no std drivers so I have to use HAL.

  • apastdei

    Hello my friend! This is an amazing effort and resource. Could you please advise on setting up a coocox project using your HAL libraries? I think I have problem with my compiler defines. All my thanks!

    • Hello,

      please send me your entire project you have for now to my email which can be found on my site, and I will take a look at your project.

      • apastdei

        For now I am just trying to run one of your HAL KEIL examples in Coocox, that’s all I need advice on. thanks!

        • Ok, but:
          1. I have to download coocox again,
          2. Which board you are using for testing so I can make project template for you.
          3. I hope I will do it today.

          • apastdei

            I am using STM32F429 Discovery. I have just come back to STM programming after some break, I used to work with standard periph libraries, but want to start with HAL/your libraries.

            You are amazing, I will be always grateful!

          • apastdei

            Hello again my friend, I have made simple button interrupt in Coocox to turn on onboard LEDs (just using HAL drivers, NOT your libraries), but it is not working. I can blink LEDs using HAL Write or Toggle functions, but cannot get button to toggle LED using interrupt. If I send project can you take a look? I know it must be something simple..

          • Do it.

          • apastdei


  • Mohammad Kamel

    i searched a lot on internet to find hal library how can i get them
    thanks for your help

  • Hello Majerle, first of all, this hal library that you prepared is another level compared to your previous amazing stdperiph library which I spent a lot of time playing with it. Best thing that I see in hal library is that we can combine different stm32 processors in one keil project without dealing with changing our codes every time for every processor. I can build same project for stm32f030 and stm32f405 (I use most of the time in my projects) at the same time. This change made me save a lot of time of migrating from one processor to another. Your libraries helped me shortening my code and made my code more readable. Another leveling up is that you put all of your work to github.

    Thank you very much to your great effort for spending time on this libraries.

    However, where is “tm_stm32_adc.h” and “tm_stm32_adc.h”. 😀 Do you plan migrating adc library from stdperiph to hal ? If you don’t do it soon, please inform me then i will try 😀

    • You are right. Libs are only done to speed up development process by not initializing everything from start always.

      ADC lib will be done, but right now I just don’t find free time to do it. 🙂

  • mukhe

    Hey MJ,
    Just letting you know that your I2C and USART for HAL libraries are very good. Thrown everything at it but still working without issues.

    I do wonder if you will ever have a DCMI library though. Just being greedy though.
    Anyways, thanks for all the libraries!

  • Георгий

    Please, give me the default project with HAL libraries. Thank you.

  • Jeremy Vance

    Could I suggest another library or perhaps you have already dabbled in this? Have you tried to emulate EEPROM writing to the user configurable flash on the chip? It would be great to save small bits of data without a backup battery or external EEPROM or SD card.

    • You must reserve one sector for eeprom data (I suggest second sector). First sector for bootloader program and third an more for yoir program.

      To write data, read sector, change value, erase sector and write data.

      • Jeremy Vance

        Do you have any code that shows this as an example? I’ve been searching the internet for HAL based examples but I can’t find anything complete or working. A lot of unanswered questions on the ST forums.

        • Not for HAL. Search for examples for flash how to program it and erase. Thats all you need.

  • JL

    Hello. Thanks for your libraries, I have been using the STD versions quite a bit.
    I tried using the HAL NRF transmit (no IRQ) example and it doesn’t compile for me, there are errors.

    .TargetsSTM32F4_DISCOVERYproject.axf: Error: L6218E: Undefined symbol TM_NRF24L01_Read_Interrupts (referred from main.o).

    ..0-STM32_LIBRARIEStm_stm32_disco.c(89): warning: #61-D: integer operation result is out of range

    I fixed those and the code compiles and runs but gets stuck on SPI_WAIT when run the code on my discovery with the NRF on the default SPI pins.

    The exact same setup works fine with the STD version of the example, no problems. Am I missing something?

    • This function exists in library.
      So I have no idea what is going wrong here.

      I checked again and also on github under hal drivers.

      • JL

        Here is my build log after downloading the example code from github and compiling without changes:

        • I see, I forgot to set to void or return something from it. Will fix that.

      • JL

        It is complaining about this function in tm_stm32_nrf24l01.c

      • JL

        I tried fixing it by replacing all occurences of “NRF24L01_CLEAR_INTTERRUPTS” with


        This allowed it to compile but I am not sure if it is correct

      • JL

        Please disregard my original comment above, you are right, that function exists

      • divum

        Hi Tilen,

        Partial display update library is available in HAL Libraries?

  • Guiem

    Hi Majerle,

    First of all fantastic work with your libraries, they are very useful!

    I’ve seen that you haven’t done the HAL PWM library. Are you planning to do it? I’m interested in this library and if you’re not going to do it soon I’m going to do it by my self.

    Thank You.

    • Making pwm lib is not necessary with hal since it is very easy to do it.

  • macgeorge

    Hello and thank you for all the libraries!
    Do you intend to port your ethernet library for HAL (STM32F7 Disco)? Thanks!

  • Artur Rybus

    I have pretty complicated problem with your library. I am trying to make my hd 44780 working but nothing works. I defined what i should and it seems to compiling without any problems. I started to checking your libraries with files generated by stm32CubeMX. After this i noticed first problem. Your delay library works perfect only in debugger mode. That means it doesn’t work after uploading program to microcontroler. Do you know what can be reason of my problem? I work on STM32F411RETx
    Greetings from Poland.

    • Library works ok always. Check your pll settings.

      • Artur Rybus

        I know what i did wrong. I have forgotten to init libraries in main . Thanks for great libraries

  • yosa

    I am using STM32F407 Discovery board with AC6 systemworkbench. I tried to copy only the GPIO and DISCO libraries and integrating with my project.
    I am not able to find the stm32f4xx.h stm32f4xx_hal.h files which are defined in stm32f4xxx.h. Please help.

    • You must read about my HAL drivers. File stm32fxxx_hal.h is also included in package of libraries you downloaded from this site. stm32f4xx.h file is file from Cube package you get with HAL drivers.

      • yosa

        Thank you for your prompt reply!
        where do we get the cube package?

        • Google for more info.
          It can be downloaded from

          • yosa

            Able to download only PDF from check with other sites. Thanks for your help!

          • Stm32cubef4

  • Elkin

    Hi Tilen, I’m stating with an STM32F401 Discovery board I just bought. I want to learn to program it using HALs. Somewhere in your site you mention that STM’s HAL libraries are not good. What is wrong with them? Why you made new libraries since STM already released theirs? It’s confusing for me.

    • I have wrappers built on hal because f7 series does not have other than HAL.

      HAL has some problems and still does not work properly.

  • david

    how can I include this library in current project in Keil uVision created using CubeMX?

    I have created new map in project and import all your files into this map bit I got many of errors after I tried to compile project: “browse information of one or more files is not available”

    • I made those libs to not to use cubemx 😉 but anyway you can use it. Add files to project. From that error I cant help you much.

      • david

        What’s about define.h file, cant find it because uvision said that can’t find this file, although it including in onewire.h file

        • Actually reading this post gives you this:
          “If you see this first time, make sure you read this post first about how structure of my libs looks like!”