Forum Discussion
Altera_Forum
Honored Contributor
20 years agoProblem testing SRAM device
Hi
I made a Project in Quartus II, and in SOPC Builder, I added NIOS II cpu, AvalonTri-State Bridge to an external SRAM, Jtag UART and a on-chip RAM. The system generation and hardware configuration went fine. I made a simple memory test application, for the external SRAM. It writes a patern on on a specific adress then reads back from that adress, checks if the value is the same that was writen, then it increases the adress and so on. But it doesnt´seem to work http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/sad.gif What am I doing wrong?? The memory is a 128KByte and is 65536 words by 16bits. The hardware part is ok. I know this becouse I downloaded some applications to the external memory. While Im doing this memory test Im using the onchip ram for prorgram drives and stack.#include <io.h># include <stdio.h># include "system.h"
int main(void)
{
unsigned int value = 0;
unsigned int pattern = 0x0000000F;
unsigned int i, memory_size;
// Adress size is 65536 = 0x8AD0
// EXT_SRAM_BASE is 0x00020000
memory_size = 0x8AD0;
for(i = 0; i< memory_size; i= i+4)
{
IOWR_32DIRECT((ONCHIP_RAM_BASE), i, pattern);
value = IORD_32DIRECT((ONCHIP_RAM_BASE), i);
printf("%d,%d\n", i,value);
if (value != pattern)
{
printf("ERROR!!\n");
}
}
return 0;
} I get the folowing output : 0,-1 ERROR!! 91964,-1 ERROR!! 91968,-1 ERROR!! 91972,-1 ERROR!! 90,15 4,15 8,15 12,15 16,15 20,15 24,15 28,15 32,15 36,15 40,15 44,15 48,15 52,15 56,15 60,15 64,15 68,15 72,15 76,15 80,15 84,15 88,15 92,15 96,15 100,15 104,15 108,15 112,15 116,15 120,15 124,15 128,15 132,15 136,268929082 ERROR!! 140,-528482025 ERROR!! 144,411041845 ERROR!! 148,-528481769 ERROR!! . . . Can someone please tell me what Im doing wrong.5 Replies
- Altera_Forum
Honored Contributor
Where is your stack?
Perhaps that's conflicting with the external ram. gm - Altera_Forum
Honored Contributor
For the stack memory Im using an on-chip ram.
- Altera_Forum
Honored Contributor
--- Quote Start --- originally posted by mrzol@Oct 19 2005, 08:17 AM for the stack memory im using an on-chip ram.<div align='right'><{post_snapback}> (index.php?act=findpost&pid=10457)
--- quote end ---
--- Quote End --- Hi, I am new to Nios. Regarding the code above, can I use IOWR_32DIRECT with the base of SDRAM (set when building the HW in SOPC) in order to read and write to Micron SDRAM? In Nios documentation, it shows how to deal with UART per example, but not with SDRAM. Thanks in advance, John.
- Altera_Forum
Honored Contributor
Hi
Yes you can do that, and you can also just use the name of your RAM and than _base. For example if your RAM is named Micron_RAM in SOPC builder, you just write IOWR_32DIRECT(Micron_RAM_BASE, offset, pattern); Micron_RAM_BASE is equal whit the base adress of your ram. Look in system.h it can be found in your Nios IDE project folder. and for my code above it should be EXT_SRAM_BASE instead of ONCHIP_RAM_BASE in IOWR and IORD becouse Im using my external SRAM not the on-chip RAM. - Altera_Forum
Honored Contributor
--- Quote Start --- originally posted by mrzol+oct 19 2005, 06:20 am--><div class='quotetop'>quote (mrzol @ oct 19 2005, 06:20 am)</div>--- quote start ---
the memory is a 128kbyte and is 65536 words by 16bits.[/b]
--- quote end ---
<!--quotebegin-mrzol@Oct 19 2005, 06:20 AM while im doing this memory test im using the onchip ram for prorgram drives and stack. --- Quote End --- "Program drives"? Do you mean the .text, .rodata, .rwdata, and .bss segments? Your code would require that none of the compiled code or data be in the external SRAM or it's going to get corrupted.
65536 != 0x8AD0. 65536 == 0x10000, 0x8AD0 == 35536 In any case, memory_size should be 128K (131072 or 0x20000), since your code is using byte addresses, not word addresses.// Adress size is 65536 = 0x8AD0 // EXT_SRAM_BASE is 0x00020000 memory_size = 0x8AD0;