I am using DE2 Board. I want to write 1MB of data into flash and my flash is 4MB. My code is below:
--- 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_flash.h" # include "sys/alt_flash_dev.h" # define size 0xFFFFF int main (int argc, char* argv[], char* envp[]) { alt_flash_fd* fd; int ret_code, i; int *p1; int *p2; p1 = SDRAM_BASE+0x200000; p2 = EXT_FLASH_BASE; for(i=0;i<size;i++) { IOWR(p1, i, i); } fd = alt_flash_open_dev(EXT_FLASH_NAME); if (fd!=NULL) { if((ret_code = alt_write_flash(fd, 0x0, p1, 4096)) == 0) { printf("Done writing into flash\n"); printf("Reading data from flash...\n"); for(i=0;i<size;i++) { printf("Value at %X is %u\n", p2, *p2); p2 = p2+1; } }else { printf("Error in writing to flash\n"); } }else { printf("Error in opening flash\n"); exit(1); } printf("DONE\n"); return 0; } --- Quote End --- First, I am storing 1MB of data into SDRAM. then from SDRAM, i write into flash. to test whether the result is correct, I read the data out from the flash. a part of my output is as below: --- Quote Start --- Value at 142FFF4 is 49149 Value at 142FFF8 is 49150 Value at 142FFFC is 49151 Value at 1430000 is 4294967295 Value at 1430004 is 4294967295 Value at 1430008 is 4294967295 --- Quote End --- suppose i will get the 1MB data but it stops at address 142FFFC. Please help! Thanks!链接已复制
5 回复数
change your print to this :
printf("Value at %X is %u, written is %u\n", p2, *p2, IORD(p1, i); would help verify your write buffer is correct. Also, make sure your length of SIZE is correct for what you want, it does not match what you are writing into the flash. Also, it should most likely be 0x100000 if you ware trying to do 1MB, not 0xFFFFF.