I have a set of 32-bit registers for a peripheral in an embedded application(ARM bare-metal), with the following byte addresses.
CTL 0x0;
STAT 0x4
TXR 0x8 <-- Discontinuous address
RXR 0x20
DAT1 0x30 <-- Discontinuous address
DAT2 0x40 <-- Discontinuous address
and so on
I want to group all these registers into a C struct (Its a packed struct)
struct my_peri { uint32_t CTL; uint32_t STAT; uint32_t TXR; uint32_t RXR; uint32_t DAT1; uint32_t DAT2; }; struct my_peri* pPeri0 = (uint32_t*) (BASE_ADDRESS_OF_MY_PERI_0); Now if i access
pPeri->RXR; // This will point to (BASE_ADDRESS + 0x10) // But the actual address i want to refer is (BASE_ADDRESS + 0x20) In order to get the right the address right i manually added some elements between
struct my_peri { uint32_t CTL; uint32_t STAT; uint32_t TXR; uint32_t RESERVED[4]; // 0x10 to 0x1c uint32_t RXR; uint32_t RESERVED_1[3]; // 0x24-0x2c uint32_t DAT1; uint32_t RESERVED_2[3]; // 0x34-0x3c uint32_t DAT2; }; But any access to RESERVED, RESERVED_1 and RESERVED_2 will give error as per the peripheral specs.
Is there a way to add address spacing between the struct elements? Without adding RESERVED elements If not, is there a way to group these registers into a single data structure?. With each register pointing to the right address. I'm using ARM-GCC toolchain.
volatile(yes, "volatile considered harmful", et cetera, et cetera).