- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello. I am using Altera DE2 Board with Flash (1Mb). I want to know how to store data into and read data from flash memory. For example, I want to store 1-10 into the flash. Then, I will read the number 1-10 from the flash memory for addition. Thanks!
Link Copied
6 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Add these header files:
# include "sys/alt_flash.h" # include "sys/alt_flash_dev.h" and take a look to the functions available in them.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
thanks. but i dont really understand. can i have some sample code? just a simple writing and reading to/from flash.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
First of all init the flash device and possibly get extra info about the flash device, like block size:
flash_region *regions;
int numRegions;
int error = 0;
pFlashDevice = alt_flash_open_dev(FLASH_CONTROLLER_NAME);
if (pFlashDevice <= 0)
error = -1;
if (!error)
error = alt_epcs_flash_get_info(pFlashDevice, ®ions, &numRegions);
if (!error) {
flash_block_size = regions->block_size;
flash_max_addr = regions->region_size;
This is for erasing a single block: alt_epcs_flash_erase_block(pFlashDevice, block_address);
This is for writing any data to a previously erased area: int buf = { 1, 2,3,4,5,6,7,8,9,10 };
rv = alt_epcs_flash_write_block(pFlashDevice, block_address,
data_offset_inside_block , buf, 10);
Then, read back data with: alt_epcs_flash_read(pFlashDevice, addr, buf, len);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- First of all init the flash device and possibly get extra info about the flash device, like block size:
flash_region *regions;
int numRegions;
int error = 0;
pFlashDevice = alt_flash_open_dev(FLASH_CONTROLLER_NAME);
if (pFlashDevice <= 0)
error = -1;
if (!error)
error = alt_epcs_flash_get_info(pFlashDevice, ®ions, &numRegions);
if (!error) {
flash_block_size = regions->block_size;
flash_max_addr = regions->region_size;
i am using cfi, is it the same? besides, my pflashdevice is <= 0. i dunno why. is it sth to do with reset vector as my reset vector is sdram. This is for writing any data to a previously erased area: int buf = { 1, 2,3,4,5,6,7,8,9,10 };
rv = alt_epcs_flash_write_block(pFlashDevice, block_address,
data_offset_inside_block , buf, 10);
why need rv when write data? Then, read back data with: alt_epcs_flash_read(pFlashDevice, addr, buf, len);
where is the data when we read it from the flash? like i want to print out the data. --- Quote End --- please help me with the ques in bold. thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
why need rv when write data?
This is not mandatory, but recommended to check if data has been written correctlywhere is the data when we read it from the flash? like i want to print out the data.
??? What's the problem? The buf array contains your data. Maybe this way is clearer: int buf[10]; alt_flash_read(pFlashDevice, addr, buf, 10);Remark: remove epcs_ from the previous post. I copied and pasted from a project using epcs instead of parallel flash and forgot to change function names.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
thank you very much

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