Re Report HPS UpdatedJan2021
Re Report HPS UpdatedJan2021
Re Report HPS UpdatedJan2021
PART 1 ABSTRACT
PART 2 GENERATE QUARTUS PROJECT
2.1. Generate using DE-10 System Builder
2.2. Building QSYS
2.2.1. Generate HPS
2.2.2. New Component
2.2.3. A complete QSYS Schematic
2.3. FPGA Synthesis and Compile
PART 3 PREPARE LINUX SD CARD
3.1. Linux SD Card Check List
3.2. Write Linux Boot Image
3.2.1. Write Linux Boot Image
3.2.2. Boot HPS System
3.3. Convert FPGA Programming File
3.4. Prepare Software Headers
3.4.1. Generate qsys_hps header
3.4.1 Locate HWLIB system header
Builded Qsys
When we complete our Qsys configuration, choose Generate HDL and then Finish.
In this project we connect h2f_axi_master to a 7 segment display and the lightweight bridge
controls 4 leds.
2.3. FPGA Synthesis and Compile
Add Synthesize Files:
In order to compile the previously built qsys in fpga project, add synthesized system file ‘.qip’
and qsys instantiation file ‘.v’ that is available at <qsys folder> /synthesis.
Step 1
Write instantiations:
Run Synthesis
After the netlist is synthesized, the project now can identify the HPS. For backend script, run
TCL script by going to ‘Tools > TCL Scripts’ menu. Only run the two .tcl files in the red box.
First of all, we have to have a clean SD Card by using ‘SD Card Formatter’ and choose quick
format.
SD Card Formatter interface
Then we load the boot image by the suitable version of Linux to the kit by Win32 Disk Imager.
Choose the Disk of the SD, which is D in my laptop. We also have to choose the .img file
which is the DE10_Standard_Angstrom_console.img and write to the SD card.
Angstrom Console for DE10
Since HPS will execute our program, we have to convert the .sof file to .rbf ( Raw Binary File)
in order to embedded the code to the HPS. We go to File > Convert Programming File, fill in
the template below and click Convert. After the .rbf file is generated, copy it to SD Card.
Converter interface
! Please rename your .rbf file to soc_system.rbf , which the Linux Kernel will
automatically load during booting.
3.4. Prepare Software Headers
Starting from this point, users are recommended to use Embedded Development Suite for SoC-
FPGA.
After Qsys is generated, we generate a library for headers called hps_0.h from .sopcinfo file.
The generater_hps_header.sh can be created using text file, or provided at
“<DE10_Standard>/DE10_Standard/Demonstration/SoC_fpga/”
This header file is derived directly from the previously built qsys. It contains addresses of
created blocks and crucial information about the system that will be used later on in this project.
In order the this demonstation to work correctly, please change user-define Quartus II directory
and the name of the ‘created project’.socpcinfo
\
generate_hps_qysy_header.sh file for generating Qsys header
The written generate_hps_qsys_header.sh should be placed in the same directory as the ‘.qsys’
and ‘.socpcinfo’ files
The start EDS and go to qsys directory
@EDS$ cd /cygdrive/d/cuong/Quartus/Project/fp_adder_test_1/qsys
@EDS$ ./generate_hps_qsys_header.sh
EDS would return the following line if the header is generated successfully
In order to support for HPS programming, we need to have hwlib which provides us the
addresses of bridges and system functions that required in our project such as Lightweight.
This library is optional, but it is recommended because it includes address of Avalon, AXI
bridges and sends warnings and stoppages if user tries to access an illegal memory block.
We can find this hwlib folder:
<SoC EDS installation path>\embedded\ip\altera\hps\altera_hps>.
Verify the content of our hwlib:
Because our device is Altera Cyclone V, we only focus on our header folder ‘soc_cv_av’ which
has headers for our current project.
header files in folder soc_cv_av
The folder soc_cv_av refers to ‘System on Chip Cyclone V Avalon”, this library indicates the
OS the device being configured.
Please refer to tar.gz compression to emerge this library from PC to SoC-HPS.
@EDS$ cd /cygdrive/d/cuong/Quartus/embedded\ip\altera\hps\altera_hps
@EDS$ tar –czvf hwlib.tar.gz hwlib
Makefile’s content
The name of our generated file will be the TARGET’s name. Our CROSS_COMPILE, which
allows us to access external devices and system registers as a developer instead of MinGW that
limits our access, is changed to arm-angstrom-linux-gnueabi-.
Main.c
3.2. Open bridges by mmap:
4. How mmap helps us access the bridges
Main c:
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <stdint.h>
#include "hwlib.h"
#include "socal/socal.h"
#include "socal/hps.h"
#include "socal/alt_gpio.h"
#include "hps_0.h"
int main()
{
int fd;
void *virtual_base, *master_base;
int loop_count;
void *leds_addr;
volatile uint32_t* hex7_addr;
int counter = 0;
printf("\n");
printf("1.PROGRAM START\n");
printf("2\n" );
// map the address space for the LED registers into user space so we can interact with
them.
// we'll actually map in the entire CSR span of the HPS since we want to access various
registers within that span
if ((fd = open( "/dev/mem" , (O_RDWR | O_SYNC))) == -1)
{
printf( "ERROR: could not open \"/dev/mem\"...\n");
return -1;
}
if (virtual_base == MAP_FAILED)
{
printf("ERROR: mmap() failed...\n");
close(fd);
return -1;
}
if (master_base == MAP_FAILED){
printf("ERROR: mmap() failed @ H2F_master..\n");
close(fd);
return -1;
}
printf("4\n");
*(hex7_addr) = 0x05;
// Toggle the LEDs in a counting pattern
while (loop_count < 60)
{
printf("5\n");
printf("6\n");
// Wait 1s
usleep(1000 * 1000);
close(fd);
return 0;
}