Skip to main content
NW27
Associate II
August 3, 2020
Solved

STM32CubeIDE device type variable availability

  • August 3, 2020
  • 4 replies
  • 3084 views

Hi,

I'm writing some generic utilities for use across multiple projects and processor types.

Quite often I have to include the device header file in the utility header, e.g.

//#include "stm32f1xx_hal.h"

//#include "stm32l4xx_hal.h"

#include "stm32f7xx_hal.h"

Is there a compiler variable that specifies what the processor is? Then I could do something like the below for each of the processor types.

#ifdef stm32f7xx

#include "stm32f7xx_hal.h"

#endif

#ifdef stm32f1xx

#include "stm32f1xx_hal.h"

#endif

#ifdef stm32f4xx

#include "stm32f4xx_hal.h"

#endif

Thanks.

This topic has been closed for replies.
Best answer by prain

In cubeIDE there is a symbol defined in compiler settings:

0693W000003C4S5QAK.jpg

4 replies

TDK
Super User
August 4, 2020

There is a per-chip define. Look at the top of the "stm32f4xx.h" and similar files. For the F4, it's one of these:

/* Uncomment the line below according to the target STM32 device used in your
 application 
 */
#if !defined (STM32F405xx) && !defined (STM32F415xx) && !defined (STM32F407xx) && !defined (STM32F417xx) && \
 !defined (STM32F427xx) && !defined (STM32F437xx) && !defined (STM32F429xx) && !defined (STM32F439xx) && \
 !defined (STM32F401xC) && !defined (STM32F401xE) && !defined (STM32F410Tx) && !defined (STM32F410Cx) && \
 !defined (STM32F410Rx) && !defined (STM32F411xE) && !defined (STM32F446xx) && !defined (STM32F469xx) && \
 !defined (STM32F479xx) && !defined (STM32F412Cx) && !defined (STM32F412Rx) && !defined (STM32F412Vx) && \
 !defined (STM32F412Zx) && !defined (STM32F413xx) && !defined (STM32F423xx)

There is a per-family define "STM32F4" but it's not really used and STM32CubeMX doesn't add it. You'd have to define it yourself.

"If you feel a post has answered your question, please click ""Accept as Solution""."
prain
prainBest answer
Visitor II
August 4, 2020

In cubeIDE there is a symbol defined in compiler settings:

0693W000003C4S5QAK.jpg

S.Ma
Principal
August 4, 2020

very true, all compilers have compile options and label names. only drawback is syntax is compiler dependent and not part of source code. a global include file is another way.

Pavel A.
Super User
August 4, 2020

Keil has also a symbol CMSIS_device_header which expands to name of a "standard" CMSIS device header. For example

#define CMSIS_device_header "stm32f0xx.h"

They put this in RTE_Components.h

So you do this:

#include "RTE_Components.h"

#include CMSIS_device_header

-- pa

NW27
NW27Author
Associate II
August 17, 2020

Thanks All.