Forum Discussion
Altera_Forum
Honored Contributor
12 years agoThanks for the reply. I had initially thought that the alt_write_flash function would do the read and compare as well. However, from table 6-7 in the manual it doesn't appear to do this. The table actually shows that the contents of a block outside the part that you are writing will be set to 0xFF and the original data will be lost. On page 161 it says:
"alt_write_flash() might need to erase the contents of a block before it can write data to it. In this case, it makes no attempt to preserve the existing contents of the block. This action can lead to unexpected data corruption (erasure), if you are performing writes that do not fall on block boundaries." Which suggests that it is not reading and comparing the data before the erase. It then says "If you wish to preserve existing flash memory contents, use the fine-grained flash functions." and under the section on the fine grained functions, it says "Therefore, to alter a specific location in a block while leaving the surrounding contents unchanged, you must read out the entire contents of the block to a buffer, alter the value(s) in the buffer, erase the flash block, and finally write the whole block-sized buffer back to flash memory. The fine-grained flash access functions automate this process at the flash block level." But looking at the actual functions in the fine grained section (alt_erase_flash_block() and alt_write_flash_block()) I don't see how it automates the first two stages in that paragraph. It seems that they do the same thing as the simple functions (erase and write) except that the two stages are separated. I did think the fine grained methods referenced the flash by block number, but I don't even think that's true. For alt_write_flash you pass "offset" bytes from the start of the flash, and for alt_write_flash_block you must specify "block_offset" bytes from the start of the flash. If "offset" is on a block boundary, I can't see the difference between these two parameters. This isn't a problem - I can do the read myself and alter the buffer before I call erase and write, after working out the offset of the block I'm writing to, but I have to do this when using either the simple or fine grained functions. As I think you always have to do the erase before the write, I still don't see the difference between the two methods except that the first is a single function and the second is two functions (both of which must be called in order). I must be missing something, but from the documentation I'm not sure what it is. Is there any more documentation on this other than the chapter in the Software Developer's Handbook, or could you explain this a bit more please? Thanks a lot, Giles