2258432
Occasional Contributor
2 years agoHow to transfer data from FPGA to HPS DDR
Hi, I have two cyclone V soc boards, and I am working on a design to transmit video data generated from the FPGA side of the first board to the second board through HPS Ethernet, and finally display...
- 2 years ago
After testing, using the mmap function on the HPS side can read data from HPS DDR. I referred to https://github.com/zangman/de10-nano/blob/master/docs/FPGA-SDRAM-Communication_-Avalon-MM-Host-Master-Component-Part-3.md and used the mmap function to operate on HPS DDR, resulting in the same results as Zangman's.
In cycloneV soc(de10-nano), the starting address of HPS DDR is 0x0000000 and the ending address is 0x3FFFFFFF.
/* code for operating HPS DDR */ #include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <sys/mman.h> #define HPS_DDR_BASE 0x00000000 #define HPS_DDR_SPAN 0x40000000 #define HPS_AXI_BASE 0xC0000000 int main() { int fd; void *hps_ddr_base; void *h2f_base; int *addr1; int *addr2; // Open /dev/mem device fd = open("/dev/mem", O_RDWR | O_SYNC); if (fd == -1) { perror("could not open /dev/mem\n"); return 1; } hps_ddr_base = mmap(NULL, HPS_DDR_SPAN, PROT_READ | PROT_WRITE, MAP_SHARED, fd, HPS_DDR_BASE); h2f_base = mmap(NULL, 0x1000, PROT_READ | PROT_WRITE, MAP_SHARED, fd, HPS_AXI_BASE); if (hps_ddr_base == MAP_FAILED) { perror("could not mirror HPS DDR3 to user space\n"); close(fd); return 1; } // Write 0xAA to 0x20000000 addr1 = (int*)(hps_ddr_base + 0x20000000); *addr1 = 0xAA; // Write 0x1 to 0xC0000000 addr2 = (int*)(h2f_base); *addr2 = 0x1; // Unmap and close the /dev/mem device munmap(hps_ddr_base, HPS_DDR_SPAN); close(fd); return 0; }Thank you again for your help. Please close this thread, Adzim.
Regards.