0

We are using Atmel's ASF (3.48) with Studio 7 (on an ATSAM4E series MCU), with the arm-gnu-toolchain 9-2020-q2-update. The team has recently decided to write more higher interface layers with C++, while still using the CMSIS and ASF drivers in C as they are. With that in mind, I am trying to replace the following in my interface file:

#define MY_DEBUG_UART UART0

with

constexpr Uart *MY_DEBUG_UART = UART0;

Now, UART0 is defined in the relevant CMSIS/SAM4E file as

#define UART0 ((Uart *)0x400E0600U) /**< \brief (UART0 ) Base Address */

So upon building, an error is returned with this UART0 #define.

Error reinterpret_cast from integer to pointer

I think I see why. But the examples I have seen seem to involve setting up a register class. I don't want to duplicate things and would like to use the drivers provided, have the readability of #defines without its accompanying issues, and utilise the C++ advantages. What's the cleanest way to achieve this please?

Adimanav
  • 1
  • 1
  • So.. just remove `constexpr` and replace with `static Uart * const`. – KamilCuk Jul 31 '20 at 17:22
  • Thanks. I have ended up with static const Uart* const MY_DEBUG_UART = UART0. My thinking is UART0 being a register address should be treated as a constant, and I don't want the pointer to change either. – Adimanav Aug 04 '20 at 21:57

0 Answers0