How to create a GPIO driver

classic Classic list List threaded Threaded
30 messages Options
12
Reply | Threaded
Open this post in threaded view
|

How to create a GPIO driver

EnneGi
Hi, I must create a GPIO driver for my lpc1766 board. I try to search some source example for do it, but for gpio drivers I don't find anything. Does anybody tell me how I do it please?
Reply | Threaded
Open this post in threaded view
|

Re: How to create a GPIO driver

Andrew Lunn-2
On Sun, Mar 10, 2013 at 11:19:17AM -0700, EnneGi wrote:
> Hi, I must create a GPIO driver for my lpc1766 board. I try to search some
> source example for do it, but for gpio drivers I don't find anything. Does
> anybody tell me how I do it please?

For one example, take a look at the end of:

http://ecos.sourceware.org/cgi-bin/cvsweb.cgi/ecos/packages/hal/arm/at91/var/current/include/var_io.h?rev=1.27&content-type=text/x-cvsweb-markup&cvsroot=ecos

        Andrew

--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

Reply | Threaded
Open this post in threaded view
|

Re: How to create a GPIO driver

Ilija Kocho [Илија Кочо]
In reply to this post by EnneGi
On 10.03.2013 19:19, EnneGi wrote:
> Hi, I must create a GPIO driver for my lpc1766 board. I try to search some
> source example for do it, but for gpio drivers I don't find anything. Does
> anybody tell me how I do it please?

You could look at STM32 port.

Ilija


--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

Reply | Threaded
Open this post in threaded view
|

Re: How to create a GPIO driver

EnneGi
why STM32 port? I don't understand...
Reply | Threaded
Open this post in threaded view
|

Re: How to create a GPIO driver

Morris, Richard
In reply to this post by Ilija Kocho [Илија Кочо]
Hi All,

We are using the STM32F4 eCos port.  It has a nice set of macros to configure and access the GPIO.  Definitely worth a look as a pattern on how to do GPIO on other boards.

--Richard


--------
On Mar 10, 2013, at 12:22 PM, Ilija Kocho <[hidden email]> wrote:

On 10.03.2013 19:19, EnneGi wrote:
Hi, I must create a GPIO driver for my lpc1766 board. I try to search some
source example for do it, but for gpio drivers I don't find anything. Does
anybody tell me how I do it please?

You could look at STM32 port.

Ilija


--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss


Richard Morris
Senior Staff Firmware Engineer

T  650.638.6883
850 Lincoln Centre Dr
MS 407-1
Foster City, CA 94404
USA
http://www.lifetechnologies.com





--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

Reply | Threaded
Open this post in threaded view
|

Re: How to create a GPIO driver

Morris, Richard
In reply to this post by EnneGi
The STM32 ports show up in the eCos Configuration tool under Build>Templates as: ST STM3240 EVAL board, etc.

Useful macros are CYGWRD_HAL_STM32_GPIO_SET(…), CYGHWR_HAL_STM32_GPIO_OUT(…), CYGHWR_HAL_STM32_GPIO_IN(…).  You will find these in your ecos directory tree:

    .../ecos/packages/hal/cortexm/stm32/var/current/include/var_io.h

----------------------------
On Mar 10, 2013, at 3:57 PM, EnneGi <[hidden email]> wrote:

why STM32 port? I don't understand...



--
View this message in context: http://sourceware-org.1504.n7.nabble.com/How-to-create-a-GPIO-driver-tp224910p224925.html
Sent from the Sourceware - ecos-discuss mailing list archive at Nabble.com.

--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss


--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

Reply | Threaded
Open this post in threaded view
|

Re: How to create a GPIO driver

EnneGi
Thanks a lot! So, for my work, I "copy" the instruction of stm32 in the "var_io.h" file of lpc1766 (changing adress) and define the function of GPIO set in a file on the directory devs/ right?
Reply | Threaded
Open this post in threaded view
|

Re: How to create a GPIO driver

Morris, Richard
Hi EnneGi,

You may want to use the CYGHWR_HAL_LPC1XXX_GPIO_SET(…), CYGHWR_HAL_LPC1XXX_GPIO_OUT(…), and CYGHWR_HAL_LPC1XXX_GPIO_IN(…) macros.
 
I have found it useful to grep the eCos code base for examples of how to use macros, etc.

For examples, you can see code that uses them here:
    ./packages/hal/cortexm/lpc1xxx/var/v3_1_33/src/lpc1xxx_misc.c
    ./packages/devs/eth/arm/lpc2xxx/v3_1_33/src/if_lpc2xxx-lwip.c


Here are the related macros for the LPC1766, found in: .../packages/hal/cortexm/lpc1xxx/var/v3_1_33/include/var_io.h:

    // This macro packs the port number, bit number and mode for a GPIO
    // pin into a single word. The packing puts the mode in the ls 8 bits,
    // the bit number in 16:20 and the GPIO port number bits 8:10. The
    // mode is only specified using the last component of the name to
    // keep definitions short.
 
    #define CYGHWR_HAL_LPC1XXX_GPIO(__port, __bit, __mode )                 \
        (((__port)<< 8)                                              |      \
         ((__bit)<<16)                                               |      \
         (CYGHWR_HAL_LPC1XXX_GPIO_MODE_##__mode)                     )

    // Macros to extract encoded values
    #define CYGHWR_HAL_LPC1XXX_GPIO_PORT(__pin)                     (((__pin)&0x00000700)>>8)
    #define CYGHWR_HAL_LPC1XXX_GPIO_BIT(__pin)                      (((__pin)>>16)&0x1F)
    #define CYGHWR_HAL_LPC1XXX_GPIO_MODE(__pin)                     ((__pin)&0xFF)

    #define CYGHWR_HAL_LPC1XXX_GPIO_NONE      (0xFFFFFFFF)

    // Functions and macros to configure GPIO ports.

    __externC void hal_lpc1xxx_gpio_set( cyg_uint32 pin );
    __externC void hal_lpc1xxx_gpio_out( cyg_uint32 pin, int val );
    __externC void hal_lpc1xxx_gpio_in ( cyg_uint32 pin, int *val );

    #define CYGHWR_HAL_LPC1XXX_GPIO_SET(__pin )        hal_lpc1xxx_gpio_set( __pin )
    #define CYGHWR_HAL_LPC1XXX_GPIO_OUT(__pin, __val ) hal_lpc1xxx_gpio_out( __pin, __val )
    #define CYGHWR_HAL_LPC1XXX_GPIO_IN(__pin,  __val ) hal_lpc1xxx_gpio_in( __pin, __val )

Hope this helps.

--Richard


------
On Mar 11, 2013, at 9:52 AM, EnneGi <[hidden email]> wrote:

Thanks a lot! So, for my work, I "copy" the instruction of stm32 in the
"var_io.h" file of lpc1766 (changing adress) and define the function of GPIO
set in a file on the directory devs/ right?



--
View this message in context: http://sourceware-org.1504.n7.nabble.com/How-to-create-a-GPIO-driver-tp224910p225026.html
Sent from the Sourceware - ecos-discuss mailing list archive at Nabble.com.

--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

Reply | Threaded
Open this post in threaded view
|

Re: How to create a GPIO driver

EnneGi
Great answer! Thanks! A question: can you tell me how the function hal_LPC1XXX_gpio_set() (and other) appear in your source? In my source this function is described in this way:


__externC void hal_LPC17XX_gpio_set( cyg_uint32 pin )
{
    cyg_uint32 port = CYGHWR_HAL_LPC17XX_GPIO_PORT(pin);
    int bit = CYGHWR_HAL_LPC17XX_GPIO_BIT(pin);
    cyg_uint32 cm = CYGHWR_HAL_LPC17XX_GPIO_CFG(pin);
    cyg_uint32 cr;

    if( pin == CYGHWR_HAL_LPC17XX_GPIO_NONE )
        return;
   
    if( bit > 7 ) port += 4, bit -= 8;
    HAL_READ_UINT32( port, cr );
    cr &= ~(0xF<<(bit*4));
    cr |= cm<<(bit*4);
    HAL_WRITE_UINT32( port, cr );

    // If this is a pullup/down input, set the ODR bit to switch on
    // the appropriate pullup/down resistor.
    if( cm == (CYGHWR_HAL_LPC17XX_GPIO_MODE_IN|CYGHWR_HAL_LPC17XX_GPIO_CNF_PULL) )
    {
        cyg_uint32 odr;
        port = CYGHWR_HAL_LPC17XX_GPIO_PORT( pin );
        bit = CYGHWR_HAL_LPC17XX_GPIO_BIT(pin);
        HAL_READ_UINT32( port+CYGHWR_HAL_LPC17XX_GPIO_ODR, odr );
        if( pin & CYGHWR_HAL_LPC17XX_GPIO_PULLUP )
            odr |= (1<<bit);
        else
            odr &= ~(1<<bit);
        HAL_WRITE_UINT32( port+CYGHWR_HAL_LPC17XX_GPIO_ODR, odr );
    }
}
   
__externC void hal_LPC17XX_gpio_out( cyg_uint32 pin, int val )
{
    cyg_uint32 port = CYGHWR_HAL_LPC17XX_GPIO_PORT(pin);
    int bit = CYGHWR_HAL_LPC17XX_GPIO_BIT(pin);
   
    port += CYGHWR_HAL_LPC17XX_GPIO_BSRR;
    if( (val&1) == 0 ) port += 4;
    HAL_WRITE_UINT32( port, 1<<bit );
}
   
__externC void hal_LPC17XX_gpio_in ( cyg_uint32 pin, int *val )
{
    cyg_uint32 port = CYGHWR_HAL_LPC17XX_GPIO_PORT(pin);
    int bit = CYGHWR_HAL_LPC17XX_GPIO_BIT(pin);
    cyg_uint32 pd;
   
    HAL_READ_UINT32( port+CYGHWR_HAL_LPC17XX_GPIO_IDR, pd );
    *val = (pd>>bit)&1;
}
Reply | Threaded
Open this post in threaded view
|

Re: How to create a GPIO driver

EnneGi
In reply to this post by Morris, Richard
Ok, so I use the macros

CYGHWR_HAL_LPC1XXX_GPIO_SET(…),
CYGHWR_HAL_LPC1XXX_GPIO_OUT(…),
CYGHWR_HAL_LPC1XXX_GPIO_IN(…)

and the parameters (__pin) is the address of my GPIO board?
Reply | Threaded
Open this post in threaded view
|

Re: How to create a GPIO driver

Morris, Richard
In reply to this post by EnneGi
The pin arguments for the hal_LPC17xx_gpio_xxx() functions you describe are likely provided by a macro, of which I don't know the name.  It may be in the var_io.h file for your eCos distribution.

Once you know the value of the PIN argument, you can call the hal_LPC17XX_gpio_xxx() functions of your distribution.


--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

Reply | Threaded
Open this post in threaded view
|

Re: How to create a GPIO driver

EnneGi
I try to do the porting but i failed.
Does anybody help me step by step? I really don't understand. Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: How to create a GPIO driver

Michael Jones
EnneGi,

I don't know at what step you have a problem, so let me describe how I made changes, and if you already know this part, please forgive.

I take a copy of the code from CVS and never change it. This is for reference. Then I copy the package tree to my install area after tar'ing up my old one.

I make changes to files in the package tree. Now I can use diff or guiffy between the clean tree and the working tree if I get in trouble and need to know what I did. And I can use this for making patches.

I then have a eCos project. That project creates two directories, one ending in _build and one ending in _install.

I cd to _build and do a:

make clean
make

I do this because the build from the eCos tool may not report errors. This prevents accidental use of old files.

Then I take my application project and do a clean to make sure the compiler does not make any mistakes with old object files, and compile everything. Then I debug.

If the question is about the code itself, others may know the code you are using as an example. I am only familiar with the Kinetis macros, and I am a bit of a newbie, so I have no authority when it comes to proper coding style and structure in eCos.

Mike




On Mar 14, 2013, at 8:40 AM, EnneGi <[hidden email]> wrote:

> I try to do the porting but i failed.
> Does anybody help me step by step? I really don't understand. Thanks.
>
>
>
> --
> View this message in context: http://sourceware-org.1504.n7.nabble.com/How-to-create-a-GPIO-driver-tp224910p225400.html
> Sent from the Sourceware - ecos-discuss mailing list archive at Nabble.com.
>
> --
> Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
> and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss
>


--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

Reply | Threaded
Open this post in threaded view
|

Re: How to create a GPIO driver

EnneGi
In reply to this post by EnneGi
I'm using ecos-3.0 with redboot-k70 packages upgrade; my target is lpc1766stk
Thanks for reply
Reply | Threaded
Open this post in threaded view
|

Re: How to create a GPIO driver

Michael Jones
EnneGi,

Look at http://bugs.ecos.sourceware.org/show_bug.cgi?id=1001787

to see what I did.

Mike




On Mar 14, 2013, at 9:06 AM, EnneGi <[hidden email]> wrote:

> lpc1766stk


--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

Reply | Threaded
Open this post in threaded view
|

Re: How to create a GPIO driver

EnneGi
In reply to this post by Michael Jones
thanks for reply. Now I describe my steps:

- found explicit address of gpio in the file lpc17xx.h at this url: http://www.keil.com/dd/docs/arm/nxp/lpc17xx/lpc17xx.h
(search   "Peripheral memory map")

- copy the address in the "var_io.h" of the stm32 in the "#define" of gpio and copy the part of source that I modify in the "var_io.h" in "the var_io.h" of lpc1766stk

- compile ecos with
   ecosconfig new lpc1766stk
   ecosconfig tree
   make

- try an application of gpio


<cyg/hal/var_io.h>

int main (void)
{
    hal_LPC17XX_gpio_set(/*here I put the address*/);
    hal_LPC17XX_gpio_out(/*here I put the address*/, 0);

}


I think that gpio (associated to led) send value 0 in the output.
Reply | Threaded
Open this post in threaded view
|

Re: How to create a GPIO driver

EnneGi
the function is described in the file ecos-3.0/packages/hal/cortexm/stm32/var/current/src/stm32_misc.c

then I copied the declaration of function in lpc1766stk_misc.c
Reply | Threaded
Open this post in threaded view
|

Re: How to create a GPIO driver

Michael Jones
In reply to this post by EnneGi
EnneGi,

I don't know this part, but you may want to look at the configuration of the port. Most GPIO have a configuration register. It is possible the GPIO port is disabled or disconnected. You should be able to examine the configuration registers with your debugger. I find it much faster to just see what is in the registers than wade through code trying to reason my way to the registers value.

Mike



On Mar 14, 2013, at 9:23 AM, EnneGi <[hidden email]> wrote:

> thanks for reply. Now I describe my steps:
>
> - found explicit address of gpio in the file lpc17xx.h at this url:
> http://www.keil.com/dd/docs/arm/nxp/lpc17xx/lpc17xx.h
> (search   "Peripheral memory map")
>
> - copy the address in the "var_io.h" of the stm32 in the "#define" of gpio
> and copy the part of source that I modify in the "var_io.h" in "the
> var_io.h" of lpc1766stk
>
> - compile ecos with
>   ecosconfig new lpc1766stk
>   ecosconfig tree
>   make
>
> - try an application of gpio
>
>
> <cyg/hal/var_io.h>
>
> int main (void)
> {
>    hal_LPC17XX_gpio_set(/*here I put the address*/);
>    hal_LPC17XX_gpio_out(/*here I put the address*/, 0);
>
> }
>
>
> I think that gpio (associated to led) send value 0 in the output.
>
>
>
> --
> View this message in context: http://sourceware-org.1504.n7.nabble.com/How-to-create-a-GPIO-driver-tp224910p225418.html
> Sent from the Sourceware - ecos-discuss mailing list archive at Nabble.com.
>
> --
> Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
> and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss
>


--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

Reply | Threaded
Open this post in threaded view
|

Re: How to create a GPIO driver

EnneGi
Ok, so how I locate GPIO register in this way?
Reply | Threaded
Open this post in threaded view
|

Re: How to create a GPIO driver

Michael Jones
You have to get the datasheet for the processor you are using, then use a memory display in your debugger.



On Mar 14, 2013, at 9:35 AM, EnneGi <[hidden email]> wrote:

> Ok, so how I locate GPIO register in this way?
>
>
>
> --
> View this message in context: http://sourceware-org.1504.n7.nabble.com/How-to-create-a-GPIO-driver-tp224910p225422.html
> Sent from the Sourceware - ecos-discuss mailing list archive at Nabble.com.
>
> --
> Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
> and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss
>


--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

12