How to erase just some bytes of Flash Memory?

a 夏天 提交于 2019-12-24 05:42:06

问题


My PIC18F87J11 only erases 1024 bytes at a time. Is there away to force it to only erase 2 bytes or more at a time?

I am making a Bootloader and sometimes only one line of the HEX file (16 bytes) changes for the application program, so I want to replace that line in memory with the new 16 bytes only . If I try to erase those 16 bytes, automatically 1024 bytes get erased too. Then I am forced to re-write them which takes some time and reduce the speed of the Bootloader.

Is there an alternative way of erasing something from flash memory without erasing 1024 byes? Hopefully there is.

Thanks!


回答1:


You cannot erase less than the "erase block size" of the underlying memory implementation. If that is 1024 bytes on your device (something you can verify) then that is the smallest size you can erase.

You may be able to copy the entire block to RAM (if available), modify only the necessary portions, erase the flash block, and then write it back, avoiding the need to re-upload unchanged portions from an external source.

In many of these technologies, there is also a direction you can write in without erasing - for example, the memory may permit changing a "1" to a "0", but only an erase cycle can change a "0" back to a "1". Depending on your precise needs, you may be able to design a scheme which takes advantage of this.



来源:https://stackoverflow.com/questions/23895253/how-to-erase-just-some-bytes-of-flash-memory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!