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

Contact

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



Content

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
Introduction

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
Introduction
Table of contents
Leon3
MicroBlaze
OpenRISC 1200
Nios II

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

FPGA Design From Scratch
Started December 2006
Introduction
Table of contents
Index
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

CAD
A hardware designer's best friend
Zoo Design Platform

Linux
Installing Cobra Command Tool
A processor benchmark

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

Bicycling
Stockholm by bike

Running
The New York City Marathon

Skiing/Skating
Kittelfjall Lappland

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

Travel
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

Books
100 Power Tips for FPGA Designers

Favorites
Adventures in ASIC
ChipHit
Computer History Museum
DeepChip
Design & Reuse
Dilbert
d9 Tech Blog
EDA Cafe
EDA DesignLine
Eli's tech Blog
Embedded.com
EmbeddedRelated.com
FPGA Arcade
FPGA Blog
FPGA Central
FPGA CPU News
FPGA developer
FPGA Journal
FPGA World
Lesley Shannon Courses
Mac 2 Ubuntu
Programmable Logic DesignLine
OpenCores
Simplehelp
SOCcentral
World of ASIC



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



rss feed



 
Saturday, November 12, 2011
FPGA design from scratch. Part 78

Writing and debugging an application program

Let's write a program that is doing some useful stuff. We will calculate all  prime numbers between 1 and 1000. We change the HelloWorld program to look like this:

#include "stdio.h"

int main(int argc, char *argv[])
 {

    int i;
    int num = 1;

    printf(" Calculate all prime numbers between 1 and 1000 ");

    while(num <= 1000) {
      i=2; 
      while(i<=num) {
          if(num%i==0)
          break;
          i++; }

      if(i==num)
      printf(" %d is a prime number",num);
      num++;
 }

return 0;

}


Compile and build the application

We compile the program and build the new image using the predefined makefiles

--> $PETALINUX/software/petalinux-dist

--> make

Testing the application

After building a new image we test our application in the emulator.

--> petalinux-qemu-boot 

This is what the beginning of printout looks like when executing the HelloWorld application.




Debugging our application with GDB

PetaLinux supports GDB to debug user applications. This section described the basic debugging procedure. For more information see the GNU website.

Prepare the build system for debugging

We will change the user application Makefile to disable compiler optimizations. Compiler optimizations make debugging difficult because the compiler can re-order or remove instructions that do not impact the program result.

Add the following line to the user Makefile to disable compiler optimization:

'CFLAGS += O0

Here is an example from the MakeFile.


Preparing the application for debugging

Change to the $PETALINUX/software/petalinux-dist directory and run appconfig.

--> $PETALINUX/software/petalinux-dist

--> make appconfig

Scroll down to debugging.




Select the debugging sub-menu and ensure that:

  • build debugable libraries
  • build debugable applications
  • gdbserver

are all selected.




Exit appconfig and select <Yes> to save the configuration.


Rebuild the PetaLinux image.

In the directory $PETALINUX/software/petalinux-dist run the following commands:

--> make userapps/HelloWorld_clean

--> make userapps/HelloWorld_only

--> make userapps/HelloWorld_romfs

--> make image



Performing a debug session

Boot the board with our new image using the emulator (QEMU). Run gdbserver with the application on the PetaLinux console:




1234 is the gdbserver port, it can be any unused port. On the workstation navigate to the user application directory and start the gdb client.

--> cd $PETALINUX/software/user-apps/HelloWorld

--> microblaze-unknown-linux-gnu-gdb HelloWorld




The GDB debugging source window will open.




Target settings

Select File-> Target Settings. In the Target settings choose the following settings.




To find the Hostname execute the follow command in the PetaLinux console:




Setting breakpoints

In the GDB "Source Window", set Breakpoints in the source by clicking the mouse at the beginning of the line of the source code. Lines that are "breakable" are shown by '-' on the left most column. The window above shows a breakpoint set on the first line of the main function, and indicated by a red square icon.

Running the program

Run the program by clicking the run icon at the left corner of the tool bar. GDB will connect to the gdbserver running on the target, and run the program until the first breakpoint is reached. 




Here is the message displayed on the target console.




Stepping the program

Use the step, next and continue GDB commands by clicking the icons next to the run icon.




Finishing the debug session

When the program finishes, the GDB server application on the target system will exit displaying the following message.




Top  Previous Next



Posted at 12:37 by

 

Leave a Comment:

Name


Homepage (optional)


Comments




Previous Entry Home Next Entry