cancel
Showing results for 
Search instead for 
Did you mean: 

Compiling/Linking stm32h753xx.h with errors

jcbless-ga
Visitor

I am trying to compile in stm32h753xx.h into a project.  It has a number of lines like this:

#define SPI3                ((SPI_TypeDef *) SPI3_BASE)

I am getting this error on that line:

In file included from ../src/libraries/CMSIS/Device/ST/STM32H7xx/Include/stm32h7xx.h:124,
                 from ../src/rt-arm/STM32F4/i2cComm.hh:17,
                 from ../src/rt-arm/busses/i2c.cc:12:
../src/libraries/CMSIS/Device/ST/STM32H7xx/Include/stm32h753xx.h:2510:30: error: 'reinterpret_cast<SPI_TypeDef*>(1073757184)' is not a constant expression
 2510 | #define SPI3                ((SPI_TypeDef *) SPI3_BASE)
      |                             ~^~~~~~~~~~~~~~~~~~~~~~~~~~
../src/rt-arm/STM32F4/dma.hh:178:64: note: in expansion of macro 'SPI3'
  178 | plate<> struct dma_perph<1,0,0> { enum {addr =  (uint64_t)(&SPI3->RXDR)}; }; //"SPI3_Rx"
      |                                                             ^~~~

Other lines like that one also get a similar error.  What I don't understand is that the SPI3_BASE is a constant and therefore I would think everything in ((SPI_TypeDef *) SPI3_BASE) would be considered a constant.  This code is directly from STM and therefore I'd expect the code to be correct and compilable.  Is the fact that the compiler is trying to change the c style cast to a reinterpret_cast<SPI_TypeDef*> causing it to think that it is not really a constant expression?  If so, what can be done to deal with this?  Given that it is a #define it seems that there shouldn't even be the requirement that the substituted value is constant.  In any case, do you have any ideas about the core problem here and how to fix it?

Note that I am not compiling this within STM32CubeIDE.  I am compiling with the arm-none-eabi-g++ compiler with this version info:

arm-none-eabi-g++ (15:13.2.rel1-2) 13.2.1 20231009
Copyright (C) 2023 Free Software Foundation, Inc.

 

1 REPLY 1
TDK
Super User

c++ - Why is reinterpret_cast not constexpr? - Stack Overflow

If you feel a post has answered your question, please click "Accept as Solution".