Atmel website | ARM Community | AVR freaks | Technical Support
Banner
 FAQ •  Search •  Register •  Login 

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Makefile issue when including header files
PostPosted: Tue Jan 11, 2011 11:50 am 
Offline

Joined: Thu Dec 30, 2010 6:49 pm
Posts: 38
Hi,

I have SAM9G45 Atmel kit and i am trying to write a simple utility for gpio control.
I came across the following function at91_set_gpio_output() in the kernel source for Atmel for gpio control. I see they have include few header files which are already part of kernel.
When i write my own application and try to include the following header in my application, it fails says not able to find the header files.

#include <linux/clk.h>
#include <linux/errno.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/debugfs.h>
#include <linux/seq_file.h>
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/module.h>
#include <linux/io.h>

#include <mach/hardware.h>
#include <mach/at91_pio.h>
#include <mach/gpio.h>

Below is content of my makefile


[root@localhost dbgene]# vi Makefile
CC = /usr/local/arm/arm-2007q1/bin/arm-none-linux-gnueabi-gcc
DIR = /home/workspace/Debug_box/Atmel_ARM_Board/dbgene_fw/source_code/linux-2.6.30_atmel_patch/arch/arm/mach-at91/
LDIR = /home/workspace/Debug_box_Atmel_ARM_Board/dbgene_fw/source_code/linux-2.6.30_atmel_patch/arch/arm/kernel

INCLUDES = -I$(DIR)

all:
$(CC) $(INCLUDES) -o led led.c

Here is my application
[root@localhost dbgene]# vi led.c
#include <linux/mm.h>
#include <linux/module.h>
#include <mach/gpio.h>
#include <mach/at91sam9g45.h>

void main()
{
printf("Glowing LED ");
at91_set_gpio_output(AT91_PIN_PB21, 1);

}



I have pointed it to pick up header files from Kernel source bu then too it fails. Can any one please help me out?

Thanks
Prashanth


Top
 Profile  
 
 Post subject: Re: Makefile issue when including header files
PostPosted: Tue Jan 11, 2011 3:30 pm 
Offline

Joined: Sat Oct 30, 2010 6:04 pm
Posts: 574
If this is a user space application, you'll need to mmap() the ATMEL peripheral space to a pointer you can access, and write your own GPIO access routines.


Top
 Profile  
 
 Post subject: Re: Makefile issue when including header files
PostPosted: Wed Jan 12, 2011 8:37 am 
Offline

Joined: Tue Jan 11, 2011 9:34 am
Posts: 9
If you are just wanting GPIO access, then enable CONFIG_GPIO_SYSFS in your kernel config.

Then something along these lines will work. This is just the first link I found on google.
http://squidge.sourceforge.net/gpio/


Top
 Profile  
 
 Post subject: Re: Makefile issue when including header files
PostPosted: Wed Jan 12, 2011 12:06 pm 
Offline

Joined: Thu Dec 30, 2010 6:49 pm
Posts: 38
Thanks for the reply.

Currently i am using gnu tool chain provided by codesourcery using which mmap() call fails as the tool chain doesn't have page.h file.

Below is snippet of my file using mmap.
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <sys/mman.h>
#include <asm/page.h>

#define PIOBASEADDR 0xFFFFF000 //generic address which can be mapped to any port
#define PIOB_PER 0xFFFFF400 //offset 400 from base address
#define PIOB_OER 0xFFFFF410
#define PIOB_OWER 0xFFFFF4A0
#define PIOB_SODR 0xFFFFF430


#define PIO_PER_VAL 0x00F00000
#define PIO_OER_VAL 0x00F00000
#define PIO_OWER_VAL 0x00F00000


int main(int argc, char *argv[])
{
FILE * mem_fh;
unsigned long int* vid_addr;
unsigned long int baseAddr = 0;
unsigned long int value = 0;
unsigned int baseOffset;


if ((mem_fh = fopen("/dev/mem", "r+") ) < 0)
{
printf("can't open /dev/mem \n");
exit (-1);
}

// First enable PIO_PER

baseAddr = PIOB_PER;

// adjust the base address at the page boundary

baseOffset = baseAddr & ~PAGE_MASK;
baseAddr &= PAGE_MASK;

vid_addr = (unsigned char*)mmap(NULL, /* where to map to: don't mind */
PAGE_SIZE, /* how many bytes ? */
PROT_READ | PROT_WRITE, /* want to read and write */
MAP_SHARED, /* no copy on write */
fileno(mem_fh), /* handle to /dev/mem */
baseAddr); /* hopefully the Text-buffer :-)*/

// Now write the value to enable PIO_PER
vid_addr[baseAddr] = PIO_PER_VAL;

Even the above code was not compiling with codesourcery compiler. I used one more gcc compiler which we had and was based on arm-linux which can compile the above code.
Strangely when i flash the compiled code my board, and execute my file ./gpio, it says cannot find the file even thought is it present

Below is o/p from my debug console... i have never seen such thing....
[root@Mini6045:/dbgene]# ls -l
-rwxr--r-- 1 root root 371 Mar 4 2011 Makefile
-rwxr-xr-x 1 root root 9201 Jan 3 2011 gpio
-rwxr--r-- 1 root root 3438 Jan 3 2011 gpio.c
-rwxr-xr-x 1 root root 8216 Mar 4 2011 hello
-rw-r--r-- 1 root root 101 Jan 1 2011 hello.c
-rwxrwxr-x 1 root root 4908 Mar 1 2011 hello386
-rw-r--r-- 1 root root 37 Dec 29 2010 pk.txt
-rw-r--r-- 1 root root 28 Mar 1 2011 pkmk
[root@Mini6045:/dbgene]#
[root@Mini6045:/dbgene]# ./gpio
-/bin/sh: ./gpio: not found
[root@Mini6045:/dbgene]#


Later on i wrote the following file to use atmel kernel source


#include <linux/mm.h>
#include <linux/module.h>
#nclude <linux/clk.h>
#include <linux/errno.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/debugfs.h>
#include <linux/seq_file.h>
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/module.h>
#include <linux/io.h>
#include <stdio.h>

void main()
{
printf("Glowing LED ");
//at91_set_gpio_output(AT91_PIN_PB21, 1);

}

When i compile this code with codesourcery compiler (GNU EABI), it givs tons and tons of error saying lot of header files are not present.

Below is how my makefile looks

[root@localhost dbgene]# pwd
/home/workspace/Debug_box/Atmel_ARM_Board/dbgene_fw/source_code/dbgene_fs/dbgene
[root@localhost dbgene]# vi Makefile
CC = /usr/local/arm/arm-2007q1/bin/arm-none-linux-gnueabi-gcc
#CC = /usr/local/arm/intcc/bin/arm-linux-gcc

IDIR = /home/workspace/Debug_box/Atmel_ARM_Board/dbgene_fw/source_code/linux-2.6.30_atmel_patch/include
IDIR1 = /home/workspace/Debug_box/Atmel_ARM_Board/dbgene_fw/source_code/linux-2.6.30_atmel_patch/arch/arm/include

INCLUDES = -I$(IDIR) -I$(IDIR1)

all:
$(CC) $(INCLUDES) -o atmelled atmelled.c
#(CC) -o atmelled atmelled.c


This is making me go crazy as i am not able to find any help from Google...


canat91,

Even if i enable GPIO capability, i still need to write a user level application to link to the module during which i still need to use Atmel kernel source and it fails :(


Top
 Profile  
 
 Post subject: Re: Makefile issue when including header files
PostPosted: Wed Jan 12, 2011 12:50 pm 
Offline

Joined: Thu Dec 30, 2010 6:49 pm
Posts: 38
I found more about sysfs LED class in the below link ...

http://www.mjmwired.net/kernel/Document ... -class.txt

When i execute the following command, i am able to turn off or on a LED but their is not much details on how they have done it. I still need a user space application from which i meed to access GPIO, I2C, PWM drivers and there method might not be much helpful...


Top
 Profile  
 
 Post subject: Re: Makefile issue when including header files
PostPosted: Sat Jan 15, 2011 5:12 am 
Offline

Joined: Sat Oct 30, 2010 6:04 pm
Posts: 574
The mmap() is a bit broken, this should be better.

// adjust the base address at the page boundary

baseOffset = baseAddr & PAGE_MASK; // Byte Offset within the page
baseAddr &= ~PAGE_MASK; // Address on page boundary

vid_addr = (unsigned long int*)mmap(NULL, /* where to map to: don't mind */
PAGE_SIZE, /* how many bytes ? */
PROT_READ | PROT_WRITE, /* want to read and write */
MAP_SHARED, /* no copy on write */
fileno(mem_fh), /* handle to /dev/mem */
baseAddr); /* hopefully the Text-buffer :-)*/

// Now write the value to enable PIO_PER
vid_addr[baseOffset / sizeof(unsigned long int)] = PIO_PER_VAL;


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: