i use atemga2560 mcu,want write some data to the flash,and the program regin not locked.this is my code,could you please help me how to write flash in the shetch?
The Set Program Memory (SPM) instruction is the only instruction that can write into FLASH. The SPM instruction can only be executed in the Boot Loader Segment. That means only the bootloader can write into FLASH.
If you need to write into FLASH you will have to modify the bootloader so you can call a function in the bootloader to do the actual write.
johnwasser:
The Set Program Memory (SPM) instruction is the only instruction that can write into FLASH. The SPM instruction can only be executed in the Boot Loader Segment. That means only the bootloader can write into FLASH.
If you need to write into FLASH you will have to modify the bootloader so you can call a function in the bootloader to do the actual write.
ok,we just found the truth,thanks.
call a function from the bootloader seems to use the assemble code, do someone have the experience on it?
also,the mcu2560 has 256Kbytes FLASH,the code just about 60Kbytes,whether i need to update program via ethernet in purpose or not,its just a big waist...why not we use it for some data storage instead of some parallel or SPI FLASH application?
waysleehh:
also,the mcu2560 has 256Kbytes FLASH,the code just about 60Kbytes,whether i need to update program via ethernet in purpose or not,its just a big waist...why not we use it for some data storage instead of some parallel or SPI FLASH application?
no.at the beginning,i want to update my program by these steps:
receive the updated program data from the ethernet,then store these data on a special defined address of the 256KByte flash.
then make a update flag in eeprom or flash,reset the device.
modify the bootloader to check that update flag,if is true,then bootloader make a memory copy from the special defined address to the beginning of the program 0x0.
4.reset when finished the memory writing.
if those steps success,i think the program must be updated successfully