Does anyone know how to flash example code test_dospm of optibootloader

Hi guys,

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.

I am sharing the code GitHub link for the reference -(https://github.com/Optiboot/optiboot/tree/master/optiboot/examples/test_dospm).

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...)

(Most Arduinos still ship with Optiboot v4.x)

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.

Probably not. The new code would have to overwrite the old code that is in the same place(s)

Can I put this code in bootloader section to rewrite flash memory?

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.

can I use external EEPROM to flash data in application code section using spm instruction?