| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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. |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
|||
|
|||
|
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)
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Segmentation fault |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|