GPIO Pin Manipulation Unstable High-Low Duration


On Xaiver Nx JP4.6 we are trying to set GPIO pins as High and Low.
It is critical for us to set HIGH for some amount of time lets say 1ms and set LOW again. We test it with low cpu load device and measure the signal with osciloscope it gave stable output with 1ms interval. But when we run stress application and increase cpu load, the output signal is unstable , it gave ~1.5ms ~2ms ~1ms randomly. We try to update nice value it decreases the variance but not enough. Are there any way to control gpio on high load ?

This is the code snippet we use for GPIO manipulation

       int fd = open("/dev/mem", O_RDWR | O_SYNC);
        if (fd < 0)
            fprintf(stderr, "Please run this program as root (for example with sudo)\n");
            return false;

        uint32_t pagesize = getpagesize();
        uint32_t pagemask = pagesize - 1;

        void *gpio_address = mmap(0, pagesize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, (adr & ~pagemask));
        void *pad_ctl_address = mmap(0, pagesize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, (adr2 & ~pagemask));

        if (gpio_address == NULL || pad_ctl_address == NULL)
            fprintf(stderr, "gpio_adress or pad_ctl_address is null\n");
            return false;

        volatile char *gpio_base = ((char *)gpio_address + (adr & pagemask));
        volatile char *pad_ctl = ((char *)pad_ctl_address + (adr2 & pagemask));

        *pad_ctl = 0x00000000;                           // Select GPIO
        *(gpio_base + GPIO_OUTPUT_CONTROL) = 0x00000000; // Driven
        *(gpio_base + GPIO_ENABLE_CONFIG) = 0x00000003;  // GPIO Enable, Out

        output_value = gpio_base + GPIO_OUTPUT_VALUE;
    *output_value = m_highVal;

    *output_value = m_lowVal;

1 Like

Hi ikoc,

Are you using the devkit or custom board for Xavier NX?

It seems the expected behavior the interval of GPIO high/low is depending on the CPU load.

May I know what’s your use case to control GPIO?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.