UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Visitor trjeppsdl
Visitor
8,223 Views
Registered: ‎02-09-2015

Petalinux Zedboard: Understanding peek/poke, mmap, GPIO(emio).

Jump to solution

I'm trying to get a better understanding of how to access Zynq's I/O peripheral registers in petalinux. The ultimate goal is writing drivers, but I want to start simple.

 

I've routed 16 bits of GPIO(emio) to the PMOD connectors on my zedboard, and in a bare metal project, I'm able to control them using the GPIO bank 2 registers (DIRM2, OEN2, DATA_2_RO, MASK_DATA_LSW) as detailed in the Zynq-TRM.

 

Next, I exported my bitstream and hardware definition files, and built a petalinux 2014.4 image based on them.

 

I assumed that I would be able to use the peek/poke application to access these same control registers, but all reads (peek) return 0's and nothing happens when I write (poke).

 

As i understand it, peek/poke use the mmap() function to map an address range from /dev/mem into userspace, but my knowledge of linux memory mapping is very limited, and I'm obviously missing something.

 

So, why doesn't this method work, and what do I need to do to get direct read/write access to the Zynq's GPIO bank 2 registers?

 

From there, I'd like to write a loadable char driver to do the same thing.

0 Kudos
1 Solution

Accepted Solutions
Xilinx Employee
Xilinx Employee
13,931 Views
Registered: ‎03-13-2012

Re: Petalinux Zedboard: Understanding peek/poke, mmap, GPIO(emio).

Jump to solution

Somewhere in the SLCR is a register (APER_CLK_CTRL, IIRC). Some bit in it controls the clock gate for that clock.

0 Kudos
4 Replies
Xilinx Employee
Xilinx Employee
8,217 Views
Registered: ‎03-13-2012

Re: Petalinux Zedboard: Understanding peek/poke, mmap, GPIO(emio).

Jump to solution

Basically your approach is correct and works. But likely, the clock for GPIO is not enabled (grep -i gpio /sys/kernel/debug/clk/clk_summary). Things should work if you enable the GPIO-related clocks.

Unless you just do this as an exercise, there are already GPIO drivers available: http://www.wiki.xilinx.com/Linux+GPIO+Driver

0 Kudos
Visitor trjeppsdl
Visitor
8,206 Views
Registered: ‎02-09-2015

Re: Petalinux Zedboard: Understanding peek/poke, mmap, GPIO(emio).

Jump to solution

I think you're right about the clock.

 

grep returned this line from the clock summary:

gpio_aper       0         0        111111110          0

 

From this line of my device tree, the gpio clock is:

clocks = <&clkc 42>;

 

This document confirms that clk 42 is in fact gpio_aper

https://www.kernel.org/doc/Documentation/devicetree/bindings/clock/zynq-7000.txt

 

The clocks section of my device tree:

            clkc: clkc@100 {
                #clock-cells = <1>;
                compatible = "xlnx,ps7-clkc";
                ps-clk-frequency = <33333333>;
                fclk-enable = <0xf>;
                clock-output-names = "armpll", "ddrpll", "iopll", "cpu_6or4x",
                        "cpu_3or2x", "cpu_2x", "cpu_1x", "ddr2x", "ddr3x",
                        "dci", "lqspi", "smc", "pcap", "gem0", "gem1",
                        "fclk0", "fclk1", "fclk2", "fclk3", "can0", "can1",
                        "sdio0", "sdio1", "uart0", "uart1", "spi0", "spi1",
                        "dma", "usb0_aper", "usb1_aper", "gem0_aper",
                        "gem1_aper", "sdio0_aper", "sdio1_aper",
                        "spi0_aper", "spi1_aper", "can0_aper", "can1_aper",
                        "i2c0_aper", "i2c1_aper", "uart0_aper", "uart1_aper",
                        "gpio_aper", "lqspi_aper", "smc_aper", "swdt",
                        "dbg_trc", "dbg_apb";
                reg = <0x100 0x100>;
            };

 

How do I go about enabling gpio_aper?

0 Kudos
Xilinx Employee
Xilinx Employee
13,932 Views
Registered: ‎03-13-2012

Re: Petalinux Zedboard: Understanding peek/poke, mmap, GPIO(emio).

Jump to solution

Somewhere in the SLCR is a register (APER_CLK_CTRL, IIRC). Some bit in it controls the clock gate for that clock.

0 Kudos
Highlighted
6,924 Views
Registered: ‎08-22-2015

Re: Petalinux Zedboard: Understanding peek/poke, mmap, GPIO(emio).

Jump to solution

The article below covers the steps of configuring, building, and loading PetaLinux (2015.2) for Zedboard. With demo Linux application tested(gpio-demo).

 

http://embeddedcentric.com/embedded-operating-systems/

 

EmbeddedCentric.com

0 Kudos