cancel
Showing results for 
Search instead for 
Did you mean: 

Recommended way to create project with HAL drivers without using code generation in STM32CubeIDE?

HaLed
Associate II

I am trying to create a project that takes advantage of the HAL drivers, but does not include auto generated code. It would be ideal to be able to tell the IDE which HAL drivers to include and start off from there. Unfortunately, I could not find such option. As an alternative approach, I saw cloning the respective MCU firmware package (in my case the STM32CubeWB) and copying the Drivers and Middlewares folders into the project. Unfortunately, this lead to an infinite chain of having to delete certain files and folders and updating include and source paths. I am wondering what would be the recommended strategy to work with the HAL libraries when I do not want to end up with auto generated code.

Many thanks in advance!

1 REPLY 1
Pavel A.
Evangelist III

Just throw the generated code away and bring yours own?

> It would be ideal to be able to tell the IDE which HAL drivers to include

For this we've invented a dirty hooliganish hack.

C language purists and MISRA addicts, please look away.

Below is example for STM32F7, it works also for H7 and some others.

// @file stm32F7_hal_drivers_pack.c
// ST HAL drivers needed for <project X>
// -I ${STM32f7xx_HAL_Driver}/Inc
 
#ifndef USE_HAL_DRIVER
#define USE_HAL_DRIVER
#endif
 
#include <stm32f7xx_hal.h>
 
//>>> Here you can check and redefine things from  stm32f7xx_hal_conf.h
#if (HSE_VALUE != 25000000U)
#error the board has HSE 25 MHz !
#endif
 
#include <../Src/stm32f7xx_hal.c>
#include <../Src/stm32f7xx_hal_cortex.c>
#include <../Src/stm32f7xx_hal_rcc.c>
#include <../Src/stm32f7xx_hal_rcc_ex.c>
#include <../Src/stm32f7xx_hal_gpio.c>
#include <../Src/stm32f7xx_hal_dma.c>
#include <../Src/stm32f7xx_hal_flash.c>
#include <../Src/stm32f7xx_hal_i2c.c>
#include <../Src/stm32f7xx_hal_i2c_ex.c>
#include <../Src/stm32f7xx_hal_pwr.c>
#include <../Src/stm32f7xx_hal_pwr_ex.c>
#include <../Src/stm32f7xx_hal_spi.c>
#include <../Src/stm32f7xx_hal_uart.c>
#include <../Src/stm32f7xx_hal_tim.c>
#include <../Src/stm32f7xx_hal_tim_ex.c>
#include <../Src/stm32f7xx_hal_qspi.c>
#include <../src/stm32f7xx_ll_fmc.c>
// ......... add more as needed

In short, you enable all the needed HAL modules in your stm32??xx_hal_conf.h as usual.

Then create a small .c file and include from it the needed HAL .c files.

To add or remove HAL modules, simply edit this file.

This works because the HAL Inc directory usually is in the list of include directories so ../Src/... contains the HAL .c files.

Use on your own risk.