UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

Reply

AXI BRAM write/read

Accepted Solution Solved
Highlighted
Voyager
Posts: 288
Registered: ‎06-26-2015
Accepted Solution

AXI BRAM write/read

is there example c code on how to access PL Bram via axi bram controller?  I don't have to malloc, just write to the bram address?


Accepted Solutions
Voyager
Posts: 1,779
Registered: ‎06-24-2013

Re: AXI BRAM write/read

Hey @s002wjhw

 

is there example c code on how to access PL Bram via axi bram controller?

 

Something like this should work:

        int fd = open("/dev/mem", O_RDWR | O_SYNC);
        .... error checks ...        
        
        void *base = mmap(BRAM_ADDR, BRAM_SIZE,
            PROT_READ | PROT_WRITE, MAP_SHARED,
            fd, NULL);
        .... error checks ...        

I don't have to malloc, just write to the bram address?

You need to map the memory region, then you can access it like normal memory.

 

Hope this helps,

Herbert

-------------- Yes, I do this for fun!

View solution in original post


All Replies
Explorer
Posts: 152
Registered: ‎04-05-2016

Re: AXI BRAM write/read

Are you interfacing to the BRAM controller via MicroBlaze?  if so, then yes, you just have to read/write from the address using the Xilinx helper Macros:

 

 

#include "xil_types.h"
#include "xil_io.h"
#include "xil_printf.h"

#include <inttypes.h>

#define MY_PERIPHERAL_BASE_ADDRESS 0x43000000

int main()
{
    const uint32_t value = 0xDEADBEAF;
    uint32_t response;

    xil_printf("Writing to BRAM ... ");
    Xil_32Out(MY_PERIPHERAL_BASE_ADDRESS, value);
    xil_printf("Done.\r\n);

xil_printf("Reading from BRAM ... "); response = Xil_32In(MY_PERIPHERAL_BASE_ADDRESS); xil_printf("Done.\r\n); if ( response == value ) xil_printf("SUCCESS!\r\n); else xil_printf("ERROR!!\r\n); return 0; }

 

Note: I did not compile the above code, it is intended as a reference only.

 

You can get the address of your block ram controller via the addresses tab in Vivado when the block diagram is open, or from xparameters.h, which is generated inside of the BSP that accompanies your application project in SDK.

 

 

 

Voyager
Posts: 1,779
Registered: ‎06-24-2013

Re: AXI BRAM write/read

Hey @s002wjhw

 

is there example c code on how to access PL Bram via axi bram controller?

 

Something like this should work:

        int fd = open("/dev/mem", O_RDWR | O_SYNC);
        .... error checks ...        
        
        void *base = mmap(BRAM_ADDR, BRAM_SIZE,
            PROT_READ | PROT_WRITE, MAP_SHARED,
            fd, NULL);
        .... error checks ...        

I don't have to malloc, just write to the bram address?

You need to map the memory region, then you can access it like normal memory.

 

Hope this helps,

Herbert

-------------- Yes, I do this for fun!
Voyager
Posts: 288
Registered: ‎06-26-2015

Re: AXI BRAM write/read

yep gotta it working.

if I have axi_dma, how do I access it? this is on zynq petalinux
Moderator
Posts: 1,157
Registered: ‎09-12-2007

Re: AXI BRAM write/read

Newbie
Posts: 1
Registered: ‎09-17-2018

Re: AXI BRAM write/read

Hi Hey @s002wjhw,

We tried using mmap.

Code runs without any error, but I do not see any change in LUT values (in fact it is always 0).

I am not sure, what I might be doing wrong. Do you have any suggestions as you seem more experienced than I.

 

Many thanks,