• 0

Memory issues in Arty-7x Microblaze


Question

I'm working on some embedded software on the Arty board and programming in Microblaze. When I try to allocate an array of sixteen-bit numbers, length 512, it works just fine, but the same array set to length 1024 causes malloc to return NULL. After some experimentation and testing, I believe this is because the Microblaze processor has run out of internal memory. However, the Arty board is supposed to have 256MB of DDR memory. 

An interface to the memory already existed in my block diagram (copied from Getting Started With Microblaze with some PMods added), so I assumed that the DDR memory was already being used by the Microblaze processor, but 256 MB of memory shouldn't be struggling to deal with a 2KB array. (Outside of the allocated array, the program is very small.) Is there something special I need to be doing to access the DDR memory from inside Microblaze?

Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 0

@wanderso

When you run block automation in Vivado to connect the Microblaze to memory (Step 4.2 of the Getting Started Guide), you select how much local memory the microblaze has access to, I'm not sure how to check or change this after the fact. If you have the settings displayed in that step, you can increase your stack and heap significantly, just be aware that the program has to fit in that 32K as well (if I recall correctly). You would likely need to up the sizes to 4K apiece (0x8000), depending on where your array is being stored.

Alternatively, you could use the AXI BRAM Controller and Block Memory Generator IP cores to create some external memory, the interface should be fairly straightforward, and this is probably easier and safer, though the project may run a little slower. I'll attach some code and screenshots of how to quickly set this up.

#include <stdio.h>
#include "platform.h"
#include "xil_printf.h"
#include "xbram.h"
#include "xparameters.h"

int main()
{
	XBram bram;
	XBram_Config *pcfg;
    u32 i;
	init_platform();
    pcfg = XBram_LookupConfig(XPAR_AXI_BRAM_CTRL_0_DEVICE_ID);
    XBram_CfgInitialize(&bram, pcfg, pcfg->CtrlBaseAddress);

	while (1) {
		print("Any key to start test\n\r");
		inbyte();
		for (i=0; i<8000; i+=4)
			XBram_Out32(bram.Config.MemBaseAddress+i, i);
		for (i=0; i<8000; i+=4)
			if (i != XBram_In32(bram.Config.MemBaseAddress+i))
				xil_printf("error: data mismatch at %x\n\r", i);
		print("Test Complete\n\r");
	}
    cleanup_platform();
    return 0;
}

 

 

Hope this helps,

Arthur

bramblock.JPG

axi_bram_ctrl.JPG

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now