Search code examples
fpgaintel-fpga

How to read data from FPGA on HPS side


I am a novice. I have a cyclone V board. I have generated several 32-bit ASCII codes through verilog on the FPGA side. I want to send them to the HPS side through the H2F AXI bus and program the HPS side to read them. . I connected the FIFO and H2F AXI bus as shown in the picture, I don't know if such connection is correct.

Can someone give me some idea, any help would be greatly appreciated.

I wrote preloader, u-boot, device tree file, rbf file, and linux kernel to sd card, but I don't know what to do next.


Solution

  • Use address mapping on the HPS side to read data. qsys

    /* Code for reading data on HPS side */
    #include <stdio.h>
    #include <fcntl.h>
    #include <sys/mman.h>
    #include <stdint.h>
    #include <unistd.h>
    
    
    #define HW_REGS_BASE (0xC0000000)
    #define HW_REGS_SPAN (0x04000000)
    #define ALT_H2F_OFST  (0xFF500000)
    #define HW_REGS_MASK (HW_REGS_SPAN - 1)
    #define LED_PIO_OFFSET (0x00000408)
    
    int main()
    {
    int fd;
    void *h2f_axi_base;
    void *led_pio_addr;
    
    
    fd = open("/dev/mem", O_RDWR | O_SYNC);
    if (fd == -1) {
        perror("could not open /dev/mem\n");
        return 1;
    }
    
    
      h2f_axi_base = mmap(NULL, HW_REGS_SPAN, PROT_READ | PROT_WRITE, MAP_SHARED, fd, HW_REGS_BASE);
    if (h2f_axi_base == MAP_FAILED) {
        perror("could not mirror the H2F AXI address\n");
        close(fd);
        return 1;
    }
    
    
    led_pio_addr = h2f_axi_base + ( ( unsigned long ) (ALT_H2F_OFST+LED_PIO_OFFSET) & (unsigned long ) (HW_REGS_MASK) );
    
    
    while (1) {
    
        uint32_t data = *((volatile uint32_t *)led_pio_addr);         
        printf("read data:   %x\n", data);
        usleep(10000);
    
       
    }
    
    munmap(h2f_axi_base, HW_REGS_SPAN);
    close(fd);
    
    return 0;
    }