Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Altera_Forum
Honored Contributor I
1,098 Views

Read/Write CFI flash

I am using a Cyclone III starte board for some initial design. I am using the CFI flash for configuration and code storage, but I'd like to use unused space for non-volatile storage. I have tried the alt_read_flash/alt_write_flash but have not been able to read/write, even though the returned codes seem to indicate it worked. Is this due to the fact that my reset vector is in flash (exception is in sdram)? Can you not use it in this case? 

 

a la the example given in the book: 

 

char temp ; memset(temp, 0xAA, 131072); flashfd = alt_flash_open_dev(CFI_FLASH_0_NAME); if (flashfd) { alt_write_flash(flashfd, 0x00FE0000, temp, 131072) ; }then I read by: 

 

char out_temp ; alt_read_flash(flashfd, 0x00FE0000, out_temp, 131072); alt_flash_close_dev(flashfd);but my temp is all FF's, leading me to believe the write is failing... 

 

Could it be the fact it is in 16-bit mode? What about the alt_cfi_flash_read/write commands? Are they to be used instead? I've checked other posts and it seems like it is initializing ok, and the CFI stuff is in order according to nios2-flash-programmer... 

 

Help? Thanks!
0 Kudos
7 Replies
Altera_Forum
Honored Contributor I
169 Views

Refer to the memtest example (in $SOPC_KIT_NIOS2/examples/software) that is shipped with the Altera software for a decent example. There are also other examples that program/write data to the flash (AN-429 and the Application Selector that comes with the NEEK come to mind). 

 

Cheers, 

 

- slacker
Altera_Forum
Honored Contributor I
169 Views

I looked at memtest.c and it seems like my setup is nearly identical. i just dont go about discovering all the flash details like the example. I've checked the values using nios2-flash-programmer --debug. 

 

For a CFI with address range of 0x05000000 to 0x05FFFFFF, shouldnt the code I posted work for writing 0x20000 values to the last block? Shouldnt the code example given in the software dev handbook (p 6-22) work?! Do I need finegrained access?  

 

As for the NEEK/An429 example... thats a little too much to follow to be honest... I just want to write/read from a region on the flash that I know exists without pulling my hair out.
Altera_Forum
Honored Contributor I
169 Views

UPDATE: Success! As it turns out, for whatever reason (perhaps someone here can enlighten anyone who may be reading?), programming the CFI flash did not work until I burned the FPGA config AND code into the flash and runnint the system in standalone mode. Running it either in debug mode or on the NIOS over JTAG did not allow for writes. 

 

So, apparently the code works fine, with that caveat. Perhaps it is mentioned in some document somewhere? Hopefully this helps out anyone else who may have had a similar issue!
Altera_Forum
Honored Contributor I
169 Views

Possibly there were some other accesses to the flash memory device while the programming sequence was active? 

Maybe interrupts (or something) from the JTAG code ? 

If you are executing code from flash through a I-cache, it may all depend on the instruction alignments in cache lines!
Altera_Forum
Honored Contributor I
169 Views

Well, my reset vector is in flash, and my exception vector is in ddr... I was under the impression that when setup in such a way, the NIOS system copies the code from flash to ram on bootup and would therefore not need to access the flash anymore. 

 

I am probably wrong, as most assumptions are at least partially flawed. 

 

Anyway, it is nice to know that my code does work. I just wish things were a bit more cut and dry with the NIOS... I've spent a lot of time reading and writing code, looking thru the documentation, etc, and there are so many subtle nuances that still get me.
Altera_Forum
Honored Contributor I
169 Views

I am using Nios-II simple socket server software application. 

No DHCP server. Network settings are to be done statically. 

I wish to store network settings like IP address & subnet mask in flash and want to read this IP address & subnet mask from flash for Nios-II simple socket server software application so that network parameters get configured. 

Please tell me how to do this.
Altera_Forum
Honored Contributor I
169 Views

hi, i have a code to compression of image(bmp to jpg),this code have a out put file(.jpg). My problem is where i can write this file ?(because filesystem with write support, which isn't available in the standard Nios distribution). can i write this file in flash memory?( if yes how)? 

thanks in advance. I need your help pleaz.
Reply