I am trying to do self-programming by using example code test_dospm in optibootloader but after flashing the code in Arduino when I am running code on the serial terminal I am unable to write data on flash pages after entering data serially.
So, is this code should be flashed in bootloader section or in the application section. Kindly suggest me the way to test this code.
First you have to install the new version of the Optiboot bootloader (at least version 8.0)
After that, the test_dospm example is just a normal Arduino sketch.
(I guess test_dospm could use a comment to that effect...)
Thanks westfw for your advice now I am able to write data in flash memory but is it possible to rewrite the application using this method. So that I can update my code during runtime serially.
The do_spm feature is mainly for writing relatively small amounts of data to the areas flash memory not already used by your sketch, not for re-writing code.