Forum Discussion
Altera_Forum
Honored Contributor
15 years agoFlash Memory
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!
6 Replies
- Altera_Forum
Honored Contributor
thank you very much
- Altera_Forum
Honored Contributor
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.
- Altera_Forum
Honored Contributor
--- Quote Start --- First of all init the flash device and possibly get extra info about the flash device, like block 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: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;
why need rv when write data? Then, read back data with: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);
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!alt_epcs_flash_read(pFlashDevice, addr, buf, len); - Altera_Forum
Honored Contributor
First of all init the flash device and possibly get extra info about the flash device, like block size:
This is for erasing a single block: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 writing any data to a previously erased area:alt_epcs_flash_erase_block(pFlashDevice, block_address);
Then, read back data with: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);alt_epcs_flash_read(pFlashDevice, addr, buf, len); - Altera_Forum
Honored Contributor
thanks. but i dont really understand. can i have some sample code? just a simple writing and reading to/from flash.
- Altera_Forum
Honored Contributor
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.