I am developing an embedded project (on STM32). I currently use GCC 4.9.2, but I would like to switch to newer version of my toolchain. Unfortunately my code which succesfully compiles on gcc 4.9.2, throws reinpreted_cast errors on version 6.2.0 or 7.2.0 and I have no idea why. It looks like that newer gcc sees some problems when casting int to pointer and back to int - which I think should be quite normal operation.
Error message thrown:
1>STM32L4\CMSIS\stm32l4a6xx.h(1567,30): error : 'reinterpret_cast<ADC_TypeDef*>(1342439424)' is not a constant expression
1> #define ADC1 ((ADC_TypeDef *) ADC1_BASE)
1> ^
1> Sources\CAdc.cpp(31,35): note: in expansion of macro 'ADC1'
1> case reinterpret_cast<uint32_t>ADC1: u32DMAChannel = LL_DMA_CHANNEL_1; break;
Here is part of my code which error refers to:
switch ((uint32_t)adc)
{
case (uint32_t)ADC1: u32DMAChannel = LL_DMA_CHANNEL_1; break;
case (uint32_t)ADC2: u32DMAChannel = LL_DMA_CHANNEL_2; break;
case (uint32_t)ADC3: u32DMAChannel = LL_DMA_CHANNEL_3; break;
}
And adc
declaration:
private:
ADC_TypeDef *adc;
Here are all macros definitions:
#define PERIPH_BASE (0x40000000UL) /*!< Peripheral base address */
#define AHB2PERIPH_BASE (PERIPH_BASE + 0x08000000UL)
#define ADC1_BASE (AHB2PERIPH_BASE + 0x08040000UL)
#define ADC1 ((ADC_TypeDef *) ADC1_BASE)
So for compiler, my in-switch cast looks like this:
(uint32_t)((ADC_TypeDef *) (((0x40000000UL)+ 0x08000000UL)+ 0x08040000UL))
Simple cast of unsigned long
to some struct pointer and back to unsigned long
. What is wrong with it?
Whould should I do to get rid of this error? Any macro edition is impossible for me because these are BSP libraries.