Forum Discussion
How to transfer data from FPGA to HPS DDR
- 3 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.
Hi,
Thanks again for your help. I would like to ask another question, how to read data from HPS DDR on the HPS side? Can I use the mmap function to do this? If possible, I don't know the mapping address for HPS DDR. In https://www.intel.com/content/www/us/en/programmable/hps/cyclone-v/hps.html , I didn't find the address for HPS DDR.
regards.
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.