I'm having an issue when accessing the GPIO 2 and 3 registers through
/dev/mem. Here is a snippet of the related code:
__off_t GPIO_REGISTER_OFFSETS[] = {
0x44E07000, // GPIO 0
0x4804C000, // GPIO 1
0x481AC000, // GPIO 2
0x481AE000 // GPIO 3
};
// Offsets within the GPIO Register
#define GPIO_MEM_LENGTH 0xfff
#define GPIO_OE 0x134
#define GPIO_DATAIN 0x138
#define GPIO_DATAOUT 0x13C
#define GPIO_CLEARDATAOUT 0x190
#define GPIO_SETDATAOUT 0x194
struct GPIO_LAYOUT
{
int fd;
uint8_t *gpio_addr;
uint32_t *gpio_oe_addr;
uint32_t *gpio_setdataout_addr;
uint32_t *gpio_cleardataout_addr;
uint32_t *gpio_dataout_addr;
uint32_t *gpio_datain_addr;
} GPIO_Layouts[4];
int fd;
GPIOManager::GPIOManager()
{
fd = open("/dev/mem", O_RDWR);
//printf("Mapping %X - %X (size: %X)\n", GPIO1_START_ADDR,
GPIO1_END_ADDR, GPIO1_SIZE);
for( size_t gpio = 0; gpio < 4; ++gpio)
{
GPIO_LAYOUT& mux = GPIO_Layouts[gpio];
mux.gpio_addr = (uint8_t*)mmap(0, GPIO_MEM_LENGTH, PROT_READ |
PROT_WRITE, MAP_SHARED, fd, GPIO_REGISTER_OFFSETS[gpio]);
if(mux.gpio_addr == MAP_FAILED)
{
throw MSC_EXCEPTION("Unable to map texpr PIO");
}
mux.gpio_oe_addr = (uint32_t *)(mux.gpio_addr + GPIO_OE);
mux.gpio_setdataout_addr = (uint32_t *)(mux.gpio_addr +
GPIO_SETDATAOUT);
mux.gpio_cleardataout_addr = (uint32_t *)(mux.gpio_addr +
GPIO_CLEARDATAOUT);
mux.gpio_dataout_addr = (uint32_t *)(mux.gpio_addr +
GPIO_DATAOUT);
mux.gpio_datain_addr = (uint32_t *)(mux.gpio_addr +
GPIO_DATAIN);
// !!! Crash occurs here when gpio == 2
unsigned int temp = *mux.gpio_addr;
}
}
The last line will crash when dereferencing any memory location for gpio 2
and 3 though the mmap appears to be successful. Any thoughts? I am running
with root permissions.
--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.