Forums

Configuring GPIO on lpc2468

Started by khader_s_s February 8, 2008
Hi
I have an lpc2468 board where I have uart0 and a GSM module
connected to uart1 and a GPS module connected to uart2 where
UART0= P0.2 ~ P0.3
UART1= P2.0 ~ P2.7
UART2= P0.10 ~ P0.11
UART3= P0.25 ~ P0.26

I am trying set GPIO for this.
PINSEL0 |= 0x00500050; /* P0.2 TXD0 , P0.3 RXD0 & P0.10
TXD2 , P0.11 RXD2 */
PINSEL1 |= 0x003b0000; /* P0.25 TXD3 , P0.26 RXD3 */
PINSEL4 |= 0x0000A88A; /* P2.0 TXD1 , P2.1 RXD1 , P2.3
DCD1 ,
P2.5 DTR1 , P2.6 RI1 ,P2.7 RTS1 */
PINSEL6 |= 0x55555555; /* P3.0 ~ P3.15 as Data Bus
PINSEL7 |= 0x00000030; /* P3.18 CTS1, P3.23 as GPIO

I need to configure p3.23 as output so, I am doing:

FIO3DIR0 |= 0x00;
FIO3DIR1 |= 0x00;
FIO3DIR2 |= 0x8; /* P3.23 as O/P
FIO3DIR3 |= 0x4; /* P3.26 as O/P

FIO3CLR2 |= 0x8; /* P3.23
delay (2); /* delay for 2sec
FIO3SET2 |= 0x8; /* P3.23

I am a linux guy, and I really dont know about how this stuff works,
as these settings are suggested by my board vendor.

As you see I am trying to do the above in kernel initialization and
adding these UARTs to 8250 serial driver. I see these devices getting
detected, but I cant perform any I/O.

I have read the lpc user manual, but couldnt figure out how to do
this.

Could you answer me:
1) How can I enable GPIO for a perticular pin say p3.23
2) Do can I set direction.
3) Do I need to specifically enable FIO to use it?

Thanks
Syed

An Engineer's Guide to the LPC2100 Series

Hi Syed,

I can't go though your setup in detail but I can tell you that you approach
looks correct.

It is difficult when starting out with a new micro but you are fortunate
that what you are trying to do is 'common' and there are many examples 'out
there' and all this information is covered in the User Manual.

So that you will be able to see how your vendor came up with the settings
you listed I will briefly explain how I/O needs to be setup on the LPC
micros.

Basically the LPC GPIO config is 'managed' in three 'sets' of resisters.

PSEL registers - as you know LPC pins can be configured for different
purposes (eg a given pin might function a UART pin, an SPI pin or and TIMER
pin or a general purpose I/O pin). The function of the pin is configured by
the PSEL register. There are two bits per pin - thus you have 4 'possible
functions' that a pin may have. You need to look at the appropriate PSEL
register for the specific pin you want to configure as not all four
'functions' defined.

PCONP - if a set of pin is configured as a peripheral (UART, Timer etc) you
will need to check that is it 'powered up' by setting the appropriate bits
in the PCONP register. Most 'common' peripheral are powered up by default
but I wasted hours because I did not 'know' about the PCONP reg and my
peripheral turned out to NOT be powered up by default!)

PERIPERAL REGISTERS. Id a pins function is defined to have a peripheral
function (eg UART) you then need to further configure the registers
appropriate for the peripheral
Eg. In the case of UART you will need to setup the baud rate, parity, number
of bits and so on. For details you will need to refer the appropriate
section on the peripheral the user manual. In your case you are 'lucky' that
the LPC UARTs are compatible with 'industry standard' 16550 UARTs and there
is plenty of sample code on the net and it wis well documented.

GPIO. If the pin is a general purpose IO pin then you need to further
configure the GPIO registers to specify where the pin is a input pin or an
output pin and whether (if an Input) it have internal pull ups enabled)
This configuration is done by the FIOxDIR (data direction) and FIOxPIN
resisters. Again lots of sample code out there and its in TFM)

NB: Ports 0 & 1 have a 'legacy' function that defaults them be 'slow GPIO'
(RTFM if you are interested). For them to operate as 'Fast GPIO' (i.e. and
use FIOxXXX regs) they need to be configured in the SCS register.

The most difficult part of the LPC micros is that peripheral configuration
details are not always located just in the section related to the
peripheral. When starting out it is good idea to read the manual cover to
cover so that you know what is there. (Not knowing about the PCONP and the
SCS registers really caught me out in the past! (I am sure there are other
'gotcha' regs waiting to catch us - hmm perhaps an idea for a FAQ)

I hope that his makes sense and helps.
Please let us know how you get on.

Cheers,
Ivan Vernot

> -----Original Message-----
> From: l... [mailto:l...] On Behalf
> Of khader_s_s
> Sent: Saturday, 9 February 2008 8:15 AM
> To: l...
> Subject: [lpc2000] Configuring GPIO on lpc2468
>
> Hi
> I have an lpc2468 board where I have uart0 and a GSM module
> connected to uart1 and a GPS module connected to uart2 where
> UART0= P0.2 ~ P0.3
> UART1= P2.0 ~ P2.7
> UART2= P0.10 ~ P0.11
> UART3= P0.25 ~ P0.26
>
> I am trying set GPIO for this.
> PINSEL0 |= 0x00500050; /* P0.2 TXD0 , P0.3 RXD0 & P0.10
> TXD2 , P0.11 RXD2 */
> PINSEL1 |= 0x003b0000; /* P0.25 TXD3 , P0.26 RXD3 */
> PINSEL4 |= 0x0000A88A; /* P2.0 TXD1 , P2.1 RXD1 , P2.3
> DCD1 ,
> P2.5 DTR1 , P2.6 RI1 ,P2.7 RTS1 */
> PINSEL6 |= 0x55555555; /* P3.0 ~ P3.15 as Data Bus
> PINSEL7 |= 0x00000030; /* P3.18 CTS1, P3.23 as GPIO
>
> I need to configure p3.23 as output so, I am doing:
>
> FIO3DIR0 |= 0x00;
> FIO3DIR1 |= 0x00;
> FIO3DIR2 |= 0x8; /* P3.23 as O/P
> FIO3DIR3 |= 0x4; /* P3.26 as O/P
>
> FIO3CLR2 |= 0x8; /* P3.23
> delay (2); /* delay for 2sec
> FIO3SET2 |= 0x8; /* P3.23
>
> I am a linux guy, and I really dont know about how this stuff works,
> as these settings are suggested by my board vendor.
>
> As you see I am trying to do the above in kernel initialization and
> adding these UARTs to 8250 serial driver. I see these devices getting
> detected, but I cant perform any I/O.
>
> I have read the lpc user manual, but couldnt figure out how to do
> this.
>
> Could you answer me:
> 1) How can I enable GPIO for a perticular pin say p3.23
> 2) Do can I set direction.
> 3) Do I need to specifically enable FIO to use it?
>
> Thanks
> Syed
--- In l..., "Ivan Vernot" wrote:
>
> Hi Syed,
>
> I can't go though your setup in detail but I can tell you that you
approach
> looks correct.
Firstly thanks for your patient reply.
> pin or a general purpose I/O pin). The function of the pin is
configured by
> the PSEL register. There are two bits per pin - thus you have
4 'possible
> functions' that a pin may have. You need to look at the appropriate
PSEL
> register for the specific pin you want to configure as not all four
> 'functions' defined.
I think I am doing this correctly.

> PCONP - if a set of pin is configured as a peripheral (UART, Timer
etc) you
For PCONP I did:
SCS |= GPIOM; /* for converting GPIO on uart0&1 to FIO
PCONP |= (1 << 4) /* UART1 */
PCONP |= (1 << 24) /* UART2 */
PCONP |= (1 << 25) /* UART3 */

But now when try to do I/O from uart1, I see errors:
serial8250: too much work for irq7
irq7 is for uart1.

Somewhere it is posted that there is no fix for this. Hmm.. I think I
dont even have clue here. It seems my gpio settings are correct but
uart1 looks unstable.
BTW do I need set anything for the GPIO interrupts? IOxIntE for
example?

Regards
Syed
>
> Could you answer me:
> 1) How can I enable GPIO for a perticular pin say p3.23
> 2) Do can I set direction.
> 3) Do I need to specifically enable FIO to use it?
>
> Thanks
> Syed
>

ya the functions of pins are vendor specific.
u can select the fun of any pin through pinselect block. look for in
which pinselect block required ur required pin is residing.

by seting output on pin u actually configure them as o/p pin.
IOSETx = 0x00; x=> corrospinding pinsel block

i don't understand what is fio.
> -----Original Message-----
> From: l... [mailto:l...] On Behalf
> Of khader_s_s
> Sent: Sunday, 10 February 2008 1:59 AM
> To: l...
> Subject: [lpc2000] Re: Configuring GPIO on lpc2468


> For PCONP I did:
> SCS |= GPIOM; /* for converting GPIO on uart0&1 to FIO
> PCONP |= (1 << 4) /* UART1 */
> PCONP |= (1 << 24) /* UART2 */
> PCONP |= (1 << 25) /* UART3 */
>
> But now when try to do I/O from uart1, I see errors:
> serial8250: too much work for irq7
> irq7 is for uart1.

What you wrote makes not sense to me at all?!
Where do you 'see' these errors?
You need to provide more detail as to the problem and what you tried.
Just pasting lots of code will not get too much result as it needs some else
to reverse engineer your work.

>
> Somewhere it is posted that there is no fix for this.
Where is it posted?
Fix for what? What are you fixing?
More detail please.
>Hmm.. I think I
> dont even have clue here. It seems my gpio settings are correct but
> uart1 looks unstable.
> BTW do I need set anything for the GPIO interrupts? IOxIntE for
> example?
>

Depends.
If your routines simply poll the UARTs LSR then you don't need to worry
about the interrupts.
If your code is fully interrupt driven then you do.

To simplify life for yourself I would suggest you used polled comms at first
then move up to using for Interrupts.

Tell us what you tried. RTFM. Describe what you saw. RTFM. Look for sample
code. RTFM. Try with sample code. RTFM. Think about it. RTFM.
Ask specific questions.

I don't mean to be difficult (well maybe a little ;-) ) but the information,
for Uart in particular, is readily available, and the data sheet is quite
detailed. And there is plenty of sample code around.

Good Luck
Ivan Vernot

> Regards
> Syed
khader_s_s wrote:
>
> --- In lpc2000@yahoogroups .com ,
> "Ivan Vernot" wrote:
> > What you wrote makes not sense to me at all?!
> > Where do you 'see' these errors?
> > You need to provide more detail as to the problem and what you
> tried.
> > Just pasting lots of code will not get too much result as it needs
> some else
> > to reverse engineer your work.
> Like I said in my first post I was trying to run this on uClinux.
> Whenever I do I/O to/from UART1 I see errors:
> serial8250: too much work for irq7
>
> > > Somewhere it is posted that there is no fix for this.
> > Where is it posted?
> > Fix for what? What are you fixing?
> > More detail please.
> http://tech. groups.yahoo. com/group/ lpc2400_uClinux/ message/76
>
Look at:
http://www.opensubscriber.com/message/l...@vger.kernel.org/8367294.html

Google is your friend, when googling for Linux related problems, goto
this URL:

http://www.google.com/linux

Leave off the last '/' otherwise google won't take you there. All
searches within that space will return results related to linux.

TomW
--- In l..., "Ivan Vernot" wrote:
> What you wrote makes not sense to me at all?!
> Where do you 'see' these errors?
> You need to provide more detail as to the problem and what you
tried.
> Just pasting lots of code will not get too much result as it needs
some else
> to reverse engineer your work.
Like I said in my first post I was trying to run this on uClinux.
Whenever I do I/O to/from UART1 I see errors:
serial8250: too much work for irq7

> > Somewhere it is posted that there is no fix for this.
> Where is it posted?
> Fix for what? What are you fixing?
> More detail please.
http://tech.groups.yahoo.com/group/lpc2400_uClinux/message/76

> >Hmm.. I think I
> > dont even have clue here. It seems my gpio settings are correct
but
> > uart1 looks unstable.
> > BTW do I need set anything for the GPIO interrupts? IOxIntE for
> > example?
> > Depends.
> If your routines simply poll the UARTs LSR then you don't need to
worry
> about the interrupts.
> If your code is fully interrupt driven then you do.
It is fully interrupt driven in uClinux 8250serial driver.

> I don't mean to be difficult (well maybe a little ;-) ) but the
information,
> for Uart in particular, is readily available, and the data sheet is
quite
> detailed. And there is plenty of sample code around.
Thanks

Thanks
Syed