From 4794cfea404ae74cd0fb25e424f2b1dee66086da Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Fri, 17 Jun 2022 13:19:59 +0200 Subject: [PATCH] Convert illegal constexpr to static const pointers We cannot get a constexpr definition of the register addresses, and any reinterpret cast is currently illegal for a constexpr in c++17. Change the SPI0, TIFR and TIMSK to volatile const pointers instead. SPI0 has volatile members instead of marking the entire struct as volatile, which is probably not a good idea as it technically drops the volatile from the original pointer. --- src/hal/spi.h | 9 ++++++--- src/hal/timers.h | 4 ++-- src/hal/tmc2130.h | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/hal/spi.h b/src/hal/spi.h index c057f64..a7a58b5 100644 --- a/src/hal/spi.h +++ b/src/hal/spi.h @@ -3,7 +3,10 @@ #include #include "gpio.h" -#define SPI0 ((hal::spi::SPI_TypeDef *)&SPCR) +#ifdef __AVR__ +#define SPI0 ((hal::spi::SPI_TypeDef *const) & SPCR) +#endif + namespace hal { /// SPI interface @@ -30,9 +33,9 @@ void Init(SPI_TypeDef *const hspi, SPI_InitTypeDef *const conf); uint8_t TxRx(SPI_TypeDef *hspi, uint8_t val); #ifdef __AVR__ -constexpr SPI_TypeDef *TmcSpiBus = SPI0; +static SPI_TypeDef *const TmcSpiBus = SPI0; #else -constexpr SPI_TypeDef *TmcSpiBus = nullptr; +static SPI_TypeDef *const TmcSpiBus = nullptr; #endif } diff --git a/src/hal/timers.h b/src/hal/timers.h index 9cb0196..d952983 100644 --- a/src/hal/timers.h +++ b/src/hal/timers.h @@ -20,8 +20,8 @@ struct Tim8bit_TypeDef { volatile uint8_t OCRxB; }; -constexpr volatile uint8_t *TIFR = &TIFR0; -constexpr volatile uint8_t *TIMSK = &TIMSK0; +static volatile uint8_t *const TIFR = &TIFR0; +static volatile uint8_t *const TIMSK = &TIMSK0; struct Tim8bit_CTC_config { uint8_t cs : 3; ///clock source as per datasheet. It is not consistent between timer types diff --git a/src/hal/tmc2130.h b/src/hal/tmc2130.h index 2bd73e8..3592bd8 100644 --- a/src/hal/tmc2130.h +++ b/src/hal/tmc2130.h @@ -18,7 +18,7 @@ enum MotorMode : uint8_t { }; struct MotorParams { - const hal::spi::SPI_TypeDef *spi; + const hal::spi::SPI_TypeDef *const spi; uint8_t idx; ///< SHR16 index bool dirOn; ///< forward direction gpio::GPIO_pin csPin; ///< CS pin