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  [ 3 posts ] 
Author Message
 Post subject: segmentation Fault
PostPosted: Tue Nov 29, 2011 12:17 pm 
Offline

Joined: Tue Nov 29, 2011 10:25 am
Posts: 4
hello,
I'm working on a 9260 board running linux 2.6.36.
I try to toggle some GPIO, this works fine if I run a C program using sysfs method, but it's too slow for me.
I try to toggle these GPIOs with another C program using mmap, and it's works a little faster.
My favorite language is C++, so I try the mmap method with, and compile it with g++. And all I get is a "segmentation Fault" at the first instruction using the returning value of mmap
...
m_MapBase = ::mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, m_gpios, AT91_SYS & ~MAP_MASK);
....
uint32_t value = *(( volatile uint32_t*)( m_MapBase + ((PMC_OFFSET + PMC_PCSR) & MAP_MASK)));
-> Segmentation Fault !

I try to recompile the C program with g++, and I get the same seg fault as in C++ program...

Is there a problem between C++ and mmap ?

any idea is welcome...
thanks

Pierre


Top
 Profile  
 
 Post subject: Re: segmentation Fault
PostPosted: Tue Nov 29, 2011 10:07 pm 
Offline

Joined: Sat Oct 30, 2010 6:04 pm
Posts: 574
Well consider what the pointer returned (m_MapBase) actually is, and if it is valid.

If it is not look at m_gpios, for the C version of mmap() this should be the handle from opening "/dev/mem", is that valid?

Then consider if (PMC_OFFSET + PMC_PCSR) > MAP_SIZE, or if MAP_SIZE is a power of 2.

Do some more basic debugging, provide more context.


Top
 Profile  
 
 Post subject: Re: segmentation Fault
PostPosted: Thu Dec 01, 2011 11:19 am 
Offline

Joined: Tue Nov 29, 2011 10:25 am
Posts: 4
Of course m_gpio is a handle :
m_gpios = open("/dev/mem", O_RDWR | O_SYNC)
and its value is ok :

(gdb) p m_gpios
$1 = 4

#define MAP_SIZE 4096UL
#define PMC_OFFSET 0xC00
#define PMC_PCSR 0x0018 // Peripheral Clock Status Register - Read-only
so I try to read inside the map, not outside

Here is a gdb screen :

Program received signal SIGSEGV, Segmentation fault.
0x000096f0 in cFastGPIO::Init (this=0xbea11c78) at cFastGPIO.cpp:48
48 uint32_t value = *(( volatile uint32_t*)( m_MapBase + ((PMC_OF...
(gdb) p value
$1 = 4
(gdb) p m_MapBase
$2 = (void *) 0x400df000

the thing is surprising for me , is the fact that the (quite) same code is running well in C!


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

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 2 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:  
cron