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++

Flash EPCS access problem

Altera_Forum
Honored Contributor II
926 Views

Hi, 

 

I'm trying to write my FPGA configuration file on its EPCS16 flash using Nios processor. The final goal is to use Uart/Usb/Ethernet communication to download the FPGA configuration file on the board. 

I have implemented an EPCS_Controller on my Nios CPU using SOPC builder, and I'm using 'alt_flash_dev' drivers to access to it. 

I success to read flash datas. But I have some problems concerning write access : I can't write a block entirely (65536 bytes, I don't have enough memory to store such amount of datas), so I would like to write only part of a block, like this way : 

 

my_epcs = alt_flash_open_dev(epcs_controller_name); 

if(my_epcs) { 

printf ("epcs opened successfully!"); 

ptr = 0; 

while (ptr<3146000) { // fichier 3mo maxi 

my_data = .. // store 0x2000 datas 

ret_code = alt_write_flash(my_epcs, ptr, my_data, 0x2000); 

ptr = ptr + 0x2000; 

alt_flash_close_dev(my_epcs); 

 

The problem is that each access with &#39;alt_write_flash&#39; function seems to erase the entire block/sector of the flash (which represent 0x10000 datas). Is there a solution to my problem ? 

 

Thanks, 

 

Jérôme
0 Kudos
2 Replies
Altera_Forum
Honored Contributor II
190 Views

Hi Jérôme, 

 

> I can&#39;t write a block entirely (65536 bytes, I don&#39;t have enough memory to store such amount of 

> datas), so I would like to write only part of a block, 

 

You can write as little as you like -- but no more than the page size. 

 

> The problem is that each access with &#39;alt_write_flash&#39; function seems to erase the entire 

> block/sector of the flash 

 

Correct. You can either erase a single sector, or the entire device. There&#39;s no way to erase 

anything smaller than a sector. 

 

> Is there a solution to my problem ? 

 

If you need to preserve some data in the sector, you need to: read--modify--erase sector--write sector. 

If you don&#39;t have enough memory (RAM) to read an entire sector, you&#39;ll need to be creative. 

You could try reserving a sector to hold a copy of the original sector while you perform the update. 

It&#39;s very not pretty -- but it can work. 

 

Regards, 

--Scott
0 Kudos
Altera_Forum
Honored Contributor II
190 Views

 

--- Quote Start ---  

originally posted by jérôme@Apr 28 2006, 04:19 AM 

the problem is that each access with &#39;alt_write_flash&#39;[/b] function seems to erase the entire block/sector of the flash (which represent 0x10000 datas). Is there a solution to my problem ? 

 

Thanks, 

 

Jérôme 

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=14815) 

--- Quote End ---  

[/b] 

--- Quote End ---  

 

 

This is the nature of using most any flash device. 

 

For your situation, it makes sense to use the alt_write_flash_block() function. It won&#39;t automatically erase the flash....like alt_write_flash() does. In this way you could write to the flash in whatever data size you want and detect when a sector erase is necessary yourself. 

 

Something like the following should work if you implement it in a loop passing new "data" in with each pass: 

 

if(new_flash_block != current_flash_block)    {      printf("\nFlash Block %d", new_flash_block);      alt_erase_flash_block(fd, (new_flash_block * regions->block_size),                                      regions->block_size);      current_flash_block = new_flash_block;    }    alt_write_flash_block(fd, (current_flash_block * regions->block_size),                                   target_addr, data, data_len); 

 

Cheers, 

 

- slacker
0 Kudos
Reply