Linux application cannot read/write FPGA registers
Added by Mathew Jones almost 9 years ago
I am trying write a simple C application (for Linux on the MityDSP-L138 ARM) that can access registers within an LX16 FPGA image, which is yet to be implemented but I'd like to get the basics working for now with any of the CriticalLink FPGA images.
I want to prove that I can use the mmap mechanism to read/write to the FPGA but so far I've run into some issues.
For starters, both the examples 'fpgautil' and 'mmap_demo' try to open "/dev/0", which does not exist in the supplied Jan 2014 kernel/fs. I've changed both examples to access "/dev/mem".
'mmap_demo' outputs the following, and does not seem to enumerate any of the core ids as the code suggests:
Beginning mmap demo. Device DNA: 0x0000000000000000
For an 'fpgautil' read operation it outputs 0000 for any address I try, but I was expecting to be able to at least read the core ids.
The FPGA images I've tried are: "build_dvi_rev_c/IndustrialIO.bin", "build_lcd_rev_c/IndustrialIO.bin", and
also an in-house image. I can read registers from uBoot but not once Linux has started.
I'm using the MityDSP-L138 with LX16 FPGA and the FPGA images are from MDK_2014_01_13.
I've tried it when the FPGA is loaded from uBoot (from NAND Flash):
U-Boot > sf probe 0; sf read 0xc0700000 0x580000 0x170000; loadfpga 0xc0700000 0x170000 8192 KiB M25P64 at 0:0 is now current device Loading FPGA from 0xC0700000 with 0x170000 bytes Loading FPGA done Found Device ID 00-Base Module (01.01) at 66000000 [0]
For "build_lcd_rev_c/IndustrialIO.bin": I get:
Found Device ID 00-Base Module (01.01) at 66000000 [0] Found Device ID 23-ADS7843 Touch Screen (01.02) at 66000080 [1] Found Device ID 02-LCD Settings Controller (01.00) at 66000180 [3]
and from Linux ("build_dvi_rev_c/IndustrialIO.bin"):
# insmod /lib/modules/$(uname -r)/extra/fpga_ctrl.ko # echo 1 > /sys/devices/fpga_ctrl/cmd # echo 2 > /sys/devices/fpga_ctrl/cmd # cat industrialIO.bin > /sys/devices/fpga_ctrl/image # echo 3 > /sys/devices/fpga_ctrl/cmd fpga fpga_ctrl: Found Device ID 00-Base Module (01.01) at C6878000
For "build_lcd_rev_c/IndustrialIO.bin": I get
fpga fpga_ctrl: Found Device ID 00-Base Module (01.01) at C6878000 fpga fpga_ctrl: Found Device ID 23-ADS7843 Touch Screen (01.02) at C6878080 fpga fpga_ctrl: Found Device ID 02-LCD Settings Controller (01.00) at C6878180
Our Linux version is "3.2.0 #1 PREEMPT Mon Jan 13 11:06:16 EST 2014 armv5tejl GNU/Linux"
I notice that the load addresses(?) are different between uBoot and Linux.
Is there anything I'm missing?
Replies (2)
RE: Linux application cannot read/write FPGA registers - Added by Gregory Gluszek almost 9 years ago
Hi Matthew,
First we need to deal with the issue of /dev/0 not being present. Using /dev/mem is ultimately not what you want to do as you will run into caching issues.
/dev/0 is created after the FPGA is loaded and the device drives finds the base module. Have you checked that /dev/0 does not exist after you load the FPGA?
Thanks,
\Greg
RE: Linux application cannot read/write FPGA registers - Added by Mathew Jones almost 9 years ago
Hi Greg
Excellent, that has definitely helped as I can now see /dev/0 after the following two commands (with FPGA loaded from uBoot).
# insmod /lib/modules/$(uname -r)/extra/fpga_ctrl.ko # echo 3 > /sys/devices/fpga_ctrl/cmd
Now when I run 'mmap_demo' for lcd rev c 'IndustrialIO.bin' I get:
Beginning mmap demo. Device DNA: 0x0000000000000000 Found core at 0x4030b000 - ID: 0 Found core at 0x4030b080 - ID: 23 Found core at 0x4030b180 - ID: 2
I can also use 'fpgautil' to write and read from the base core 0 scratch ram area at 0x40-0x7f.
My problems arose because I was relying on uBoot to load the FPGA before Linux is booted, but I wasn't issuing command 3 to the fpga_ctrl driver.
Later on I was using the linux driver to load the FPGA but had previously changed 'mmap_demo' & 'fpgautil' to use /dev/mem, instead of /dev/0, which didn't work.
Thanks
Mat