[Onion Omega2] Direct GPIO register access problem

  • Hello everyone.
    I have some problems with my Onion. I'm trying to access device registers via mmap function. I've successfully map PWM registers (address: 0x10005000). I can write and read from these registers.
    But when I try to change address to 0x10000600 (GPIO access registers) with the same code I can read, but write fails with message Segmentation fault.
    I tried to unload all GPIO modules with no effect.
    Here is my code (without headers):

    int main(int argc, char *argv[])

    uint32_t alloc_mem_size, page_mask, page_size;
    volatile uint32_t *mem_pointer, *virt_addr;
    const uint32_t mem_address = 0x10000600;
    const uint32_t mem_size = 0x600;
    page_size = 4096;
    alloc_mem_size = (((mem_size / page_size) + 1) * page_size);
    page_mask = (page_size - 1);
    int mem_dev = open("/dev/mem", O_RDWR | O_SYNC);
    mem_pointer = mmap(NULL,
                   PROT_READ | PROT_WRITE,
                   (mem_address & ~page_mask)
    virt_addr = (mem_pointer + (mem_address & page_mask)); 
    int i=0;
    printf("Memory dump before\n");
    for(i=0; i<10;i=i+2) 
    	printf("GPIO memory address=0x%016x: 0x%016x\n", virt_addr+i, *(virt_addr+i));
    // Set GPIO_0 direction bit
    printf("Memory dump after\n");
    for(i=0; i<10;i=i+2) 
    	printf("GPIO memory address=0x%016x: 0x%016x\n", virt_addr+i, *(virt_addr+i));


    Help please :)

  • Where did you get the 0x10000600 number from?

    Take a look at my GPIO management code:

  • @Krzysztof-Skiba said in [Onion Omega2] Direct GPIO register access problem:


    I found in Mediatek MT7688 Datasheet page 109:

    "Module name: GPIO Base address: (+10000600h)"

    Edit: Got it! Seems that datasheet info is incorrect.

    Thanks for help!

Log in to reply

Looks like your connection to Onion Community was lost, please wait while we try to reconnect.