Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12600 Discussions

Writing/Reading into/from EPCS Flash Device

Altera_Forum
Honored Contributor II
1,371 Views

I am sorry for starting a new thread for this when there are some old threads of me and other in the same topics. I am not getting a response for those as yet. I am greatful to the forum as i have solved many of my newbie doubts here... I hope to get out of this too... 

 

i want to use epcs16 on my board to store some 16 bit words during runtime and wish to recall the same on subsequent power ups.  

 

Correct me if am wrong, 

 

i have to use the api's provided in "altera_avalon_epcs_flash_controller" ???? I am confused first, how to access the EPCS device ? I can just see it has 32 sectors of 24 bits each. what address should i use to access the same. I am using C program in NIOS SBT for programming NIOS now. :confused::confused:
0 Kudos
4 Replies
Altera_Forum
Honored Contributor II
271 Views

Hey.... Guys.. i have somehow managed to store and retrieve data from free space in EPCS. But have a problem.... I followed method explained in http://www.alteraforum.com/forum/showthread.php?t=27724 this thread...  

 

So i am going to the last block starting address and writing a value... and am able to read the same and print.... Suppose i wish to write a second variable where should i start ? 

I am writing a char array of 16 bit for the first value... so if i have to write a similar value adjecent to the first, what must i do ? 

 

I tried something like this... alt_write_flash(p_epcs_fd,addr+sizeof(def_ctr),&def_ptr,sizeof(def_ptr)); for second value.. but am getting wrong value when i read the location.
0 Kudos
Altera_Forum
Honored Contributor II
271 Views

The epcs is quite simple to access with the standard APIs.  

Reading flash data is straightforward. For writes, the only point you must make sure is that the location you want to write to is blank. 

Otherwise you'll need to erase the whole block/sector: infact, like any other flash memory you can program single bytes but you can't erase them the same way. 

Then try repeating your test after you added a block erase before writing the first data. 

 

In the first post you talked about EPCS16 device and said it has 32 sectors of 24 bits each; this is not true EPCS16 indeed has 32 sector, but they are 64kBytes each.
0 Kudos
Altera_Forum
Honored Contributor II
271 Views

Thanks Cris72....!!! Sorry for the mistakes,... i am getting used to the details slowly.... and based on the following two old threads i have managed to read and write EPCS flash.... I am now implementing the logic... will get back in case i face some issue... thanks for the support...would not have been possible without all ur help.... 

 

http://www.alteraforum.com/forum/showthread.php?t=27724 

 

http://www.alteraforum.com/forum/showthread.php?t=18461
0 Kudos
Altera_Forum
Honored Contributor II
271 Views

You do need to sort out a scheme to limit the number of erase cycles (to improve the lifetime of the flash). 

One possibility is to use a type-length-data encoding to create a serial data stream in a flash block. 

Terminate on a type of all 1s - allowing items to be appended, and 'erase' old items by changing the type to 0. 

I did this with 32bit flash (paired devices) using a 24bit type and 8 bit length (of 32bit words). 

You then only need to do an erase cycle when the sector is getting full.
0 Kudos
Reply