Altera_Forum
Honored Contributor
13 years agosdram write/read in arria ii gx dev. board
Hi
I am trying to write and read the DDR3 SDRAM on my Arria II Gx Dev. board with the following code.
# include <stdio.h>
# include "system.h"
# include "altera_avalon_pio_regs.h"
# include "alt_types.h"
int main()
{
// test message
printf("Hello from Nios II!\n");
// ==========
// test SDRAM
// ==========
// write SDRAM
int i = 0;
for(i = 0; i < 32; i++)
{
*((alt_32*)ALTMEMDDR_0_BASE + i) = (alt_32)i;
}
// read SDRAM
for(i = 0; i < 32; i++)
{
alt_32 data = *((alt_32*)ALTMEMDDR_0_BASE + i);
printf("SDRAM = %d\n", i, data);
}
// flash led every one second
while(1)
{
IOWR_ALTERA_AVALON_PIO_DATA(PIO_0_BASE, 0xf);
usleep(1000000);
IOWR_ALTERA_AVALON_PIO_DATA(PIO_0_BASE, 0x0);
usleep(1000000);
}
return 0;
}
Basically, I write 0,1,2,3,...,31 to the DDR3 SDRAM and read these data back for testing. However, when those read data are displayed in the console using printf function, some of the access fails, as you can see in the following:
Hello from Nios II!
SDRAM = 0
SDRAM = 0
SDRAM = 0
SDRAM = 0
SDRAM = -1
SDRAM = -1
SDRAM = -1
SDRAM = -1
SDRAM = 0
SDRAM = 0
SDRAM = -1
SDRAM = 0
SDRAM = 0
SDRAM = 0
SDRAM = 14
SDRAM = 15
SDRAM = 16
SDRAM = 17
SDRAM = 18
SDRAM = 19
SDRAM = 20
SDRAM = 21
SDRAM = 22
SDRAM = 23
SDRAM = 24
SDRAM = 25
SDRAM = 26
SDRAM = 27
SDRAM = 28
SDRAM = 29
SDRAM = 30
SDRAM = 31
When I run my program again, the result is always different. For example: some of data in SDRAM[14:31] may be wrong this time but other data may be correct. Does any one have any clue on this problem??? Thanks a lot. (I also provide my qsys design as an attached image if anyone thinks the problem may come from my qsys design)