New Horizons

Welcome to my blog

My name is Sven Andersson and I
work as a consultant in embedded
system design, implemented in ASIC
and FPGA.
In my spare time I write this blog
and I hope it will inspire others to
learn more about this fantastic field.
I live in Stockholm Sweden and have
my own company


You are welcome to contact me
and ask questions or make comments
about my blog.


New Horizons
What's new
Starting a blog
Writing a blog
Using an RSS reader

Zynq Design From Scratch
Started February 2014
1 Introduction
Changes and updates
2 Zynq-7000 All Programmable SoC
3 ZedBoard and other boards
4 Computer platform and VirtualBox
5 Installing Ubuntu
6 Fixing Ubuntu
7 Installing Vivado
8 Starting Vivado
9 Using Vivado
10 Lab 1. Create a Zynq project
11 Lab 1. Build a hardware platform
12 Lab 1. Create a software application
13 Lab 1. Connect to ZedBoard
14 Lab 1. Run a software application
15 Lab 1. Benchmarking ARM Cortex-A9
16 Lab 2. Adding a GPIO peripheral
17 Lab 2. Create a custom HDL module
18 Lab 2. Connect package pins and implement
19 Lab 2. Create a software application and configure the PL
20 Lab 2. Debugging a software application
21 Running Linux from SD card
22 Installing PetaLinux
23 Booting PetaLinux
24 Connect to ZedBoad via ethernet
25 Rebuilding the PetaLinux kernel image
26 Running a DHCP server on the host
27 Running a TFTP server on the host
28 PetaLinux boot via U-boot
29 PetaLinux application development
30 Fixing the host computer
31 Running NFS servers
32 VirtualBox seamless mode
33 Mounting guest file system using sshfs
34 PetaLinux. Setting up a web server
35 PetaLinux. Using cgi scripts
36 PetaLinux. Web enabled application
37 Convert from VirtualBox to VMware
38 Running Linaro Ubuntu on ZedBoard
39 Running Android on ZedBoard
40 Lab2. Booting from SD card and SPI flash
41 Lab2. PetaLinux board bringup
42 Lab2. Writing userspace IO device driver
43 Lab2. Hardware debugging
44 MicroZed quick start
45 Installing Vivado 2014.1
46 Lab3. Adding push buttons to our Zynq system
47 Lab3. Adding an interrupt service routine
48 Installing Ubuntu 14.04
49 Installing Vivado and Petalinux 2014.2
50 Using Vivado 2014.2
51 Upgrading to Ubuntu 14.04
52 Using Petalinux 2014.2
53 Booting from SD card and SPI flash
54 Booting Petalinux 2014.2 from SD card
55 Booting Petalinux 2014.2 from SPI flash
56 Installing Vivado 2014.3

Chipotle Verification System

EE Times Retrospective Series
It all started more than 40 years ago
My first job as an electrical engineer
The Memory (R)evolution
The Microprocessor (R)evolution

Four soft-core processors
Started January 2012
Table of contents
OpenRISC 1200
Nios II

Using the Spartan-6 LX9 MicroBoard
Started August 2011
Table of contents
Problems, fixes and solutions

FPGA Design From Scratch
Started December 2006
Table of contents
Acronyms and abbreviations

Actel FPGA design
Designing with an Actel FPGA. Part 1
Designing with an Actel FPGA. Part 2
Designing with an Actel FPGA. Part 3
Designing with an Actel FPGA. Part 4
Designing with an Actel FPGA. Part 5

A hardware designer's best friend
Zoo Design Platform

Installing Cobra Command Tool
A processor benchmark

Porting a Unix program to Mac OS X
Fixing a HyperTerminal in Mac OS X
A dream come true

Stockholm by bike

The New York City Marathon

Kittelfjall Lappland

Tour skating in Sweden and around the world
Wild skating
Tour day
Safety equipment
A look at the equipment you need
Skate maintenance
Books, photos, films and videos
Weather forecasts

38000 feet above see level
A trip to Spain
Florida the sunshine state

Photo Albums
Seaside Florida
Ronda Spain
Sevilla Spain
Cordoba Spain
Alhambra Spain
KittelfjÀll Lapland
Landsort Art Walk
Skating on thin ice

100 Power Tips for FPGA Designers

Adventures in ASIC
Computer History Museum
Design & Reuse
d9 Tech Blog
EDA Cafe
EDA DesignLine
Eli's tech Blog
FPGA Arcade
FPGA Central
FPGA developer
FPGA Journal
FPGA World
Lesley Shannon Courses
Mac 2 Ubuntu
Programmable Logic DesignLine
World of ASIC

If you want to be updated on this weblog Enter your email here:

rss feed

Sunday, March 02, 2014
Zynq design from scratch. Part 19.
Create a software application

In this experiment we will use SDK to create and run software for the new custom PL peripheral. But first we will configure the programmable logic (PL) using the newly created bitstream file. Let's start Xilinx SDK.

xsdk &


Click the configuration icon in the top menu. This will open the "Program FPGA" window. Find and select the bitstream file (system_wrapper.bit) that was exported to SDK. I will always use the words configure and configuration when I talk about "programming the hardware" on the board.

Click Program and wait a minute or two.

If the configuration is successful this blue LED will light up.

Create a new application project.

1. Select File->New->Application Project

2. Type LED_Dimmer in the project name and select "Use existing" under Board Support Package. Click Next.

3. Select Empty Application to be used as a template and click Finish.

4. The new software project will appear in the Project Explorer window. Expand LED_Dimmer and right-click on src and select New->File.


5. Enter the name main.c. Click Finish.

6. The C file will open in the editor window. It should be blank as an empty application was specified. Now we can start writing our application program.

Don't invent the wheel again

Xilinx has included a lot of documentation, program examples, and low-level drivers in the SDK installation. To access this information we open the system.mss file (if not already open).

Where is the axi_gpio driver

I can't find the <axi_gpio> driver. Is should be included in the board support package we have generated earlier.

Rebuilding the board support package

The GPIO module was added after we created the standalone_bsp_0. To inlude the new module we have to rebuild the BSP.  This is what we are going to do:

  1. Open SDK and delete the standalone_bsp_0
  2. Create a new BSP with same name

When we open the system.mss file this time it displays the axi_gpio driver.

Let's click the Documentation hyperlink.

Error opening Firefox

When clicking one of the hyperllnks in the system.mss file to open Firefox this error message appear on the terminal screen.

This is not the first time I see this error message. The problem seems to be that Xilinx includes their own shared C-libraries and that they are not updated automatically by the Ubuntu software updater. An easy fix is to rename this library and then Firefox will pick up the Ubuntu shared library.

cd /opt/Xilinx/SDK/2013.4/lib/lin64
sudo mv

Let's try again.

Clicking the Files hyperlink reveals the following information.

Writing the application program

After studying the documentation we are ready to write the application program. Here is what I came up with. Take a look and try to understand what is happening. It is quite simple.

/*                               H E A D E R                                 */

// Program Name          : main.c
// Program Type          : C application program for Zynq
// Platform              : Zynq All Programmable SoC
// Board                 : ZedBoard
// Date                  : 2014-03-05

/*                         I N C L U D E   F I L E S                         */

#include "xparameters.h"
#include "xgpio.h"

/*                           C O N S T A N T S                               */

//The following constant maps to the name of the hardware instances that
// were created in the Vivado system.


// The following constant is used to determine which channel of the GPIO is
// used for the LED if there are 2 channels supported.

#define LED_CHANNEL 1

/*                            V A R I A B L E S                              */

XGpio Gpio;        // The Instance of the GPIO Driver

/*                                M A I N                                    */

int main(void)
    int Status;
    u32 value           = 0;
    u32 period          = 0;
    u32 brightness      = 0;

    // Initialize the GPIO driver

    Status = XGpio_Initialize(&Gpio, GPIO_EXAMPLE_DEVICE_ID);
    if (Status != XST_SUCCESS) {
        return XST_FAILURE;

    // Clear the LEDs
    XGpio_DiscreteWrite(&Gpio, LED_CHANNEL, 0);

    while (1) {
       print(" Select a Brightness between 0 and 9 : ");
       value = inbyte();
       period = value - 0x30;
       xil_printf("Brightness Level %d selected ", period);

       // Since the LED width is 1e6 clk cycles, we need to normalize
       // the period to that clk.  Since we accept values 0-9, that will
       // scale period from 0-999,000.  0 turns off LEDs, 999,000 is full
       // brightness

       brightness = period * 110000;
       // Write the duty_cycle width (Period) out to the PL GPIO peripheral

       XGpio_DiscreteWrite(&Gpio, LED_CHANNEL, brightness);


    return XST_SUCCESS;

Compiling the program

Running the program

Setup the terminal (GTKterm) and start the program (see part 14). Here is the print out on the terminal screen

and all the LEDs are glowing.

Terminate a running program

To terminate a running program click the red button.

Top   Previous   Next

Posted at 07:27 by

March 12, 2015   06:11 PM PDT
I'm following all the steps and I still don't have the "axi0 gpio" driver. I even tried Sergio_Avramenko solution and still nothing.

What am I missing?
Leonardo Solis
December 19, 2014   01:28 AM PST
Leonardo Solis
December 19, 2014   01:27 AM PST
Just to mention: I faced twice errors when trying to open the documentation hyperlinks. I needed to repeat the steps but in another folder:


Hubert Huang
December 2, 2014   01:47 PM PST
I'm wondering why the LED width is 1e6 clk cycles. We set it or just the API makes it? And where I can get documents about drivers APIs? I can't understand why the third parameter in the function XGpio_DiscreteWrite stands for the duty_cycle width out to the PL GPIO peripheral.
Thank you for reading. My email is Welcome your email.
November 11, 2014   04:33 AM PST
"No axi_gpio" solved

You should not only delete standalone_bsp_0 but also hw_platform_0 has to be deleted before you generate new BSP.
November 3, 2014   01:23 AM PST
Hello, I have problem with GPIO driver. I tried to delete standalone_bsp_0 and make a new the same thing, but there's no any axi_gpio. Where's the problem? Also compilation is impossible because of error - xgpio.h:no such file or directory.
August 7, 2014   02:06 PM PDT
Sir Thank you, i followed what you have said, and the program worked,
Sir i want to know how to read and write to the DDR memory of the board.
Can you tell me how to do it?
Uzair Zaidi
June 6, 2014   12:26 PM PDT

I am also facing the same problem.
Can anyone tell me, how to resolve this problem?

But when i ran the following commands it works perfectly.

#echo 47 > /sys/class/gpio/export
#echo out > /sys/class/gpio/gpio47/direction
#echo 1 > /sys/class/gpio/gpio47/value
June 2, 2014   02:01 PM PDT

I have succesfully run gpio-demo program on zc702 board. Now I want to run the same board on microzed board.

I have succesfully access GPIO (lit LED#47) on microzed board as an standalone application, and now I am trying to access it from userspace in linux.

I have the BSP for microZed (created following your blog), and all my petalinux related commands are working perfectly fine.

I created BOOT.BIN and image.ub. And linux boots perfectly fine.

Once I get command prompt, I cd /bin:

root@Xilinx-ZC702-14_7:/bin# gpio-demo -g 47 -o 0
Failed to open /sys/class/gpio/gpiochip47/ngpio: No such file or directory
Failed to open /sys/class/gpio/gpiochip47/ngpio: No such file or directory

47 is the number of my LED on the board.

Then I looked in /sys/class/gpio/ and I found gpiochip0 , which indicates that GPIO_BASE is 0.

So I gave the command accordingly:

root@Xilinx-ZC702-14_7:/bin# gpio-demo -g 0 -o 1
Usage: gpio-demo [-g GPIO_BASE] COMMAND
where COMMAND is one of:
-i Input value from GPIO and print it
-o VALUE Output value to GPIO
-c Cylon test pattern
-k KIT test pattern
GPIO_BASE indicates which GPIO chip to talk to (The number can be
found at /sys/class/gpio/gpiochipN).
The highest gpiochipN is the first gpio listed in the dts file,
and the lowest gpiochipN is the last gpio listed in the dts file.
E.g.If the gpiochip240 is the LED_8bit gpio, and I want to output '1'
to the LED_8bit gpio, the command should be:
gpio-demo -g 240 -o 1

gpio-demo written by Xilinx Inc.

Why this error is coming?

Kindly help me.

(I have also asked this question in forum really appreaciate for your suggestions).

Leave a Comment:


Homepage (optional)


Previous Entry Home Next Entry