cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeIDE device type variable availability

NW27
Associate III

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.

1 ACCEPTED SOLUTION

Accepted Solutions
prain
Senior III

In cubeIDE there is a symbol defined in compiler settings:

0693W000003C4S5QAK.jpg

View solution in original post

5 REPLIES 5
TDK
Guru

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
Senior III

In cubeIDE there is a symbol defined in compiler settings:

0693W000003C4S5QAK.jpg

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.
Evangelist III

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
Associate III

Thanks All.