Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Altera_Forum
Honored Contributor I
753 Views

How to fill SDRAM with dummy values

I am working with the Altera DE2 board and want to use the SDRAM to store pictures. I fill my SDRAM chip with a dummy value (all x00 or xFF) and when I see a value that is different I know that is where my picture starts. 

 

I am using a book on how to perform rapid prototyping and there was example code on how to write and read from SDRAM but the code has me very confused as to how this is happening. 

 

1.) When I highlight buffer it reads 0x800000, the base address of SDRAM. But buffer is declared as a pointer and assigned the defined value SDRAM_BASE which has been casted to be a integer pointer. Since buffer is a pointer shouldn't the value be the address of where SDRAM_BASE is located, which contains the actual value? Going through debug in nios, I could not see what the value of buffer was only that buffer was 80000. 

 

2.) in the for loop it appears that buffer is assigning sequential addresses in SDRAM to some incremented value of 100000. But the buffer pointer has the address of SDRAM_BASE, wouldn't I be overwriting the address value with a aformentioned incremented value? I do not understand why buffer is treated as an array, or how buffer[0] could correspond to write data to address 0x800000.  

 

3.) Not sure as to how many loops I would need to fill all 8 MB.  

 

The book example gave 1000000 loops. But if buffer[0] is address 0x800000 and I assign it 1000000 does this mean that memory address will have 16 bits equal 1000000? 

 

SDRAM is configured as 4,194,304 words x 16 bits. I wanted to make the loop 4194303 but that throw a bunch of errors in Nios. Is my thinking correct? 

 

This is for my senior design project and this hiccup has made my project a week behind schedule, but any help or advice would be greatly appreciated. 

 

define SDRAM_BASE 0x800000 alt_u32 *buffer = (alt_u32 *)SDRAM_BASE; /* Write data to SDRAM */ for( i = 0; i < SDRAM_MAX_WORDS; i++ ) { buffer = i + 1000000; temp = buffer; }
0 Kudos
2 Replies
Altera_Forum
Honored Contributor I
27 Views

Remember your C. 

Accesses via pointers and array indexing are interchangeable. 

So buffer[n] is absolutely equivalent to *(buffer + n) and to n[buffer] for that matter! 

 

Although your SDRAM chip might be 4M by 16bits, it will be accessed as 2M by 32bits. 

 

All this also assumes that you code is running from the fpga's internal memory blocks, if your program (etc) is loaded into the SDRAM you will be overwriting your code.
Altera_Forum
Honored Contributor I
27 Views

 

--- Quote Start ---  

Remember your C. 

Accesses via pointers and array indexing are interchangeable. 

So buffer[n] is absolutely equivalent to *(buffer + n) and to n[buffer] for that matter! 

 

Although your SDRAM chip might be 4M by 16bits, it will be accessed as 2M by 32bits. 

 

All this also assumes that you code is running from the fpga's internal memory blocks, if your program (etc) is loaded into the SDRAM you will be overwriting your code. 

--- Quote End ---  

 

 

Ok, that makes a lot more sense now. Im having a bit of an issue with reading the data saved in SDRAM from the 5 MP camera though. I think I will just make a post in the dev kit section as it is not really a NIOS problem anymore. 

 

In case someone is very kind, when I read the value of an address from SDRAM and compare it with the value I read from the System Control GUI for the DE2. Typically the first 10 addresses match exactly and the addresses after the values are slightly off. E.g. Address 1 = 4AC04AC on both, but address 122 is 4AD4AB in NIOS window and 4AD4AC in the system control 

 

Edit: Instead of my previous problem, is there a way to dump the data from SDRAM other than printing onto the console. I tried dumping into a text file until I realized that the nios II processor has no communication with my laptop. I searched through other posts on the forums but didn't find anything on a data dump,.