C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old May 4th, 2005, 05:25 AM
king_dev king_dev is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2005
Posts: 2 king_dev User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 56 m 39 sec
Reputation Power: 0
Segmentation fault

Hi,

I am trying to write some code to access the CompuLab ARMCore board GPIO, the code compilation ok using gcc/g++, but encounter 'Segmentation fault' when execute the code. Anyone can tell me why ?

> g++ -o test gpio_access.c
> ./test
Segmentation fault


typedef unsigned long volatile special_register;

typedef struct gpio gpio;
struct gpio
{
special_register GPIO_GPDR0; special_register GPIO_GPDR1;
};

#define gpio_base (*(gpio *)0x40e00000)

int main(void)
{
unsigned long int read_value;

read_value = gpio_base.GPIO_GPDR0;
}

Thanks !

Regards,
Dev_king

Reply With Quote
  #2  
Old May 4th, 2005, 07:19 PM
ubergeek ubergeek is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2005
Posts: 600 ubergeek User rank is Private First Class (20 - 50 Reputation Level)ubergeek User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 40 m 27 sec
Reputation Power: 4
Send a message via AIM to ubergeek
Code:
  #define    gpio_base (*(gpio *)0x40e00000)

You can't do this! You are assuming (1) that that block of memory is free and (2) more importantly, that your program is allowed to access it. You program is most certainly not allowed to access memory it has not allocated. Furthermore, all modern operating systems manage their memory so even if you could choose that memory address and access it, it would not actually be the region on the physical memory with that address. The reason for this is that memory may either be on a memory device, or in a swap file, and most operating systems start the memory addresses that an application sees at the point in memory where the application is stored.

Reply With Quote
  #3  
Old May 4th, 2005, 10:00 PM
king_dev king_dev is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2005
Posts: 2 king_dev User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 56 m 39 sec
Reputation Power: 0
Segmentation fault

This address 0x40e00000 is the ARMCore PXA255 GPIO internal peripheral register base location, I need to configure the GPIO using this address. So how can I declare a variable to access it ?

Currently I am running MontaVista Linux on my CompuLab ARMCore board.

Thanks

Reply With Quote
  #4  
Old May 5th, 2005, 03:11 PM
ubergeek ubergeek is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2005
Posts: 600 ubergeek User rank is Private First Class (20 - 50 Reputation Level)ubergeek User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 40 m 27 sec
Reputation Power: 4
Send a message via AIM to ubergeek
i don't know of a way to do that unless you can find a way to run your program in real-mode DOS or something equivalent (non memory-managed OS)

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Segmentation fault


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT