- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What is EXT_FLASH_BASE defined as?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hi, yes, just now the size is wrong, should be 0x100000. but even using 0x100000, it will return error when writing. the error code is -5.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you use nios2-flash-programmer, can you program the flash? If yes, there is something wrong in your code, otherwise, your nios system is not working at all for flash.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yes, it works. there is sth wrong with the length.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page