Good day, I wonder if somebody has managed to create a structured way of accessin the memory mapped IO attached to the STR912 [ARM9] via bitfields.
I can manipulate the members of a union that is declared in main(), bus a soon as I make a pointer type of my union and point it to the memory bus, get unexpected results.
The following two posts, from 2000 and 2005, make it seem asif it is onl possible to access 4 byte values on the ARM memory architecture at a tim and that bitfield accesses won't work:
My test code is as follow:
main() { uint32_t uwI; uint32_t *pwPointer;
typedef struct { volatile uint32_t PLL_MDIV:8; // [7:0] PLL Pre-divider volatile uint32_t PLL_NDIV:8; // [15:8] PLL Feedback divider volatile uint32_t PLL_PDIV:3; // [18:16] PLL Post-divider volatile uint32_t PLL_EN:1; // [19] PLL Enable (0=off, 1=on)
volatile uint32_t uwPAD:12; // [31:20] -PADDING- } mySCU_PLLCONF_t;
typedef union { volatile uint32_t ALL; volatile mySCU_PLLCONF_t BITS; } mySCU_PLLCONF_u; mySCU_PLLCONF_u umyPLLCONF; volatile mySCU_PLLCONF_u *pPLLCONF;
umyPLLCONF.BITS.PLL_MDIV = 0x80; umyPLLCONF.BITS.PLL_NDIV = 0x10; umyPLLCONF.BITS.PLL_PDIV = 0x2; umyPLLCONF.BITS.PLL_EN = 1;
uwI=umyPLLCONF.ALL; The value in uwI is 0x000a1080, as expected.
// ON SCU bus pwPointer = (uint32_t *)(AHB_NB_APB1_BASE + SCU_OFST); //5c00 2000 pwPointer++; //increment one word, to get aligned with PLL //5c00 2004 pPLLCONF = (mySCU_PLLCONF_u *)pwPointer; pPLLCONF->BITS.PLL_MDIV = 0x80; uwI=pPLLCONF->ALL; //Value is 0x8080-->Both 'MDIV' and 'NDIV'altered... pPLLCONF->BITS.PLL_NDIV = 0x10; uwI=pPLLCONF->ALL; //Value is 0x1010-->Both 'MDIV' and 'NDIV'altered... }
I'm running gcc 4.3.1, compiled for target: arm-elf, with newlib. If i will help, I could supply the detailed configure switches when I build th toolchain and CFLAGS/LDFLAGS of my Makefile.
Any help will be much appreciated.
Regards, Frikkie Thirion