I’m trying to get the GPIO_CTL register for GPIO17_HEADER40, ie pin 22 on the 40 pin header,ie gpio417 in sysfs, ie GPIO3_PQ.01. I calculated its physical address as 0x02231000. However when I try and mmap it, I always see “0”, and writing to it has no effect. I tried using sysfs to modify the GPIO and read back using my code below, but it doesn’t work. Not sure what I am doing wrong. Also note the Xavier Technical Reference manual doesn’t seem to specify the GPIO__ENABLE_CONFIG as the Parker TRM did, so I assume it is the same 8 bits as Parker TRM 8.30.9. Please help!
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdint.h>
// Base address GPIO_CTL2_GPIO1
#define GPIO_ADDR 0x02231000
#define GPIO_SZ 1
void main() {
int fd = open("/dev/mem", O_RDWR);
if (fd < 0) {
printf("Couldn't open /dev/mem!\n");
exit(1);
}
uint8_t* gpio_reg = mmap(NULL, GPIO_SZ, PROT_READ | PROT_WRITE, MAP_SHARED, fd, GPIO_ADDR);
printf("Read from %p:0x%.8X value: %x\n", gpio_reg, GPIO_ADDR, *gpio_reg);
*gpio_reg = 0xff;
printf("Read from %p:0x%.8X value: %x\n", gpio_reg, GPIO_ADDR, *gpio_reg);
// Changes between runs but my GPIO doesn't flip (confirmed on scope)
}