Skip to content

Modify the FPGA LEDs from the Linux prompt

skravats edited this page May 11, 2021 · 22 revisions

The example below shows how a soft (FPGA logic based) Parallel Input/Output (PIO) peripheral can be mapped to the HPS ARM processor. It also shows how the devices (LEDs) connected to that PIO can be manipulated directly from the Linux prompt.

Mapping

The LED PIO is created in the FPGA using a PIO IP Core in Platform Designer. It is connected to the ARM Cortex-A9 processor via the Lightweight HPS-to-FPGA bridge. This is shown in the GHRD diagram below.

The FPGA implementation is shown in the Platform Designer snapshot. The Lightweight bridge master port is connected to the led_pio slave port at bridge address 0x0001 0040. The bridge HPS address is 0xFF20 0000. See the Cyclone V Technical Reference Manual (Section 2.4) for further details. The resultant address from the ARM Cortex-A9 processor is 0xFF21 0040.

Examine the Device Tree

Below is a simplified listing of a portion of the Device Tree.

	sys_hps_bridges: bridge@ff200000 {
		compatible = "simple-bus";
		reg = <0xff200000 0x00200000>;
		reg-names = "axi_h2f", "axi_h2f_lw";
		#address-cells = <2>;
		#size-cells = <1>;
		ranges = <0x00000001 0x00010040 0xff210040 0x00000010>;

		led_pio: led-pio@100010040 {
			compatible = "altr,pio-1.0";
			reg = <0x00000001 0x00010040 0x10>;
			altr,ngpio = <2>;
			#gpio-cells = <2>;
			gpio-controller;
		};

		leds {
			compatible = "gpio-leds";

			fpga0 {
				label = "fpga_led0";
				gpios = <**&led_pio 0 1**>;
			};

			fpga1 {
				label = "fpga_led1";
				gpios = <&led_pio 1 1>;
			};
		};

The Lightweight bridge is declared by the statement "bridge@ff200000" and defined as a simple bus.

reg = <0xff200000 0x00200000> declares that the bridge is mapped to the Cortex-A9 at 0xFF20 0000 and has a span of 0x20 0000.

ranges = <0x00000001 0x00010040 0xff210040 0x00000010> declares a peripheral locally mapped to address 0x0001 0040 is mapped to the Cortex-A9 at address 0xFF21 0040 with a span of 0x10.

led_pio is declared at address 0x1 0001 0040 where the leading 0x01 is an index into the range declared earlier. The compatible = "altr,pio-1.0" statement instructs Linux to associate the altr pio driver with this device. altr,ngpio = <2> indicates that this pio has two bits.

leds is instantiated with the generic gpio-leds driver. It in turn declares two individual led devices, fpga_led0 and fpga_led1, one for each bit of led_pio. Each LED will show in Linux as an individual device.

Linux, the Device Tree and devices

The Linaro XFCE desktop is shown below. XFCE documentation is available.

Open a shell by double clicking on the Root Terminal Emulator icon on the desktop.

View the Device Tree from Linux

    $ ls /proc/device-tree/soc/bridge@ff200000

Examine the led devices

    $ ls /sys/class/leds

Turn fpga_led0 on from the linux prompt

    $ echo "0" > '/sys/class/leds/fpga_led0/brightness' 

Turn fpga_led0 off from the linux prompt

    $ echo "1" > '/sys/class/leds/fpga_led0/brightness' 

Turn fpga_led1 on from the linux prompt

    $ echo "0" > '/sys/class/leds/fpga_led1/brightness' 

Turn fpga_led1 off from the linux prompt

    $ echo "1" > '/sys/class/leds/fpga_led1/brightness'

Notice the correlation between the device names in Linux and the Device Tree.



Return - GSRD

Clone this wiki locally