Altera_Forum
Honored Contributor
14 years agoFlash memory problem
Hello, is it true that I cannot write 1MB of data into flash memory (4M)?
I am using Altera DE2 Board. My code is as follow: --- Quote Start --- # include <stdio.h># include <stdlib.h># include <unistd.h># include "altera_avalon_pio_regs.h"# include "system.h"# include "alt_types.h"# include "sys/alt_dma.h"# include "sys/alt_flash.h" # include "sys/alt_flash_dev.h" # define loop 262144# define size 1048576 int main () { alt_flash_fd* fd; int ret_code, i; int *src_ptr; int *dest_ptr; src_ptr = SDRAM_BASE + 0x200000; //Location of data written in SDRAM dest_ptr = EXT_FLASH_BASE; //Location of data written in flash //Open flash fd = alt_flash_open_dev(EXT_FLASH_NAME); if(fd!=NULL) { //Generate data into SDRAM for(i=0;i<loop;i++) { IOWR(src_ptr, i, i); } //Write data into flash ret_code = alt_write_flash(fd, 0, src_ptr, size); if(ret_code != 0) { printf("Error writing into flash: %d\n", ret_code); exit(1); } //Read from flash for(i=0;i<loop;i++) { printf("Value at %X is %d, written at is %d\n", dest_ptr, *dest_ptr, IORD(src_ptr, i)); dest_ptr++; } }else { printf("Unable to open flash\n"); exit(1); } alt_flash_close_dev(fd); return 0; } --- Quote End --- I keep on getting error msg: Cannot write into flash and the error code is -5. pls help me. i am not sure whether is my coding problem or writing 1MB into flash is a special case. pls help! thanks!