Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

flash_test

Altera_Forum
Honored Contributor II
1,890 Views

#include "system.h"# include "string.h"# include "stdio.h"# include "sys/alt_irq.h"# include "unistd.h"# include "alt_types.h"# include "flashtest.h" 

 

 

int main(void) 

unsigned char buf[100]; 

unsigned short *flash_test_address; 

int i; 

int result; 

int fail_count = 0; 

 

flash_test_address = (unsigned short *)EXT_FLASH_BASE; 

 

 

 

// | 

// | Erase the flash. Report result. 

// | 

 

printf("(1) erasing flash at 0x%08x\n",flash_test_address); 

 

result = nr_flash_erase_sector((unsigned short *)EXT_FLASH_BASE, flash_test_address); 

 

printf(" result = %d\n",result); 

 

 

// | 

// | Fill the buffer with random (but repeatable) values. 

// | 

 

 

for (i = 0; i < 100; ++i) 

// buf = rand(); 

buf = i; // test value 

 

// | 

// | Write that stuff to flash... 

// | 

 

printf("(2) writing flash...\n"); 

 

result = nr_flash_write_buffer((unsigned short *)EXT_FLASH_BASE, 

flash_test_address, 

buf, 

100); // api wants number of short words 

 

printf(" result = %d\n",result); 

 

// | 

// | Read that stuff back, and report if it matches, or what. 

// | 

 

printf("(3) reading flash.\n"); 

 

for (i = 0; i < 100; ++i) 

unsigned short a,b; 

 

a = buf

b = flash_test_address

 

if(a != http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/cool.gif  

printf("verify failure at location 0x%08x (expected 0x%04x, got 0x%04x)\n", 

&flash_test_address[i], 

a,http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/cool.gif ; 

fail_count++; 

if(fail_count >= 10) 

goto no_more_verifying; 

no_more_verifying: 

 

 

EXT_FLASH_BASE 0x00000000 

 

ONCHIP_RAM_BASE 0x00200000 

 

 

complile error: 

Kind Status Priority Description Resource In Folder Location 

 

Error  

/cygdrive/e/EDA/Altera/kits/nios2/bin/nios2-gnutools/H-i686-pc-cygwin/bin/../lib/gcc-lib/nios2-elf/3.3.3/../../../../nios2-elf/bin/ld region onchip_ram is full (flash.elf section .text) flash line 0 

 

Error /cygdrive/e/EDA/Altera/kits/nios2/bin/nios2-gnutools/H-i686-pc-cygwin/bin/../lib/gcc-lib/nios2-elf/3.3.3/../../../../nios2-elf/bin/ld section .rodata [00000020 -> 000005db] overlaps section .exceptions [00000020 -> 00000327] flash line 0 

 

Error /cygdrive/e/EDA/Altera/kits/nios2/bin/nios2-gnutools/H-i686-pc-cygwin/bin/../lib/gcc-lib/nios2-elf/3.3.3/../../../../nios2-elf/bin/ld section .rwdata [000005e0 -> 000020e3] overlaps section .text [00000328 -> 0000e37f] flash line 0 

 

 

 

 

I want to ask why appear the errors? 

 

the rountine is no problem,because I have used them in niosI. 

 

 

Thank you!
0 Kudos
3 Replies
Altera_Forum
Honored Contributor II
581 Views

From your memory map I gather you have a 2MB flash. The error messages are saying you don&#39;t have room to fit the code into onchip memory though. So my question is how big is your onchip memory? From the warnings it looks like you need more than 64kB of on chip memory. Since this worked on Nios I, I suggest performing optimizations to make it fit (see pages 4-23 to 4-28 of the "Developing Programs using the HAL" doc). 

 

Also that code with a little bit of modification could use the HAL 100% (i.e. full upgrade to Nios II). nr_flash_erase_sector and other function calls starting in "nr_" are legacy SDK calls, and there are HAL equivalents for these.
0 Kudos
Altera_Forum
Honored Contributor II
581 Views

To BadOmen 

 

I have met the same problem.I want to ask if I can use the programme to test flash ?
0 Kudos
Altera_Forum
Honored Contributor II
581 Views

I would use the HAL to communicate with the flash device for starters. Or better yet if you want to test flash try the memory test software template in the IDE (it has a flash test).

0 Kudos
Reply