Read/Write FPGA registers with C application

Applications, development tools, FPGA, C, WEB
Post Reply
Pauline
Posts: 5
Joined: Fri Mar 16, 2018 12:06 pm

Read/Write FPGA registers with C application

Post by Pauline » Fri Mar 16, 2018 12:27 pm

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!

Pauline
Posts: 5
Joined: Fri Mar 16, 2018 12:06 pm

Re: Read/Write FPGA registers with C application

Post by Pauline » Fri Mar 16, 2018 4:01 pm

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?

amike88
Posts: 78
Joined: Tue Mar 29, 2016 7:41 pm

Re: Read/Write FPGA registers with C application

Post by amike88 » Tue Mar 20, 2018 7:40 am

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.

Pauline
Posts: 5
Joined: Fri Mar 16, 2018 12:06 pm

Re: Read/Write FPGA registers with C application

Post by Pauline » Tue Mar 20, 2018 10:12 am

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?

amike88
Posts: 78
Joined: Tue Mar 29, 2016 7:41 pm

Re: Read/Write FPGA registers with C application

Post by amike88 » Tue Mar 20, 2018 4:17 pm

Yes I can confirm that your bit stream is correct if you can access the registers with monitor command.

Pauline
Posts: 5
Joined: Fri Mar 16, 2018 12:06 pm

Re: Read/Write FPGA registers with C application

Post by Pauline » Tue Mar 20, 2018 5:12 pm

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
You do not have the required permissions to view the files attached to this post.

Pauline
Posts: 5
Joined: Fri Mar 16, 2018 12:06 pm

Re: Read/Write FPGA registers with C application

Post by Pauline » Wed Mar 21, 2018 12:14 pm

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
You do not have the required permissions to view the files attached to this post.

Post Reply
jadalnie klasyczne ekskluzywne meble wypoczynkowe do salonu ekskluzywne meble tapicerowane ekskluzywne meble do sypialni ekskluzywne meble włoskie

Who is online

Users browsing this forum: Google [Bot] and 6 guests