2020-08-03 04:45 PM
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.
Solved! Go to Solution.
2020-08-04 07:32 AM
2020-08-03 07:48 PM
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.
2020-08-04 07:32 AM
In cubeIDE there is a symbol defined in compiler settings:
2020-08-04 07:39 AM
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.
2020-08-04 09:24 AM
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
2020-08-17 02:46 AM
Thanks All.