cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Anonymous
Not applicable
11,732 Views

Program location in DDR3 memory

Jump to solution

Hi,

 

I program the FPGA through SDK into a bootloop and then start my program with the "Run" button. Is there any way of setting/knowing where the program will be loaded into the DDR3 memory? I have 512 mb of DDR3 and I trying to use it for my application but during the initialization when I initialize a memory segment to zero, my program crashes.

 

I assumed that the program would be loaded at the baseaddress so I left set an offset of a power of two greater than the program size, but this didnt work. Additionally i tried initializing only a small section of DDR3 memory closer to the highaddress, but this also didnt work.

 

Thanks,

Donny 

0 Kudos
1 Solution

Accepted Solutions
Anonymous
Not applicable
17,797 Views

I found the cause of my problem and I just wanted to share it if anyone else has similar issues. 

 

For some reason EDK had defined the wrong memory module which resulted in incorrect usage of the memory. It worked for the limited address that the EDK set memory module with the actual module. This probably happened because the ML605 board I was using comes in a few revisions depending on the time of purchase. It seems that the original project which I created in ISE 13.7 used the revision C ML605 board while the later projects were based on the ML605 revision E board.

 

Be sure to check the board revision!!!

View solution in original post

0 Kudos
11 Replies
muzaffer
Teacher
Teacher
11,681 Views
Registered: ‎03-31-2012
why do you care where your program resides? It seems that you want to use the rest of the memory. the libraries generated by the sdk should know that. why don't you call malloc with the size you want and see if you can use the returned memory.
- Please mark the Answer as "Accept as solution" if information provided is helpful.
Give Kudos to a post which you think is helpful and reply oriented.
0 Kudos
Anonymous
Not applicable
11,653 Views

Thank you for your responce,

 

Does malloc allow for large memory allocation? I need as much memory as possible for storage or processed data before it is sent out. 

 

Donny

0 Kudos
muzaffer
Teacher
Teacher
11,608 Views
Registered: ‎03-31-2012
I think you should try it out and see how much memory you can allocate. Writing a small program to test wouldn't have taken much longer than writing that post asking if it would work.
- Please mark the Answer as "Accept as solution" if information provided is helpful.
Give Kudos to a post which you think is helpful and reply oriented.
0 Kudos
Anonymous
Not applicable
11,553 Views

I get the same problem. If i try to allocate more than 64 Mb, the program crashes. 

 

How does the microblaze treat the DDR3 memory, does it seperate it by the size of each physical chip on the memory stick?

0 Kudos
morgan198510
Voyager
Voyager
11,480 Views
Registered: ‎04-21-2014

"Is there any way of setting/knowing where the program will be loaded into the DDR3 memory?"

 

Yes.  In the SDK, look at your lscript.ld file, which you can edit.  You can also control the amount of memory available for malloc here (change the heap size).  You can also change the amount of memory you have for your stack too.  If you want to reserve a section of the DDR, so that you can just point a pointer to it, reduce the size of the DDR from 0x20000000 to something smaller, and then add a new memory section with the "Add Memory..." button.  You can also sub-partition your memory and assign your heap (or any other section) to a specific address.

 

This is how to do that...not saying it is a good or bad idea. 

 

It is a very good idea, however, to understand what a linker does, and the linker script.

 

***Many of us who help you are just FPGA enthusiasts, and not Xilinx employees. If you receive help, and give kudos (star), you're likely to continue receiving help in the future. If you get a solution, please mark it as a solution.***
0 Kudos
Anonymous
Not applicable
11,464 Views

Thank you Morgen for the replay, 

 

I did edit the linker script for my application and completely seperated the code section from the portion of memory which I want to use for data. I did it, just as you said by setting the main ddr section which is used to load the program code, stack, heap to a smaller length and declaring my memory section to the remaining ddr.

Using this method i found that everything worked but only for 64 mb sections of memory. For example:

i could write without a problem to addresses: 0xC100 0000 to 0xC400 0000 and from 0xC410 0000 tp 0xC800 0000 but not between 0xC400 0000 to 0xC410 0000 (and this repeats every 0x300 0000 addresses). This is what I dont understand because I divided the code and mydata section of ddr memory in the linker script.

Additionally, if i increase the heap size to well over 64 MB, my program once again crashes if I try to allocate (using malloc) more than 64 MB of space.

 

The only idea that i had was that maybe when programming the fpga through SDK, it doesnt use the linker script...? Or does it use another one, not the one that is defined in the same directory as the program?

0 Kudos
morgan198510
Voyager
Voyager
11,442 Views
Registered: ‎04-21-2014

Please upload a screenshot of your lscript.ld summary page.

 

***Many of us who help you are just FPGA enthusiasts, and not Xilinx employees. If you receive help, and give kudos (star), you're likely to continue receiving help in the future. If you get a solution, please mark it as a solution.***
0 Kudos
Anonymous
Not applicable
11,402 Views

here it is:

ls.png

0 Kudos
morgan198510
Voyager
Voyager
11,363 Views
Registered: ‎04-21-2014

Your lscript.ld looks good.  One thing I can't remember off hand is if the size of the heap is in bytes or words.  My guess, is bytes.

 

So, let me take a different stab at this, as I have a guess at what your problem might be.   If it is too basic, my apologies in advance.

 

Are you setting your pointer to NULL before you malloc?

 

Are you checking to see if it is still NULL after you malloc?

 

If you try to assign to a memory location (uninitialized pointer, NULL pointer) programs have been known to crash.

 

E.g.,

 

u32 *ptr = NULL;

 

...

 

ptr = (u32 *)malloc(1024*1024*128*sizeof(u32));

 

if(ptr == NULL){

print("some error message");

return SOME_ERROR_CODE;

}

for(i=0;i<(128*1024*1024)-1;i++){

ptr[i]=i;

}/* none of this was syntax checked */

 

Also remember to free your pointer and then set it to NULL if you are done with the memory allocated to you.

 

I'm not having any trouble mallocing large amounts of memory on a microblaze.

 

Again, sorry if this is too basic--hard to tell sometimes on a forum.

***Many of us who help you are just FPGA enthusiasts, and not Xilinx employees. If you receive help, and give kudos (star), you're likely to continue receiving help in the future. If you get a solution, please mark it as a solution.***
0 Kudos
Anonymous
Not applicable
8,844 Views

Thank you again for your replay. Don't worry any idea is a good idea when it comes to these things and usually it is a simple thing that causes most of the problems.

 

Unfortunatly that is not the case this time. I do NULL the pointer and do check for the return from mlloc, exactly how you did it. When i set the size larger than 64 mb, i do get a valid pointer (it does not return NULL) however when i try to zero the allocated space, my program crashes. Which is the same result i get when writting to ddr using my defined memory space in the linker script. 

 

But if i skip the 0x10 000 locations every 0x400 0000 memory locations, then it works. (ie. write from 0xD000 0000 to 0xD400 0000, skip 0xD400 0000 to 0xD410 0000, write 0xD410 0000 to 0xD800 0000 , etc...). Its like there is code every 64 mb, but according to the linker script they should be completely seperated.

 

btw I defined and use the following to directly access ddr:

typedef volatile u32 *U32Ptr

#define WR_WORD(addr,data)       (*(U32Ptr) (addr) = (data))

#define RD_WORD(addr,data)        ((data) = *(U32Ptr)(addr))

0 Kudos
Anonymous
Not applicable
17,798 Views

I found the cause of my problem and I just wanted to share it if anyone else has similar issues. 

 

For some reason EDK had defined the wrong memory module which resulted in incorrect usage of the memory. It worked for the limited address that the EDK set memory module with the actual module. This probably happened because the ML605 board I was using comes in a few revisions depending on the time of purchase. It seems that the original project which I created in ISE 13.7 used the revision C ML605 board while the later projects were based on the ML605 revision E board.

 

Be sure to check the board revision!!!

View solution in original post

0 Kudos