Skip to main content
Visitor II
March 24, 2024
Question

How to Include HAL Libraries into Already Existing Project

  • March 24, 2024
  • 3 replies
  • 4799 views

Hello,

I am using an STM32F407G-DISC1 to run an open source program called Picovoice. More specifically their project at the following link (https://github.com/Picovoice/picovoice/tree/master/demo/mcu/stm32f407/stm32f407g-disc1). Unfortunately they do not have an .ioc file in the project for me to enable and generate code for the UART HAL libraries. Does anyone know how I could potentially add those libraries to the already existing project?

 

I am planning to use UART4 on pins PA0 and PA1 if that helps at all. Any info would be appreciated.

Thanks!

    This topic has been closed for replies.

    3 replies

    Technical Moderator
    March 24, 2024

    Hello @GSkoumal and welcome to the ST Community :smiling_face_with_smiling_eyes:.

    What i suggest you is to create a new project wher you configure the USART interface that you are going to use starting from CubeMX. Then generate your project. Take the same includs and generated codes and add them to the first projects (don't forget to add the files included on the USART project and that are not existing on the original one. Also, make sure about check that you are using the correct paths on your configurations).

    Best Regards.

    STTwo-32 

    GSkoumalAuthor
    Visitor II
    March 24, 2024

    Thanks for getting back so quick. I've done what you recommended and am close but am running into another road block. Now whenever I build the function HAL_UART_Init() is being flagged as undefined. I realized that for some reason the file "stm32f4xx_hal_uart.c" was not properly being included. Looking in the driver folder the file is present, but greyed out. I placed "#define HAL_UART_MODULE_ENABLED" in the 'stm32f4xx_hal_conf.h' file in the Inc folder. This should include the UART .h file, and in turn, the .c file but it doesn't appear to. Additionally if I attempt to simply place #include "stm32f4xx_hal_uart.c" at the top of main the build claims so such file exists. Any idea why this might be? 

    I've attached an image of how the HAL driver folder appears in my project manager.

    Thanks again!

     

    Super User
    March 24, 2024

     #include "stm32f4xx_hal_uart.c" at the top of main

     #include "../Src/stm32f4xx_hal_uart.c" at the *bottom* of main.c  ))

     

    GSkoumalAuthor
    Visitor II
    March 24, 2024

    Huge help that worked! But now the stm32f4xx_hal_uart.c file has an error where it says the ATOMIC_CLEAR_BIT and ATMOIC_SET_BIT functions are undefined. Sorry this is a confusing one for me!

    Super User
    March 25, 2024

    ATOMIC_SET_BIT, ATOMIC_CLEAR_BIT are defined in Drivers/CMSIS/Include/stm32f4xx.h

    If this is undefined, you may be using outdated version of CubeF4 package or weird mix of versions => not going to work. Please check that you have at least a certain consistent version of the F4 HAL & CMSIS library.

     

     

    GSkoumalAuthor
    Visitor II
    March 26, 2024

    How can I check to see what version of those libraries I have? The github project in my first post has the drivers I need to match. Once I know where could I find the outdated versions of the uart library to include? 

    Thanks again for all of your help I am at a complete loss with this.

    Super User
    March 26, 2024

    How can I check to see what version of those libraries I have? 

    This is a good question, unfortunately hard to do. The library version is in a xml file in the "repository". But by default CubeMX/ide copies the library files into user's project without this file so the version information is lost.