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!

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Voyager
Voyager
3,018 Views
Registered: ‎06-26-2015

AXI BRAM write/read

Jump to solution

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?

0 Kudos
1 Solution

Accepted Solutions
Voyager
Voyager
5,258 Views
Registered: ‎06-24-2013

Re: AXI BRAM write/read

Jump to solution

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!
5 Replies
Explorer
Explorer
3,015 Views
Registered: ‎04-05-2016

Re: AXI BRAM write/read

Jump to solution

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.

 

 

 

0 Kudos
Voyager
Voyager
5,259 Views
Registered: ‎06-24-2013

Re: AXI BRAM write/read

Jump to solution

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
Voyager
2,991 Views
Registered: ‎06-26-2015

Re: AXI BRAM write/read

Jump to solution
yep gotta it working.

if I have axi_dma, how do I access it? this is on zynq petalinux
0 Kudos
Moderator
Moderator
2,926 Views
Registered: ‎09-12-2007

Re: AXI BRAM write/read

Jump to solution
Newbie curious
Newbie
526 Views
Registered: ‎09-17-2018

Re: AXI BRAM write/read

Jump to solution

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,

 

0 Kudos