LPC17xx: accessing C-type structs via bit-banding?

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by ntipping on Mon Sep 30 04:20:34 MST 2013
Hi All,

I'm looking to port an existing application from PIC18 to ARM, and am currently playing with the LPC812 LPCXpresso board as an introduction. If we move to ARM, it will probably be Cortex-M3 (in fact possibly LPC1758 - Ethernet with small footprint). The application we have makes extensive use of sub-byte(mostly bit) sized variables in arrays of unions/structs. Having realised now how ARM deals with bits, is there any way to map C-type structs into memory and have the compiler use bit-banding addressing where possible to access members? A simple example might be something like:

    typedef union
        unsigned char value;
            unsigned char bit0:1;
            unsigned char bit1:1;
            unsigned char bit2:1;
            unsigned char bit3:1;
            unsigned char bit4:1;
            unsigned char bit5:1;
            unsigned char bit6:1;
            unsigned char Bit7:1;

    REG08    MyReg08s[20];

    int main(void)
            MyReg08s[10].value = 0; // byte access
            MyReg08s[10].bit2 = MyReg08s[5].bit3; // bit access?
            MyReg08s[10].bit4 = MyReg08s[3].bit6; // bit access?

As I understand it, the conventional approach would be to either word-align everything (expensive on RAM) or pack the structs and take the hit on code. But then again I'm new to this architecture. Could someone comment on what is possible?

Thanks in advance.


Nick Tipping