Introduction
The LEDs on the Hard Processor System (HPS) side of the Arria® 10 SoC Development Kit are connected via the SPIO Interface (operated by SPI commands from the SPI Master on the HPS side to MAX V). However, Linux has a spidev function called "spidev" that can be used to connect the LEDs.
However, Linux provides a device driver for SPI called spidev, which can be used for this purpose.
Linux Image to be used
Linux Image for Arria® 10 SoC included in SoC FPGA Embedded Development Suite (SoC EDS) v18.0 Standard Edition
C:\intelFPGA\18.0\embedded\embeddedsw\socfpga\ prebuilt_images\Arria10_Linux_SDCard.tar.gz
Sample code
https://elixir.bootlin.com/linux/v4.9.78/source/tools/spi
1. Write the SD card image contained in the SoC EDS to the SD
Extract the following SD Card Image with tar command and write it to SD Card with Win32DiskImager.
C:\intelFPGA\18.0\embedded\embeddedsw\socfpga\prebuilt_images\Arria10_Linux_SDCard.tar.gz
Extracting can also be done from Nios II Command Shell.
$ tar xvf Arria10_Linux_SDCard.tar.gz
Then use Win32DiskImager to write to the SD card.
2. Copy the sample code onto fat
Remove the SD card from the PC and make it look like a drive on the PC. Check if it looks like the following.
Copy the Makefile, spidev_fdx.c, and spidev_test.c files from the links below.
https://elixir.bootlin.com/linux/v4.9.78/source/tools/spi
In this case, I put them together in a folder called spi_test.
If you right-click to save the files, they will be saved in html format, so please copy them by creating a file and then copying and pasting it.
Then copy it to the SD card.
3. Replacing the device tree
Replace the device tree in the SD card with the attached socfpga_arria10_socdk_sdmmc.dtb.
The difference is left as a difference in the spidev.patch file, but since there is no spidev definition in the spi included in the SD card at
prebuild, it has been replaced.
@@ -883,23 +883,10 @@
rx-dma-channel = <0x1e 0x11>;
32bit_access;
- a10_sysctl@0 {
- compatible = "altr,a10sycon", "altr,a10sr";
+ spidev@0 {
+ compatible = "spidev";
reg = <0x0>;
- interrupt-parent = <0x1f>;
- interrupts = <0x5 0x8>;
- interrupt-controller;
- #interrupt-cells = <0x2>;
spi-max-frequency = <0xf4240>;
-
- gpio-controller {
- compatible = "altr,a10sycon-gpio", "altr,a10sr-gpio";
- gpio-controller;
- #gpio-cells = <0x2>;
- ngpios = <0x10>;
- linux,phandle = <0x25>;
- phandle = <0x25>;
- };
};
};
4. Boot with SD card and build the sample program
After booting, confirm that spidev is visible under /dev.
$ ls /dev | grep spidev
Mount the SD card and copy it to the home directory.
$ mkdir sd $ mount -t vfat /dev/mmcblk0p1 sd $ ls sd ghrd_10as066n2.core.rbf spi_test ghrd_10as066n2.periph.rbf zImage socfpga_arria10_socdk_sdmmc.dtb $ cp -r sd/spi_test . $ ls sd spi_test $ umount sd
Go to the copied spi_test folder and build the sample source.
Make sure you have spidev_fdx and spidev_test without extensions.
$ cd spi_test/ $ make gcc spidev_test.c -o spidev_test gcc spidev_fdx.c -o spidev_fdx $ spi_test# ls Makefile spidev_fdx spidev_fdx.c spidev_test spidev_test.c
5. Issue commands using spi_test
USAGE see print_usage in the following code:
https://elixir.bootlin.com/linux/latest/source/tools/spi/spidev_test.c
According to the User Guide of the Arria® 10 SoC Development Kit, when driving the HPS-side LED, the value to be written after Instruction Code 0x02 is specified in the upper 4 bits of the following 8-bit data.
Therefore, for example, to drive HPS LED 0 and 1, specify 0xC0.
HPS LED is Low Active, so it is lit with 0.
$ . /spidev_test -D /dev/spidev32766.0 -O -H -p "\x02\xC0" spi mode: 0x3 bits per word: 8 max speed: 500000 Hz (500 KHz) RX | 00 00 __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ | ..
Check the Arria® 10 SoC Development Kit after publishing and confirm that 0 and 1 of the HPS LEDs are lit.