Hi, I hardly understand :
The
"simple flash access function" alt_write_flash( alt_flash_fd* fd, // file descriptor for flash
int offset, // destination address offset
const void* src_addr, // source address
int length ) // length of data to be written to Flash, in Bytes(?)
1) will read the block (8k B, 64 kB) in which "offset" is,
2) copy this block to a buffer,
which require some ram
3) erase the block,
4) modify the buffer with new data,
5) write the whole buffer to the flash block.
it automatically does it ?
So, if the amount of data doesn't overlap the next block, there is NO Corruption, isn't there ?[/B]
But if I want to write only 1 Byte, The alt_write_flash() will do read-copy-erase_block-modify-write.
if the amount of data overlaps the next block, there IS Corruption ?
the "fine-grained flash access" alt_write_flash_block() will only modify bytes without the "read-copy-erase_block-modify-write",
it just writes and doesn't erase the whole block, doesn't it ?
So, if the amount of data doesn't overlap the next block, there is NO Corruption, isn't there ?
if the amount of data overlaps the next block, there IS Corruption ?
I don't know what is the advantage of using the "Fine-Grained Flash Access".
In the exemple of the "Chapter 6: Developing Programs Using the Hardware Abstraction Layer", alt_write_flash() write 0xAA to the next block,
because before there was 0xFF (all bits is '1'), and the write function change only '1' to '0' if necessary. OK I understand.
If this byte was not 0xFF, the result of write function will be unexpected, I think (It would be equal to {old_Byte AND new_byte})
I am very confused.
EDIT :
--- Quote Start ---
You only need to call alt_erase_flash_block() once to erase a block, but can then call alt_write_flash_block() multiple times to write to this block (as long as you don't overwrite the same addresses). If you had a function that writes (e.g.) a buffer of 50 bytes, and wanted to call this 5 times with consecutive addresses), you would only need to do the erase if the block changes. So if all the buffers were being written to the same block, you would only do the erase once.
--- Quote End ---
To clarify,
simple "alt_write_flash()" will write data to flash located at the address, but erase :( the rest of the block.
fine-grained "alt_write_flash_block()" can only change bits '1' to '0' :( located at the address, and conserve the rest of the block.
EDIT 2:
Form document "Developping program using the HAL" :
--- Quote Start ---
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.
--- Quote End ---
That is the point that confuse the newbies.
To resume, as said by an other, to alter a specific location in a block while leaving the surrounding contents
unchanged, you can use the fine-grained flash access functions :
to read out the entire contents of the block to a buffer : alt_read_flash_block()
alter the value(s) in the buffer : buffer[42] = 123456 for example
erase the flash block : alt_erase_flash_block()
and finally write the whole block-sized buffer back to flash memory : alt_write_flash_block ()
With fine-grained flash access functions, DO NOT write to the next block. I experienced that ALL the flash get corrupted if I write more that one block.