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
Changes and updates
Zynq-7000 All Programmable SoC
ZedBoard and other boards
Computer platform and VirtualBox
Installing Ubuntu
Fixing Ubuntu
Installing Vivado
Starting Vivado
Using Vivado
Lab 1. Create a Zynq project
Lab 1. Build a hardware platform
Lab 1. Create a software application
Lab 1. Connect to ZedBoard
Lab 1. Run a software application
Lab 1. Benchmarking ARM Cortex-A9
Lab 2. Adding a GPIO peripheral
Lab 2. Create a custom HDL module
Lab 2. Connect package pins and implement
Lab 2. Create a software application and configure the PL
Lab 2. Debugging a software application
Running Linux from SD card
Installing PetaLinux
Booting PetaLinux
Connect to ZedBoad via ethernet
Rebuilding the PetaLinux kernel image
Running a DHCP server on the host
Running a TFTP server on the host
PetaLinux boot via U-boot
PetaLinux application development
Fixing the host computer
Running NFS servers
VirtualBox seamless mode
Mounting guest file system using sshfs
PetaLinux. Setting up a web server
PetaLinux. Using cgi scripts
PetaLinux. Web enabled application
Convert from VirtualBox to VMware
Running Linaro Ubuntu on ZedBoard
Running Android on ZedBoard
Lab2. Booting from SD card and SPI flash
Lab2. PetaLinux board bringup
Lab2. Writing userspace IO device driver
Lab2. Hardware debugging
MicroZed quick start
Installing Vivado 2014.1
Lab3. Adding push buttons to our Zynq system
Lab3. Adding an interrupt service routine
Installing Ubuntu 14.04
Installing Vivado and Petalinux 2014.2

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

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 svenand

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