matif
Occasional Contributor
6 years agoHow to use FPGA side SDRAM on Cyclone V SoC
Hi, There are two SDRAM (each of 1GB) on cyclone V SoC (Arrow Sockit Board (https://www.terasic.com.tw/cgi-bin/page/archive.pl?Language=English&CategoryNo=167&No=816)) (5CSXFC6D6F31C8ES), one for HPS and one on the FPGA side. I wana know how to use SDRAM on FPGA side. Is it possible to write to this SDRAM on fpga side from HPS? I made following system but when ever I try to execute my C program, it Stucks. Any help will be appreciated.
Here is my C code to HPS.
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdint.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "C:\altera\15.1\embedded\ip\altera\hps\altera_hps\hwlib\include\hwlib.h"
#include "C:\altera\15.1\embedded\ip\altera\hps\altera_hps\hwlib\include\soc_cv_av\socal\socal.h"
#include "C:\altera\15.1\embedded\ip\altera\hps\altera_hps\hwlib\include\soc_cv_av\socal\hps.h"
#include "C:\altera\15.1\embedded\ip\altera\hps\altera_hps\hwlib\include\soc_cv_av\socal\alt_gpio.h"
#include "D:\TestDesigns\SoCKit_DDR3_Nios_Test\hps_0.h"
#define REG_BASE 0xC0000000 /*AXI H2F SLAVE Address*/
#define REG_SPAN 0x00200000
volatile unsigned char *reg_addr; /*this is the pointer that reads from the register*/
void* virtual_base; /*pointer to open device memory file*/
int data[8];
int i;
int main ()
{
int fd = EXIT_FAILURE;
fd=open("/dev/mem",(O_RDWR|O_SYNC));
if (fd < 0) {
perror("open");
exit(EXIT_FAILURE);
}
printf("fd is ok\n");
virtual_base=mmap(NULL,REG_SPAN,(PROT_READ|PROT_WRITE),MAP_SHARED,fd,REG_BASE);
printf("virtual base pointer to open device memory file is ok\n");
reg_addr = (unsigned char *) (virtual_base+MEM_IF_DDR3_EMIF_0_BASE); /*accessing base address of register*/
for(i=0;i<8;i++)
{
data[i]=i+1;
*reg_addr=data[i];
reg_addr=reg_addr+1;
printf("//////////////////////////////\n");
}
for(i=0;i<8;i++)
{
printf("the output value from the SDRAM is %d\n",*reg_addr);
reg_addr=reg_addr-1;
printf("//////////////////////////////\n");
}
return 0;
}