- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi folks:
I am currently running into a CFI flash write issue with Nios II Eclipse software, I would appreciate it very much if anyone of you could give some insights on it. The issue is described as below: (1) We are using the example code “using the simple flash api functions” given by Nios II Software Developer’s Handbook, Chapter 6: Developing Programs Using the Hardware Abstraction Layer, page 6-19 : Using Flash Devices. (2) The main function is given below. ((4) I've Made sure that the flash is writable with Altera IP, by attaching a CFI flash device to FPGA on Programmer GUI. (5) With Nios II software and the attached example program, we can open the flash, read it, but can not write it, the write function returns non-zero. (6) From the comparison between the objdump file and disassembly file, we found the “alt_write_flash” function is not properly called or executed, please referring to line 383 - 399 of the objdump file and line 494 - 497 on disassembly view file. (7) A screenshot is also attached. /////////////////main function///////////////// /* * "Small Hello World" example. */# include <stdio.h># include "sys/alt_stdio.h"# include "system.h" // CFI_FLASH_NAME# include "sys/alt_flash.h" // flash HAL int main() { int return_code,k; k=0; char source[16]; alt_flash_fd* fd; # define FLASH_TEST_OFFSET 0 for(k = 0; k < 16; k++) { source[k] = k; } fd = alt_flash_open_dev(TRISTATE_CONTROLLER_NAME); //open flash //return 0 means failure if(fd) { return_code = alt_write_flash(fd,FLASH_TEST_OFFSET,source,16); //Wrte flash, return 0 means success if (return_code) { printf("\nalt_write_flash error"); } else { printf("\nalt_write_flash successful"); } alt_flash_close_dev(fd); //close flash } else { printf("\nalt_flash_open_dev error"); } while (1); return 0; } /////////////////line 383 - 399 of the objdump file///////////////// if(fd) 100000a4: 10000f26 beq r2,zero,100000e4 <main+0x78> alt_flash_fd* fd, int offset, const void* src_addr, int length ) { return fd->write( fd, offset, src_addr, length ); 100000a8: 10800517 ldw r2,20(r2) 100000ac: 8009883a mov r4,r16 100000b0: 000b883a mov r5,zero 100000b4: d80d883a mov r6,sp 100000b8: 103ee83a callr r2 { return_code = alt_write_flash(fd,FLASH_TEST_OFFSET,source,16); if (return_code) 100000bc: 10000326 beq r2,zero,100000cc <main+0x60> { printf("\nalt_write_flash error"); ///////////////// line 494 - 497 on disassembly view file///////////////// 106 if(fd) 100000a4: beq r2,zero,0x100000e4 <main+120> 109 if (return_code) 100000bc: beq r2,zero,0x100000cc <main+96> 111 printf("\nalt_write_flash error"); //////////////////////////////////////// Thank you very much SongLink Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'd guess that the flash can only be written in entire flash sectors?
These are likely to be at least 64k bytes. You can look at the source (probably) and certainly the disassembly of it to see. The call looks fine to me, the arguments are in r4,r5.r6.r7- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
HI dsl:
Thanks so much for the reply. I changed the size of source from 16 to 65536, but it's too big for the nios memory, which is only 64K. The following pieces of code didn't happen at all in the disassembly view, still OK? "100000a4: 10000f26 beq r2,zero,100000e4 <main+0x78> alt_flash_fd* fd, int offset, const void* src_addr, int length ) { return fd->write( fd, offset, src_addr, length ); 100000a8: 10800517 ldw r2,20(r2) 100000ac: 8009883a mov r4,r16 100000b0: 000b883a mov r5,zero 100000b4: d80d883a mov r6,sp 100000b8: 103ee83a callr r2 { return_code = alt_write_flash(fd,FLASH_TEST_OFFSET,source,16);" any other possibilities regarding this issue? Thanks Song- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Issue solved, the flash entered block protection mode somehow.
![](/skins/images/9DC05BB6E5999F99F35389BFB16D84DF/responsive_peak/images/icon_anonymous_message.png)
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