Segmentation fault in inline application record for registration
I am running debian with kernel 3.14.14 on a Freescale iMX6 processor.
I have this code in an embedded application which is giving a segmentation fault.
volatile unsigned int& GPIO2IO26CTRL = *((volatile unsigned int*)0x20e0104);
GPIO2IO26CTRL = 0x5;
also tried:
volatile unsigned int* GPIO2IO26CTRL = (volatile unsigned int*)0x20e0104;
*GPIO2IO26CTRL = 0x5;
But I really want to write 0x5 at 0x20e0104. This tells the iMX6 chip that the io line should be GPIO, not spi;
How do I get around this?
+3
source to share
2 answers
Thanks for the help. If anyone has the same problem, I want to show my solution. Most of this code came from devmem2 from Jan-Derk Bakker.
Here are two routines I wrote to read and write from memory.
static const u_int32_t MAP_SIZE = 4096;
static const u_int32_t MAP_MASK = (MAP_SIZE - 1);
bool CGpio::writeMem(u_int32_t memAddr, u_int32_t &value)
{
int fd;
void *map_base, *virt_addr;
off_t target = memAddr;
// open the mem file
if((fd = open("/dev/mem", O_RDWR | O_SYNC)) == -1)
return false;
// map one page
map_base = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, target & ~MAP_MASK);
if (map_base == (void *)-1)
return false;
// map virutial space
virt_addr = map_base + (target & MAP_MASK);
// write the value
*((u_int32_t *) virt_addr) = value;
// clean up
bool ret = (munmap(map_base, MAP_SIZE) != -1);
close(fd);
return ret;
}
bool CGpio::readMem(u_int32_t memAddr, u_int32_t &value)
{
int fd;
void *map_base, *virt_addr;
off_t target = memAddr;
// open the mem file
if((fd = open("/dev/mem", O_RDWR | O_SYNC)) == -1)
return false;
// map one page
map_base = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, target & ~MAP_MASK);
if (map_base == (void *)-1)
return false;
// map virutial space
virt_addr = map_base + (target & MAP_MASK);
// read the value
value = *((u_int32_t *) virt_addr);
// clean up
bool ret = (munmap(map_base, MAP_SIZE) != -1);
close(fd);
return ret;
}
And here are the headers I used.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <signal.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <string.h>
#include <iostream>
#include <sys/types.h>
+1
source to share