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!”

  • Mare

    Can I use part of your code in my project, which will be under “unlicense” ( ) ? I will keep the reference to your site.

  • otijus

    Hi Tilen,
    First, I would like to congratulate you for the excellent jobs of making the whole confusing aspects of STM32Fxxx work greatly. You are genius, really.
    Secondly, I am a true beginner in the world of microcontroller / STM32Fxxx and have been in the learning process to work with it. This is the information about my equipment : STM32F429I-DISC1 & Keil uVision 5 Lite Edition; Windows 7 64-bits.
    And here is my question regarding I2C program :
    1. I followed your instructions by downloading your libraries and worked with Keil IDE.
    2. I built and loaded your STMFxxx_EXTI software with my new installation : everything worked okay.
    3. I then built and loaded your STMFxxx_I2C with MPU-6050 of Sparkfun. So, my purpose is to learn how the I2C protocole work, since this is a new subject for me. As a result, no errors shown once I have loaded the program. However, the RED and GREEN leds are toggling / blinking once the program runs. And as I understand from your comment, this means that there is something wrong with my actions. Everything should be the same as your equipment and setups; except that there are 2 external pull-up resistors on the MPU-6050 board.
    So, could I ask you to help debugging this problem ?
    I thank you in advance and enjoy your evening.

    • From my perspective right now it is hard to detemine what the actual problem is.
      Can you give me a link from example you tested and didn’t work?

      But probably you have some problems with:
      1. Wiring
      2. Power supply for device or device actually doesn’t work.

      • otijus

        Thank you for your quick reply.
        This is the link :
        As for the wiring :
        1. VCC 3V : pins 3V of STM32F429
        2. SCL : pin PA8
        3 .SDA : pin PC9
        4. GND 0V : pin GND of STM32F429
        Before writing you the answer, I re-did the complete build and debug process again, and the result is the same. Meaning : both GREEN and RED leds are blinking. As for further info, I do right-clic on the “&read” variable to activate the watch option. It shows “0” during the run process.
        Please feel free to say if you would need further info.
        Thank you,

        • How is the A0 pin on MPU device set? With this pin, you can set I2C address.
          If after setting this pin high or low (both tests), you can run I2C scan loop to check if any device is recognized on I2C bus.

          • otijus

            Before using the MPU-6050 of Sparkfun, I checked using the multimeter that the A0 of the address byte is soldered to 0V or GND. So, A0 is always “0”.
            How should I do to check that the MPU device is recognized on I2C bus ?

          • On link below is and example for Standard Peripheral Library for my I2C lib.
            Using HAL lib, it is the same in main, so check the for loop to do the scanning.
            Also, check what TM_I2C_isDeviceConnected returns to properly detect if it is detected.


          • otijus

            Great, I will do this.
            It will probably take me some times to do so. So, I will report the result as soon as I can.
            In the meantime, here is the info about the MPU device :

          • otijus

            So I have downloaded your STD libraries, picked up the STM32F429_I2C_SEARCH_DEVICES program and build it with Keil uVision 5. I have got this error message : .TargetsSTM32F429_Discoveryproject.axf: Error: L6218E: Undefined symbol TM_DMA2DGRAPHIC_CopyBuffer (referred from tm_stm32f4_ili9341_ltdc.o).
            Any tips on how to fix it ?
            Also, do you think that the program size is less than 32K (I am using Keil Lite free version) ?

          • otijus

            Further info :
            I added the files “tm_stm32f4_dma2d_graphic.c” and “…h” to TM folder. Also the files “stm32f4xx_dma2d.c” and “…h” to STD_Periph_Drivers folder. Then I built and debugged the program : it works properly.
            Here is the info : the display shows “Device: 82” and the function TM_I2C_IsDeviceConnected() gives “0x08002472”.
            Do you have any tips / procedures on how to proceed further to fix my problem ? And thank you in advance for your useful help.

          • 0x82 is address of touch controller connected to PA8 PC9 pins as you mentioned you have setup in F429-Discovery board. So this means your device is not responsible for some reason.

          • otijus

            If the device is correctly connected and recognized by the bus, the remaining question is that : did I do some mistakes in manipulating your program example for I2C ? Or do I miss some steps in doing so ?

          • If scanner has found one device, then this means that it works (scanner code works). So it is problem with your hardware (MPU..)

          • otijus

            Thank you for your reply.
            This hardware problem really does not help in my learning process. The MPU-6050 is brand new and I really took care when I soldered the connector. Which MPU board have you been using in your example ?
            I think that I will order the MPU boards and redo the whole process again. And I will let you know how it goes.
            Cheers and enjoy your weekend, 🙂

  • otijus

    Hey Tilen,
    Hopefully that you have been doing okay.
    Feedback : so I have received the MPU-6050 from Olimex and have tested the sensor using your HAL I2C libraries. Great results : your job has been fantastic, and I thank you for this. This phase has enabled me to understand better the protocole.
    Present issue : I will need to implement the I2C protocle using a Honeywell HIH8120 sensor. Link :
    And I need your expertise to answer the following questions :
    1. Can I modify and tailor the function HAL_I2C_Master_Transmit() to correspond to the Measurement Request of the sensor (page 1, figure 2 of the datasheet) ?
    2. Can I use your function TM_I2C_ReadMultiNoRegister() to fetch and to read the datas from the sensor (page 2, figure 4 of the datasheet) ?
    Any advice would be greatly appreciated. 🙂
    Thank you in advance,

  • Matt

    Hi Tilen,

    I’m hoping you can help me with a question regarding the STM32F4 HAL driver callbacks.

    I am developing for an STM32F4. I’m using STM32CubeMX and System Workbench for STM32. I’m using FreeRTOS. I would like to know how I should, and should not, be using the STM32F4 HAL Driver callbacks.

    As an example, I’m using HAL_CAN_RxCpltCallback. Within this call back, I decode and validate the CAN frame, and then generate a number of different events (i.e. using xQueueSendFromISR). Or in some cases, I populate a CAN frame in response, and send it within the callback. Currently I have 300 lines of code in this specific callback.

    Ideally, I would make the callback easier to read, by calling out to additional functions; i.e. if the CAN frame/message is a request for date, then call handleRequestForData(), and so on.

    However, I can see that HAL_CAN_RxCpltCallback is called from HAL_CAN_IRQHandler. So I take it that HAL_CAN_RxCpltCallback is also an IRQ. And its my understanding that I should keep all IRQ’s short, and not to call out to other functions (due to stack size limitations).

    So my question is, should I minimize the amount of code in my callbacks. And in this case, simply push the CAN frame into another queue for another task to handle it?


    • Absolutelly try to maoe your isr as short as possible. If you just copy 20bytes, this is probably not a problem, but if you filter data for example, then do not use irq for that.

  • Алексей Kiss

    Dear Sir! Do you can to show us, what you will be do in future. So also I want ask you, do you can to make tutorial, how read datasheet and write one program from (I2C or SPI).
    Thank you, you make great work!

  • Shail

    Hi all,
    we are facing problem in RNDIS USB Class implementation for STM32 Nucleo 144pin. We have reference code but still not able to use USB OTG Library for RNIDS Class. Kindly explain function flow and necessary files required for that.
    Thanks and Regards,
    Shail Shah.

  • frank

    Hi, I am trying to compile your hal libs. Got the error below. Scan of all files does not show any definition of I2C_CR2_TXDMAEN. Any suggestions? Thanks.

    ‘I2C_CR2_TXDMAEN’ undeclared (first use in this function) tm_stm32_i2c_dma.c

  • frank

    Please see . Trying to compile HAL libs with including Fatfs, and cannot figure out duplicate symbol error. Any suggestions?

  • John Doe

    Hello. What version of HAL drivers does your library support?

    • In general with latest version should work.

      • John Doe

        Nope. the HAL files you have on github seem to be old – 2015. In stm32f4xx_hal_sd.h -HAL_SD_TransferStateTypedef exists. In newer HAL version, that is no longer there. Looks like it exists in version 1.12 and earlier.

        • There were changes in BSP for SD card. I’ve updated the HAL and SDcard BSP package but I didn’t tested now for all projects. SD card read/write worked after modification.

          • John Doe

            Cool ! thanks

      • saeedbzrgn

        how to use the your HAL_library in keil?

        • Every example with lib has Keil example.

          • Achour

            Hi Majerle Tilen ;

            Sorry for bothering you, but I nedd help.

            I’m actually working on a project called: Temperature monitoring. To do so, i’m using the stm32F070RBT as MCU, and the 1-wire ds18b20 temperature sensor.

            I’ve recently read your libraries to make it work, but this requires lot of changes within the code.

            Then I’ve read to d18b20 datasheet and understood how it works.

            1) Firstly, i’ve initiated my project using the CubeMx (HAL libraries) that generates the initial code.

            2) Then, i’ve created APIs (by respecting the timing) eventually to Reset, Read/Write on the 1-wire bus.

            -The reset function wors properly, i.e, i’ve received the presence pulse from the slave. By the wa the write APIs wors as well since i’ve visualised the signals on the oscilloscope.

            The problem that I got, is the fact that I alwayes read ones on the bus (0xffffffffffffffff) for scratchpad using the 0x33 command.

            Here is my APIs.c code:

            #include “stm32f0xx_hal.h”
            #include “cmsis_os.h”
            #include “stm32f0xx_hal_tim.h”
            #include “stm32f0xx_hal_gpio.h”
            #include “MyAPIs.h”
            // DELAY – with an 11.059MHz crystal.
            // Calling the routine takes about 24us, and then
            // each count takes another 16us.
            void delay(uint32_t us)
            // uint32_t CounTimer;
            //for (uint32_t s=0; s Pin = GPIO_Pin;
            //structure -> Mode = GPIO_MODE_OUTPUT_PP;
            //HAL_GPIO_Init(GPIOx, structure);
            ONEWIRE_OUTPUT(GPIOx, GPIO_Pin);

            /*set bus low*/
            HAL_GPIO_WritePin(GPIOx, GPIO_Pin, GPIO_PIN_RESET); // Drive bus low
            /*display bus*/
            //ReadBit = HAL_GPIO_ReadPin(GPIOx, GPIO_Pin);
            //printf(“ReadBit = 0x%2xhn”, ReadBit);
            //osDelay(1); // hold for 480us
            delay(900);//805 in the beginnig, but the delay has changed ???

            /*set back the bus to high*/
            // HAL_GPIO_WritePin(GPIOx, GPIO_Pin, GPIO_PIN_SET); // Drive bus low

            //delay(100); //wait (60us) for slave to pull bus low

            /*master goes into input mode to read presence from slave*/
            //structure -> Pin = GPIO_Pin;
            //structure -> Mode = GPIO_MODE_INPUT;
            //HAL_GPIO_Init(GPIOx, structure);
            ONEWIRE_INPUT(GPIOx, GPIO_Pin);
            device_present = HAL_GPIO_ReadPin(GPIOx, GPIO_Pin);
            delay(480); //wait for 250us to finish the period

            return device_present;

            // READ_BIT – reads a bit from the one-wire bus. The delay
            // required for a read is 15us, so the DELAY routine won’t work.
            // We put our own delay function in this routine in the form of a
            // for() loop.

            uint8_t OneWire_ReadBit(GPIO_InitTypeDef* structure, GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin) {
            uint8_t bit = 0;

            /*taking the bus. set port in ouput mode after the delay of 70us*/
            //structure -> Pin = GPIO_Pin;
            //structure -> Mode = GPIO_MODE_OUTPUT_PP;
            //HAL_GPIO_Init(GPIOx, structure);
            /* Line low */
            ONEWIRE_OUTPUT(GPIOx, GPIO_Pin);
            HAL_GPIO_WritePin(GPIOx, GPIO_Pin, GPIO_PIN_RESET);

            //ONEWIRE_OUTPUT(GPIOx, GPIO_Pin);
            delay(2);//putting low the bus for a 5us

            /* Bit high */
            //HAL_GPIO_WritePin(GPIOx, GPIO_Pin, GPIO_PIN_SET);
            //HAL_GPIO_WritePin(GPIOx, GPIO_Pin, GPIO_PIN_SET);
            /* Release line */

            /* Read line value */
            //HAL_GPIO_WritePin(GPIOx, GPIO_Pin, GPIO_PIN_SET);
            ONEWIRE_INPUT(GPIOx, GPIO_Pin);
            bit = HAL_GPIO_ReadPin(GPIOx, GPIO_Pin);

            delay(60);//waiting for 45us for data to be read by the master

            /* Return bit value */
            return bit;

            * @brief Writes single bit to onewire bus
            * @param *OneWireStruct: Pointer to @ref TM_OneWire_t working onewire structure
            * @param bit: Bit value to send, 1 or 0
            * @retval None

            void OneWire_WriteBit(GPIO_InitTypeDef* structure, GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint8_t bit) {

            //printf(“bit = 0x%2xn”, bit);
            /*TickType_t count0 = xTaskGetTickCount();
            printf(“count0 = %un”, count0);*/
            if (bit) {

            /*taking the bus. set port in ouput mode after the delay of 70us*/
            /*structure -> Pin = GPIO_Pin;
            structure -> Mode = GPIO_MODE_OUTPUT_PP;
            HAL_GPIO_Init(GPIOx, structure);*/
            // printf(“Erreur a la ligne %d du fichier %sn”, __LINE__, __FILE__);
            //printf(“Ce fichier a ete compile le %s a %sn”, __DATE__, __TIME__);

            /* Set line low */
            HAL_GPIO_WritePin(GPIOx, GPIO_Pin, GPIO_PIN_RESET);
            ONEWIRE_OUTPUT(GPIOx, GPIO_Pin);
            delay(2);//pulling bus low for 15us.

            /* Bit high */
            HAL_GPIO_WritePin(GPIOx, GPIO_Pin, GPIO_PIN_SET);
            //ONEWIRE_INPUT(GPIOx, GPIO_Pin);
            /* Wait for 45 us and release the line */

            } else {

            /*taking the bus. set port in ouput mode after the delay of 70us*/

            /* Set line low for 60us */
            // printf(“GPIO_Pin = 0x%xhn”, GPIO_Pin);
            HAL_GPIO_WritePin(GPIOx, GPIO_Pin, GPIO_PIN_RESET);
            ONEWIRE_OUTPUT(GPIOx, GPIO_Pin);


            /*drive the bus high*/
            HAL_GPIO_WritePin(GPIOx, GPIO_Pin, GPIO_PIN_SET);
            //ONEWIRE_INPUT(GPIOx, GPIO_Pin);

            //HAL_GPIO_WritePin(GPIOx, GPIO_Pin, GPIO_PIN_RESET);
            //for(uint32_t us = 20 ; us > 0 ; us–){}

            /*TickType_t count1 = xTaskGetTickCount();
            printf(“count1 = %un”, count1);*/

            * @brief Gets ROM number from device from search
            * @param *OneWireStruct: Pointer to @ref TM_OneWire_t working onewire
            * @param index: Because each device has 8-bytes long ROm address, you have to call this 8 times, to get ROM bytes from 0 to 7
            * @reetval ROM byte for index (0 to 7) at current found device

            /*uint8_t TM_OneWire_GetROM(TM_OneWire_t* OneWireStruct, uint8_t index) {
            return OneWireStruct->ROM_NO[index];

            void OneWire_WriteByte(GPIO_InitTypeDef* structure, uint8_t byte) {
            uint8_t i = 8;
            /* Write 8 bits */
            while (i–) {
            /* LSB bit is first */
            OneWire_WriteBit(structure, TempPinCom_GPIO_Port, TempPinCom_Pin, byte & 0x01);
            byte >>= 1;

            uint8_t OneWire_ReadByte(GPIO_InitTypeDef* structure) {
            uint8_t i = 8, byte = 0;
            while (i–) {
            byte >>= 1;
            byte |= (OneWire_ReadBit(structure, TempPinCom_GPIO_Port, TempPinCom_Pin) << 7);
            //printf("byte = 0x%xn", byte);
            return byte;

            //************************My Macros**************************************************//

            * @brief Set selected pin as input
            * @param *GPIO_TypeDef: GPIOx, where x can be: A….F
            * @param index: Because each device has 8-bytes long ROm address, you have to call this 8 times, to get ROM bytes from 0 to 7
            * @reetval ROM byte for index (0 to 7) at current found device
            void GPIO_SetPinAsInput(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin) {
            uint8_t i;
            /* Go through all pins */
            for (i = 0x00; i < 0x10; i++) {
            /* Pin is set */
            if (GPIO_Pin & (1 <MODER &= ~(0x03 << (2 * i));

            * @brief Set selected pin as output
            * @param *GPIO_TypeDef: GPIOx, where x can be: A….F
            * @param index: Because each device has 8-bytes long ROm address, you have to call this 8 times, to get ROM bytes from 0 to 7
            * @reetval ROM byte for index (0 to 7) at current found device
            void GPIO_SetPinAsOutput(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin) {
            uint8_t i;
            /* Go through all pins */
            for (i = 0x00; i < 0x10; i++) {
            /* Pin is set */
            if (GPIO_Pin & (1 <
            MODER = (GPIOx->MODER & ~(0x03 << (2 * i))) | (0x01 << (2 * i));

            Here is my main.c:
            * File Name : main.c
            * Description : Main program body
            * This notice applies to any and all portions of this file
            * that are not between comment pairs USER CODE BEGIN and
            * USER CODE END. Other portions of this file, whether
            * inserted by the user or by software development tools
            * are owned by their respective copyright owners.
            * Copyright (c) 2017 STMicroelectronics International N.V.
            * All rights reserved.
            * Redistribution and use in source and binary forms, with or without
            * modification, are permitted, provided that the following conditions are met:
            * 1. Redistribution of source code must retain the above copyright notice,
            * this list of conditions and the following disclaimer.
            * 2. Redistributions in binary form must reproduce the above copyright notice,
            * this list of conditions and the following disclaimer in the documentation
            * and/or other materials provided with the distribution.
            * 3. Neither the name of STMicroelectronics nor the names of other
            * contributors to this software may be used to endorse or promote products
            * derived from this software without specific written permission.
            * 4. This software, including modifications and/or derivative works of this
            * software, must execute solely and exclusively on microcontroller or
            * microprocessor devices manufactured by or for STMicroelectronics.
            * 5. Redistribution and use of this software other than as permitted under
            * this license is void and will automatically terminate your rights under
            * this license.
            /* Includes ——————————————————————*/
            #include "main.h"
            #include "stm32f0xx_hal.h"
            #include "cmsis_os.h"
            #include "MyAPIs.h"

            /* USER CODE BEGIN Includes */

            /* USER CODE END Includes */

            /* Private variables ———————————————————*/
            CRC_HandleTypeDef hcrc;

            osThreadId defaultTaskHandle;

            /* USER CODE BEGIN PV */
            /* Private variables ———————————————————*/

            /* USER CODE END PV */

            /* Private function prototypes ———————————————–*/
            void SystemClock_Config(void);
            static void MX_GPIO_Init(void);
            static void MX_CRC_Init(void);
            void StartDefaultTask(void const * argument);

            /* USER CODE BEGIN PFP */
            /* Private function prototypes ———————————————–*/

            /* USER CODE END PFP */

            /* USER CODE BEGIN 0 */

            /* USER CODE END 0 */

            int main(void)

            /* USER CODE BEGIN 1 */

            /* USER CODE END 1 */

            /* MCU Configuration———————————————————-*/

            /* Reset of all peripherals, Initializes the Flash interface and the Systick. */

            /* USER CODE BEGIN Init */

            /* USER CODE END Init */

            /* Configure the system clock */

            /* USER CODE BEGIN SysInit */

            /* USER CODE END SysInit */

            /* Initialize all configured peripherals */

            /* USER CODE BEGIN 2 */
            // HAL_TIM_Base_Start_IT(&htim3);
            /* USER CODE END 2 */

            /* USER CODE BEGIN RTOS_MUTEX */
            /* add mutexes, … */
            /* USER CODE END RTOS_MUTEX */

            /* add semaphores, … */

            /* start timers, add new ones, … */
            /* USER CODE END RTOS_TIMERS */

            /* Create the thread(s) */
            /* definition and creation of defaultTask */
            osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 128);
            defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);

            /* add threads, … */
            /* USER CODE END RTOS_THREADS */

            /* add queues, … */
            /* USER CODE END RTOS_QUEUES */

            /* Start scheduler */

            /* We should never get here as control is now taken by the scheduler */

            /* Infinite loop */
            /* USER CODE BEGIN WHILE */
            while (1)
            /* USER CODE END WHILE */

            /* USER CODE BEGIN 3 */

            /* USER CODE END 3 */


            /** System Clock Configuration
            void SystemClock_Config(void)

            RCC_OscInitTypeDef RCC_OscInitStruct;
            RCC_ClkInitTypeDef RCC_ClkInitStruct;

            /**Initializes the CPU, AHB and APB busses clocks
            RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
            RCC_OscInitStruct.HSIState = RCC_HSI_ON;
            RCC_OscInitStruct.HSICalibrationValue = 16;
            RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
            if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
            _Error_Handler(__FILE__, __LINE__);

            /**Initializes the CPU, AHB and APB busses clocks
            RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
            RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
            RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;

            if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
            _Error_Handler(__FILE__, __LINE__);

            /**Configure the Systick interrupt time

            /**Configure the Systick

            /* SysTick_IRQn interrupt configuration */
            HAL_NVIC_SetPriority(SysTick_IRQn, 3, 0);

            /* CRC init function */
            static void MX_CRC_Init(void)

            hcrc.Instance = CRC;
            hcrc.Init.DefaultPolynomialUse = DEFAULT_POLYNOMIAL_ENABLE;
            hcrc.Init.DefaultInitValueUse = DEFAULT_INIT_VALUE_ENABLE;
            hcrc.Init.InputDataInversionMode = CRC_INPUTDATA_INVERSION_NONE;
            hcrc.Init.OutputDataInversionMode = CRC_OUTPUTDATA_INVERSION_DISABLE;
            hcrc.InputDataFormat = CRC_INPUTDATA_FORMAT_BYTES;
            if (HAL_CRC_Init(&hcrc) != HAL_OK)
            _Error_Handler(__FILE__, __LINE__);


            /** Configure pins as
            * Analog
            * Input
            * Output
            * EVENT_OUT
            * EXTI
            static void MX_GPIO_Init(void)

            GPIO_InitTypeDef GPIO_InitStruct;

            /* GPIO Ports Clock Enable */

            HAL_GPIO_WritePin(TempPinCom_GPIO_Port, TempPinCom_Pin, GPIO_PIN_SET); // Drive bus low

            /*Configure GPIO pin : TempPinCom_Pin */
            GPIO_InitStruct.Pin = TempPinCom_Pin;
            GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
            GPIO_InitStruct.Pull = GPIO_PULLUP;
            HAL_GPIO_Init(TempPinCom_GPIO_Port, &GPIO_InitStruct);


            /* USER CODE BEGIN 4 */

            /* USER CODE END 4 */

            /* StartDefaultTask function */
            void StartDefaultTask(void const * argument)
            uint8_t OwPresence, get[10];
            /* USER CODE BEGIN 5 */
            /* Infinite loop */
            //start the timer's counter.
            OneWire_t GPIO_InitStructOW;
            GPIO_InitTypeDef GPIO_InitStruct1;

            OwPresence = ResetDS18B20 (&GPIO_InitStructOW, TempPinCom_GPIO_Port, TempPinCom_Pin );
            printf("OwPresence = 0x%xhn", OwPresence);

            if(!OwPresence) {
            printf("Device Detectedn");


            /*TM_OneWire_WriteBit (&GPIO_InitStruct1, TempPinCom_GPIO_Port, TempPinCom_Pin, 1);
            OneWire_WriteBit (&GPIO_InitStruct1, TempPinCom_GPIO_Port, TempPinCom_Pin, 1);
            OneWire_WriteBit (&GPIO_InitStruct1, TempPinCom_GPIO_Port, TempPinCom_Pin, 0);
            OneWire_WriteBit (&GPIO_InitStruct1, TempPinCom_GPIO_Port, TempPinCom_Pin, 0);
            OneWire_WriteBit (&GPIO_InitStruct1, TempPinCom_GPIO_Port, TempPinCom_Pin, 1);
            OneWire_WriteBit (&GPIO_InitStruct1, TempPinCom_GPIO_Port, TempPinCom_Pin, 1);
            OneWire_WriteBit (&GPIO_InitStruct1, TempPinCom_GPIO_Port, TempPinCom_Pin, 0);
            OneWire_WriteBit (&GPIO_InitStruct1, TempPinCom_GPIO_Port, TempPinCom_Pin, 0);*/

            // TM_OneWire_WriteByte(&GPIO_InitStruct1, 0xBE); // Read Scratch Pad
            OneWire_WriteByte(&GPIO_InitStruct1, 0x33); // Read Scratch Pad

            get[0] = OneWire_ReadByte(&GPIO_InitStruct1);
            printf("get[0] = 0x%xn", get[0]);
            get[1] = OneWire_ReadByte(&GPIO_InitStruct1);
            printf("get[1] = 0x%xn", get[1]);

            //TM_OneWire_WriteBit (&GPIO_InitStructOW, TempPinCom_GPIO_Port, TempPinCom_Pin, 1);
            //TM_OneWire_WriteBit (&GPIO_InitStructOW, TempPinCom_GPIO_Port, TempPinCom_Pin, 0);
            /*TM_OneWire_WriteBit (&GPIO_InitStructOW, TempPinCom_GPIO_Port, TempPinCom_Pin, 1);
            TM_OneWire_WriteBit (&GPIO_InitStructOW, TempPinCom_GPIO_Port, TempPinCom_Pin, 0);
            TM_OneWire_WriteBit (&GPIO_InitStructOW, TempPinCom_GPIO_Port, TempPinCom_Pin, 1);*/

            //TM_OneWire_WriteByte(&GPIO_InitStructOW, 0xCC); // Skip ROM

            /*for (uint8_t k=0;kInstance == TIM1) {
            /* USER CODE BEGIN Callback 1 */

            /* USER CODE END Callback 1 */

            * @brief This function is executed in case of error occurrence.
            * @param None
            * @retval None
            void _Error_Handler(char * file, int line)
            /* USER CODE BEGIN Error_Handler_Debug */
            /* User can add his own implementation to report the HAL error return state */
            /* USER CODE END Error_Handler_Debug */

            #ifdef USE_FULL_ASSERT

            * @brief Reports the name of the source file and the source line number
            * where the assert_param error has occurred.
            * @param file: pointer to the source file name
            * @param line: assert_param error line source number
            * @retval None
            void assert_failed(uint8_t* file, uint32_t line)
            /* USER CODE BEGIN 6 */
            /* User can add his own implementation to report the file name and line number,
            ex: printf(“Wrong parameters value: file %s on line %drn”, file, line) */
            /* USER CODE END 6 */



            * @}

            * @}

            /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

            PLEASE, if you got any suggesion, I’ll be pleased to get it. Thans for reading and excuse the writing because I did it quickly.

  • dava

    check this please.I receive an error code about :

    #include “defines.h”
    #include “tm_stm32f4_ili9341.h”
    #include “tm_stm32f4_stmpe811.h”

    • Võ Kiệt

      download library defines.h in this web

  • iss93

    there is no library for PWM ?

  • glad_guest

    “All my softwares are published under MIT license. If you modify source code, it has
    to stay under GNU GPL v3”
    Huh, what ???

    • This is a mistake from my copy/paste. License is MIT meaning you don’t need to keep it in MIT after modification.

  • mr_guest

    Some links point to .com site (eg. LCD: where a language translating site is located. Would be great, if this could be fixed!

  • 404 – Links not open

  • Tobias K.

    Hello Tilen. Do you have any plans to update the libs for STM32H7 ? It seems that some periphery has changed between F7 and H7. All I could find was this:

    • Difference between F7 and H7 is not negligible therefore it is hard to do efficient single lib for more architectures. This is specially true when we have to deal with DMA (system core, not only peripherals itself).