SoC FPGA: A small story when using on Linux

Introduction

I would like to write a small story when using an FPGA with an ARM CPU and FPGA on one chip on Linux. I hope to gradually increase the number of useful tools and useful tips in the future.

This is mainly about developing Hardware/Software using a board with Intel® Cyclone V SoC FPGA. I am using a board called Terasic DE10-nano.

memtool It is an application (utility) that can read and write Register/Memory of a physical address by specifying it. You need root privileges to use it, but you can access it from any physical address, and of course you can read/write Register and Memory created in the FPGA. With this, you can already access the FPGA circuit as if it were a Baremetal (OS less environment). There is no need to create a Device Driver for a small FPGA circuit.

To get it, download the C source from this memtool link and compile it with the gcc compiler. (If you search for "memtool" on the internet, you will find multiple types of "memtool" other than the above links. It seems that the usage is slightly different, but please use the one you like.) For ARM Linux with gcc

gcc -o memtool memtool.c

For cross-compilation on x86PC, compile with arm-linux-gnueabihf-gcc. Copy the generated memtool file to/usr/local/bin on your SD card's Linux filesystem. You are now ready to use memtool. The basic usage is

memtool <physical address of target(Hexadecimal)> <Number of words> #READ access
memtool <physical address of target(Hexadecimal)>=<data(Hexadecimal)> #WRITE access

is. Add = immediately after the address to execute Write access, and space to execute Read access. The data width of access is 32 bits by default, but you can access the data width in 8 bits and 16 bits by adding the -8 and -16 options. The address and data you enter are interpreted as hexadecimal with or without 0x.

memtool specific example

Here's an example of running on a DE10-nano booted using the "Linux LXDE Desktop (kernel 4.5)" SD card image in the DE10-Nano Kit Resources page on the Terasic site. The FPGA design (RBF file) for this SD card image is from the Demonstrations/SoC_FPGA/ControlPanel in the archive "DE10-Nano CD-ROM (rev. C Hardware)" also in Terasic's DE10-Nano Kit Resources page (https://www.terasic.com.tw/cgi-bin/page/archive.pl?Language=English&CategoryNo=167&No=1046&PartNo=4)./Quartus is the project file.

__ Read 2 words from physical address 0xFF201000: __ memtool ff201000 2 The 0xff201000 has a System ID IP and is reading the value 0xACD51302 that was set during the design.

root@DE10_NANO:~# memtool ff201000 2
Reading 0x2 count starting at address 0xFF201000

0xFF201000:  ACD51302 5FC6E9D0

By the way, the second value, 58D36B67, indicates the Unix time when this design was generated (System ID IP specification). If you decipher it with the date command, you can see that the design was generated in March 2017.

root@DE10_NANO:~# date -d @$((0x58D36B67))
Thu Mar 23 06:29:59 UTC 2017
root@DE10_NANO:~#

continue, __ Write 0x00000000 / 0x000000FF to physical address 0xFF203000: __ memtool ff203000 = 0 Since the PIO IP connected to the LED is assigned to 0xff203000, the LED can be turned ON/OFF.

root@DE10_NANO:~# memtool ff203000=0
Writing 32-bit value 0x0 to address 0xFF203000
root@DE10_NANO:~# memtool ff203000=ff
Writing 32-bit value 0xFF to address 0xFF203000
root@DE10_NANO:~#

memtool reference application

Also, this source code will be very helpful when creating your own app that accesses FPGA registers. The point is to open () and mmap ()/dev/mem. One thing to keep in mind is that the arguments you pass to mmap must specify a physical address that is an integral multiple of 4Kbyte and a size that is an integral multiple of 4Kbyte.

Precautions when using memtool

Some addresses in the HPS register space are not even allowed to read (some addresses will cause the CPU to stop if accessed incorrectly). Check the register map to see if the address can be read or written before accessing it.

Fixed Ethernet MAC address

As with the DE10-nano, most development boards do not have a fixed MAC address. If you use the board on Linux, the MAC address will generate a random local MAC address at boot time and will be used. If you use this in a DHCP environment, it may be inconvenient to assign a different IP address because the MAC address will be different each time you restart the board (in my case, my home DHCP server (router)). I have had a painful and angry experience with my family when I used up my IP address and my smartphone couldn't be used with wifi). Since then, I've been trying to fix (or specify) the MAC address with uboot. In the uboot/Linux combination used by SoC FPGAs, if you assign a MAC address to an environment variable called ethaddr in uboot, this will be set to the MAC address in Linux. At the uboot prompt

setenv ethaddr xy:xx:xx:xx:xx:xx 
saveenv

Is set. For the address to be set, it is safe to copy the value automatically generated by Linux first and use that MAC address from the second and subsequent boots. (Because it is his local MAC address of unicast, bit-1 of the first 8 bits of 6 digits must be "1" and bit-0 must be "0".)

in conclusion

For the time being, that's all.

Recommended Posts

SoC FPGA: A small story when using on Linux
A addictive story when using tensorflow on Android
A swampy story when using firebase on AWS lamda
What I stumbled upon when using CodeIgniter on a Linux server
intel Atom (notebook) Frequent petit freezes when using linux on a PC.
Troublesome story when using Python3 with VScode on ubuntu
A story about a Linux beginner putting Linux on a Windows tablet
The story when I was using IntelliJ on Linux and could not input Japanese
Small speedup when using pytorch
[Linux] A story about mounting a NAS through a firewall using NFS
A story that stumbled when using pip in a proxy environment
Install Linux (CentOS) on your PC using a USB stick
The story that a hash error came out when using Pipenv
Install Arch Linux on DeskMini A300
A note I was addicted to when making a beep on Linux
Run a Linux server on GCP
Create a Linux environment on Windows 10
Using a serial console on Ubuntu 20.04
A note on using tab completion when running Python interactively on Windows
A story about using Python's reduce
A story I was addicted to trying to install LightFM on Amazon Linux
A story about deploying a Twitter-linked app created using Flask + gunicorn on Heroku
Knowledge when making a bot using discord.py
Build a simple WebDAV server on Linux
Make Unity Accelerator a service on Linux
A struggle when installing pyenv on Cygwin
Notes on using OpenCL on Linux on the RX6800
Build a Samba server on Arch Linux
Create a Linux virtual machine on Windows
Error, warning when using TensorFlow on Mac
A story about a 503 error on Heroku open
[Linux] Let's talk about when I stumbled upon a symbolic link I was using.
Linux Ubuntu16.04 I got a little scary error when I ran a command using sudo
CPU usage is 100% when using pygame on Ubuntu 16.04
A story about simple machine learning using TensorFlow
Open a ZIP created on Windows in Linux
Try using a QR code on a Raspberry Pi
A story about displaying article-linked ads on Jubatus
Start a process with a scheduling policy on Linux
A story about running Python on PHP on Heroku
Try to create a new command on linux
A story when a Python user passes a JSON file
Create a GUI on the terminal using curses
A story that got stuck when trying to upgrade the Python version on GCE
The world changed when I opened a big Python project (Django) on Sourcetrail (Linux)
A little trick to know when writing a Twilio application using Python on AWS Lambda
What to do if you get the error ʻERR_FEATURE_UNAVAILABLE_ON_PLATFORM` when using ts-node-dev on Linux