cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Visitor
Visitor
4,727 Views
Registered: ‎03-02-2010

GPIO issue -- mismatch between documentation and drivers

I am having difficulty using some of the Xilinx provided GPIO functions and examples. I traced the issue and found that the data register for a GPIO isn't being read when it is configured as an output.

 

The Xilinx functions XGpio_DiscreteSet() and XGpio_DiscreteClear() read the data register and modify only the bits specified by a mask. These functions fail to work properly for me and any read from a GPIO output returns a 0, regardless of the state of the output.

 

In the GPIO data sheet (v2.00.a, DS569 Apr 19, 2010) it specifically says on pg 10, Table 6, Note 2, that "When a GPIO pin is configured as an output, the corresponding data register bit is write only, it cannot be read."

 

Either I am doing something wrong or the Xilinx provided examples and functions should be modified to reflect the functionality of the hardware. The code segment below produces the faulty behavior.


    XGpio LEDs;
    int status, i;

 

    status = XGpio_Initialize(&LEDs, XPAR_LEDS_8BIT_DEVICE_ID);
    if(status != 0)
        return 1;


    XGpio_SetDataDirection(&LEDs, 1, 0);

    XGpio_DiscreteWrite(&LEDs, 1, 0xff);

    // Correctly lights all LEDs

 

    i = XGpio_DiscreteRead(&LEDs, 1);

    xil_printf("Read 0x%x from GPIO\n", i);

    // Reads 0x0 from GPIO, even though all LEDs are lite

 

    XGpio_DiscreteClear(&LEDs, 1, 0x1);

    // Turns off all LEDs, not just the LSB

0 Kudos
4 Replies
Highlighted
Xilinx Employee
Xilinx Employee
4,706 Views
Registered: ‎07-30-2007

So is the issue that calling a read function against a register that cannot be read is giving an incorrect value?

 

If thats the case, I'd expect this behavior to be normal.  What are you expecting to occur?

 

Dylan

0 Kudos
Highlighted
Visitor
Visitor
4,687 Views
Registered: ‎03-02-2010

The issue is that, as far as I can tell, the GPIO hardware does not support reading from an output while the Xilinx-supplied driver functions XGpio_DiscreteSet and XGpio_DiscreteClear require that the GPIO hardware support read-modify-write for outputs.

 

Thus, these functions and the SDK examples that use them do not work correctly.

0 Kudos
Highlighted
Xilinx Employee
Xilinx Employee
4,682 Views
Registered: ‎07-30-2007

I understand.  Bug CR575225 filed against GPIO driver.

 

Thanks,

Dylan

0 Kudos
Highlighted
Xilinx Employee
Xilinx Employee
4,617 Views
Registered: ‎08-07-2007

Hi scraven,

 

Make sure that you use GPIO_IO, not the GPIO_IO_O port. Then you should be able to read back the data on output.

 

-Felix

0 Kudos