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.
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:~#
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.
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.
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".)
For the time being, that's all.
Recommended Posts