Write and run applications on the PYNQ board
In this tutorial you will learn how to write and run an application on the PYNQ board.
We demonstrate how to write and run a general C program that doesn't use the PYNQ board's special features such as LEDs, buttons, etc. We will show how to do this using Visual Studio Code, MobaXTerm, and ssh. In essence, this is like programming on your laptop or any other computer.
The basic steps are:
- connect the PYNQ board and log in (using Visual Studio, MobaxTerm, or ssh).
- create and edit a file (the C program)
- compile the C program to create an executable
- run the executable
- fix any errors in your program ("debugging")
- copy your program to your laptop, for example to submit your homework.
The PYNQ board runs the Linux operating system. In Steps 3-4 we will use the terminal, which allows you to give commands for the Linux operating system. We will introduce the Linux commands that we need as we go along; an overview is given on the introduction to Linux page.
Step 1. Connect to the PYNQ board
- Connect all cables and switch on the PYNQ board..
- Start Visual Studio Code, MobaXterm, or ssh and log in to the PYNQ board.
- Open a terminal on the PYNQ board.
Step 2. Write & run a C program
2.1 Using Visual Studio Code menus
-
Create a new file called hello.c in the home directory (/home/student). (Left-click in the Explorer pane to bring up the menu.)
Click "Install" if you get the pop-up
You can close the tab when the extension has installed. 2. Type in the program, then open the Terminal tab and type the commands
2.2 Using the terminal in Visual Studio Code (or MobaXterm or ssh)
- Edit a new file called
hello.c
in the PYNQ home directory/home/student
. When using ssh you have to edit using a Linux editor such as nano (or vi if you have Linux experience). - Type in the following (or copy and paste):
- Save the program (it depends on your editor how to do this).
-
The Linux
ls
command lists all the files in the directory. Runls
in the terminal:hello.c
should be listed. (The other files may or may not be there; that depends on the SD-card image).ℹ️ Information See the Linux page for an overview of commands such as
ls
. -
Type
cat hello.c
ormore hello.c
to show the program on the terminal. - Compile the C program to create an executable by typing
gcc hello.c -o hello
in the terminal. - If you get an error, then edit your C program and double check that it is correct.
- Type
ls
again to check that the executable (calledhello
) is in the directory. - Execute the program by typing
./hello
. The output should beHello on the PYNQ!
).
3. Keep programming
- Congratulations! You've written and run your first program.
- You can download the C program to your computer, for example if you need to submit it as homework, by right-clicking on hello.c in the Explorer:
- You can keep programming!
- When you have finished you must safely shut down the the PYNQ board.
4. Using the PYNQ board hardware (input/output)
See the libpynq for C programming page for how to install and use the libpynq
library to access the PYNQ board's input/output.
5. Shut down and disconnect the PYNQ board
Always safely shut down and disconnect your PYNQ board to avoid corruption of the SD card and data loss.