Jump to content
  • 0

Storing float values in DDR3


shashi

Question

Hi there
 
I just want to verify how to store float values in DDR3 of zed board.
 
I have written a small code,  but when i read from memory, i am not getting the correct answer.  Is it correct? can someone help me?
 
 
#include <stdio.h>
#include "platform.h"
#include "xil_printf.h"
#include "xil_io.h"
#include "xparameters.h"
 
#define DDR_BASEADDR 0x01000000
 
int main()
{
 init_platform();
    int i;
   float img[5] = {11.2345 ,17.2135 ,11.65 ,18.543 ,7.6789};
 
    for (i = 0; i <5; i++) {
     Xil_Out32(DDR_BASEADDR+(i*4),img);
     }
    cleanup_platform();
    return 0;
}
Link to comment
Share on other sites

4 answers to this question

Recommended Posts

@shashi,

Ouch, that looks pretty painful!  Why not something simpler, such as:

float *a = (float *)BASE_ADDRESS;
*a = 3.14159;

The thing to be aware of, though, is ... what else is using that DDR3 SDRAM?  Will you be overwriting memory already allocated to something else?  What about the memory management unit?  Do you have it enabled or disabled? 

Another fundamental question: are you running Linux?  Linux tends to use the memory management unit, and there are standard ways of getting access to the memory device under Linux that are device independent and can be looked up in many text books.

Dan

Link to comment
Share on other sites

Hi, I am relatively new to FPGA design.

I have not used MMU. I just want to store a 20MB file in DDR3 and do some image processing operation on it. How will i make sure i am not using the memory which is already been allocated.

I am not using Linux either.

Thank you

Link to comment
Share on other sites

@shashi,

When you compile your program, make a "map" file.  This will tell you where all of the static things (code, global variables, etc) are located.  Using the GNU linker, a map file "something.map" is generated with the "-Map=something.map" option.

But ... why not use a typical C construct like "malloc"?  As in

#include <stdlib.h>
  
  // then later, within your code ...
  
float *imagep;
imagep = (float *)malloc(20*1024*1024); // 20 MB image
// Now ... operate on imagep

If you've set up your environment well enough, this should work.  Check the result of the malloc (imagep) against NULL to know whether or not you are finding this memory properly.

Of course, you could also do it like ...

float	global_image[20*1024*1024];

main(...) {
...
	global_image[index] = value;
...
}

In this latter case, you should be able to see global_image in your map file, and know where the linker placed it.

Dan

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...