Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
21 years ago

Memory Test

Hello,

I was trying to write a simple program to test a board with a Cyclone and SRAM memory. Before hardware, I thought I would do a simple test to the IDT memory on a Cyclone Development Board.

I have defined .text, .rodata, and .rwdata as sram_0 in IDE.

My sram_0 is defined in system.h with a base of 0x00800000 with a width of 1024 Kbytes.

Reset and exception are at 0x00800000 and 0x00800020 respectively as defined in SOPC.

I get the very strange messages about sram_0, my defined memory not being within region .sram_0, and also that sram_0 is full section .bss. What does this mean? Can I use IORD and IOWR for access to Memory or should I be doing something else?

Any tips appreciated.

Thanks,

-Ray

ERRORS:

*********************************************************

Kind Status Priority Description Resource In Folder Location

Error /cygdrive/c/Altera/kits/nios21_1/bin/nios2-gnutools/H-i686-pc-cygwin/bin/../lib/gcc/nios2-elf/3.4.1/../../../../nios2-elf/bin/ld address 0xbf8150 of simple_axiom_test.elf section .sram_0 is not within region sram_0 simple_axiom_test line 0

*********************************************************

Kind Status Priority Description Resource In Folder Location

Error /cygdrive/c/Altera/kits/nios21_1/bin/nios2-gnutools/H-i686-pc-cygwin/bin/../lib/gcc/nios2-elf/3.4.1/../../../../nios2-elf/bin/ld region sram_0 is full (simple_axiom_test.elf section .bss) simple_axiom_test line 0

********************************************************

CODE:

// test memory# include <stdio.h># include <stddef.h># include <unistd.h># include <fcntl.h># include <stdlib.h>

# include "system.h" // generated header for the SOPC generated logic# include "io.h" // defines IORD, IOWR

//#include "simple.h"

# include "sys/alt_dev.h"# include "priv/alt_file.h"# include "alt_types.h" # include "sys/alt_sys_init.h" // contains reference to "alt_syst_init()"

//#include "myboard.h" // file to put system.h into a easy to read header

//#include "uart.h" // prototypes for the UART functions.

//#define SRAM_MEM_SIZE 1048575 //0x000FFFFF;# define SRAM_MEM_SIZE 1024000 //0x000FFFFF;

//#define SRAM_BASE_0 0x0080;

volatile unsigned long MEMORY_READ; // ??? what is 32 bits long for altera types

//unsigned long *SRAM_BASE_0;

//unsigned long SRAM_BASE_0;

//volatile unsigned long FAILED_ADDRESS;

//volatile unsigned long REC_DATA;

int main(void)

{

int i;

int err_flag;

static unsigned long MEMORY_ARRAY[SRAM_MEM_SIZE];

volatile unsigned long FAILED_ADDRESS;

volatile unsigned long REC_DATA;

printf("Hello from Nios II!\n");

err_flag = 0;

//Fill SRAM Base Memory with all a&#39;s first

for (i=0; i<SRAM_MEM_SIZE; i = i + 4)

//Writes

{

//IOWR((unsigned long *)(SRAM_BASE_0), i ,0xAAAAAAAA);

IOWR(0x00800000, i, 0xAAAAAAAA);

}

for (i=0; i<SRAM_MEM_SIZE; i = i + 4)

{

// Read

MEMORY_READ = IORD(0x00800000, i );

// Store in an array

MEMORY_ARRAY=memory_read;

}

// if expected results match proceed otherwise set err_flag

// capture address that fails and break out of test

// set error flag to -1

for (i=0;i<sram_mem_size;i = i + 4)

{

if( memory_array != 0xAAAAAAAA)

{

err_flag = -1;

REC_DATA = MEMORY_ARRAY;

failed_address = i;

}

}

//fill sram base memory with all 5&#39;s first

for (i=0; i<3; i++) // how do increase by 4

//writes

iowr(0x00800000, i ,0x55555555);

for (i=0; i<sram_mem_size; i = i + 4)

{

// read

memory_read = iord(0x00800000, i );

// store in an array

memory_array=MEMORY_READ;

}

// If expected results match proceed otherwise set err_flag

// Capture Address that fails and break out of test

// Set error flag to -1

for (i=0; i<SRAM_MEM_SIZE; i = i + 4)

{

if( MEMORY_ARRAY != 0x55555555)

{

err_flag = -2;

rec_data = memory_array;

FAILED_ADDRESS = i;

}

}

if ( err_flag < 0)

{

if( err_flag == -1)

{

printf(" Memory Test Failed @ Address = %x \n", FAILED_ADDRESS);

printf(" Received data = %x \n", REC_DATA);

printf(" Expected data = %x \n", 0xAAAAAAAA);

}

if( err_flag = -2)

{

printf(" Memory Test Failed @ Address = %x \n", FAILED_ADDRESS);

printf(" Received data = %x \n", REC_DATA);

printf(" Expected data = %x \n", 0x55555555);

}

else

{

printf("All Memory Tests PASSED!\n");

}

}

printf("End of Program \n");

return(0);

}

2 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi Ray,

    You don&#39;t have enough space in your .sram_0 section:

    ># define SRAM_MEM_SIZE 1024000

    ...

    > static unsigned long MEMORY_ARRAY[SRAM_MEM_SIZE]

    requires almost 4 MB in the output section. Other data,

    library code and app code gets added in as well (assuming

    everything is being placed in the SRAM).

    Regards,

    --Scott