Skip to main content
Filipx.87
Associate II
October 31, 2019
Question

Automatic choice of a header by a used STM.

  • October 31, 2019
  • 2 replies
  • 740 views

Hi! I have the own include file which contains more the same HAL libraries headers with a different types of controllers. Could it be some possible (with Directive and Contitions?) for a compiler to choose itself according to the used controller in Project? Thanx.

I always have to choose manually...

// #include "stm32l1xx_hal.h"

#include "stm32f1xx_hal.h"

//#include "stm32f4xx_hal.h"

// #include "stm32f7xx_hal.h"

This topic has been closed for replies.

2 replies

Tesla DeLorean
Guru
October 31, 2019

Doesn't the compiler command line, by way of the project meta-data, get a definition passed of the platform/cpu being used?

ie STM32L432xx

And things like

#if defined (STM32L412xx) || defined (STM32L422xx) || defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx) || defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)

/* The temperature sensor measurement path (channel 17) is available on ADC1 */

#define ADC_TEMPERATURE_SENSOR_INSTANCE(__HANDLE__) (((__HANDLE__)->Instance) == ADC1)

#elif defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || defined (STM32L4A6xx)  

/* The temperature sensor measurement path (channel 17) is available on ADC1 and ADC3 */

#define ADC_TEMPERATURE_SENSOR_INSTANCE(__HANDLE__) ((((__HANDLE__)->Instance) == ADC1) || (((__HANDLE__)->Instance) == ADC3))

#endif

OR

#if defined(STM32L1) || defined(STM32L4) || defined(STM32G0) || defined(STM32L5)

#define HAL_DAC_MSP_INIT_CB_ID    HAL_DAC_MSPINIT_CB_ID

#define HAL_DAC_MSP_DEINIT_CB_ID   HAL_DAC_MSPDEINIT_CB_ID

#endif

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Piranha
Principal III
October 31, 2019

STM32 headers are meant to be used like this:

#define STM32F767xx
#define USE_HAL_DRIVER
#include "stm32f7xx.h"

Or you can put those defines in a project configuration.

But, if you're building a single project for multiple boards, you should have some BSP layer. Then you can put MCU specific defines and includes in BSP files.