Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Message

Re: [lpc2000] C union not working

2005-03-17 by Anton Erasmus

On 17 Mar 2005 at 12:06, Leonardo Santos wrote:

> 
> Hello All:
>  I'm working with a LPC2106 using the GCC 3.4.4 toolchain (GCC +
>  binutils 2.15 
> + newlib 1.13).	I wrote a union and a structure to access the P0 pins 
> individually, like this:
> 
> typedef struct {
>  int p0	: 1;
>  int p1	: 1;
>  int p2	: 1;
> (...)
>  int p30	: 1;
>  int p31	: 1;
> }port_t;
> 
> typedef union {
>  port_t pins;
>  unsigned int reg;
> } ioreg;
> 
> typedef struct {
>  ioreg iopin;
>  ioreg ioset;
>  ioreg iodir;
>  ioreg ioclr;
> }gpio_t;
> 
> So I declare a pinter like
> 
>  volatile gpio_t *gpio = 0xE0028000;
> 
> If I access the registers using 
> 
>  if( gpio->iopin.reg & 0x01 )
> 
> or 
> 
>  gpio->ioset.reg |= 0x00008000;
> 
> Everithing works fine! But if I try a code like this:
> 
>  gpio->ioset.pins.p15 = 1;
> 
> To set P0.15, P0.23 and P0.31 are set too! I had tried this code in my
> Linux workstaion and it works just fine. The compiles setting I'm
> using are 
> 
> arm-elf-gcc -c -Wall -D GCC_ARM7 -mcpu=arm7tdmi -Tlpc2106-rom.ld
> -Wcast-align -O3
> 
> So I'm compiling it in ARM mode. Any clues? Is this a compiler issue (
> I'm not using the right parameters)?
> 

If you are using packed structs, then this will fail. The compiler generates byte
accesses to structures.  The best thing is to look at the assembler output 
to see what is actually happening.

Regards
  Anton Erasmus


-- 
A J Erasmus

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.