Page 1 of 1

Read/Write FPGA registers with C application

Posted: Fri Mar 16, 2018 12:27 pm
by Pauline
Hello, I'm a beginner on the Red Pitaya and I'm not familiar with C programming. I added a custom IP AXI slave in the FPGA with some registers (this part is correct, I made cat /opt/redpitaya/fpga/xxxx.bit > /dev/xdevcf on the board to configure FPGA with the right bitstream). I'm now trying to make a basic program in C to write and read values in registers but I've always the same issue: segmentation fault.

This is the code in C:

Code: Select all

#include <stdio.h>
#include "xil_io.h"

int main (void)
{
	int tmp = 0;
	Xil_Out32(0x43C00000,0x000000AA);
	tmp = Xil_In32(0x43C00000);
	printf("Reg1=%08X\n\r,tmp);
	
	return 0;
}
I also tried to use u32 type for tmp, it was the same problem.

Do you have any idea about how to fix this issue?
Thank you in advance for your help!

Re: Read/Write FPGA registers with C application

Posted: Fri Mar 16, 2018 4:01 pm
by Pauline
I tried to change some settings in Xilinx SDK (BSP...) and now it's not "Segmentation fault" anymore but "Illegal instruction". Do you know where is the issue?

Re: Read/Write FPGA registers with C application

Posted: Tue Mar 20, 2018 7:40 am
by amike88
Hey, I am not a software engineer so I do not have a solution for you, but take a look at this example over here.

You might be able to figure it out.

Re: Read/Write FPGA registers with C application

Posted: Tue Mar 20, 2018 10:12 am
by Pauline
Hey, thank you very much for your answer! I'll try it and tell you if I find a solution. I asked myself if I didn't have an issue with the bitstream and if I really had read/write access to registers. As I can read/write in these registers with "monitor" command in Linux terminal, I suppose my bitstream is correct, right?

Re: Read/Write FPGA registers with C application

Posted: Tue Mar 20, 2018 4:17 pm
by amike88
Yes I can confirm that your bit stream is correct if you can access the registers with monitor command.

Re: Read/Write FPGA registers with C application

Posted: Tue Mar 20, 2018 5:12 pm
by Pauline
Thank you for your answer, it confirms it's a software issue (you can see below the monitor commands performed before and after bitstream loading)
monitor_avant_apres.PNG
I tried to create a SDK project again from the example you sent to me, but I still get "segmentation fault"

Here's the error given by gdb:
"Program received signal SIGSEGV, Segmentation fault
0xb6fd9dde in ?? () from /lib/ld-linux-armhf.so.3"
gdb_seg_fault.PNG

Re: Read/Write FPGA registers with C application

Posted: Wed Mar 21, 2018 12:14 pm
by Pauline
Can it be related to the linker tool? My register appears correctly in .hdf file I used to create BSP, but when I open "Generate Linker Script", only Hardware Memory Map appears and nothing about registers. Is there a way to create links for registers? I'm not familiar at all with Xilinx SDK so I don't know all the tools.
Thank you in advance for your help and have a good day!

Here's the .hdf file:
reg_plage_addr_axi_rc.PNG
And linker script view:
linker_script.PNG