SPM modifying flash

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi there,

OK, so I've got some code done now for modifying flash from a SRAM variable. The SRAM variable is a 128 byte array, the size of a page in the ATMEGA16, which I am using.

The SPM instruction seems to get setup correctly, and all the pointers seem to be pointing to the right place, but it doesn't want to write a page.

I have tried this in AVR simulator V4.07, and on an actual device running some other code aswell. No flash gets modified.

One thing that does confuse me is the temporary buffer for the SPM instruction which you need to fill with the data before executing a page write.

I have the Z pointer pointing to the word in flash that I want to update when going through the temporary buffer fill part, but something doesn't ring right there? Is this wrong?

Also, I presume that the latest AVR studio 4 does deal with the SPM instruction OK?

I have attached some example code of the routines that are not working properly yet. Any help with this would be great.

Many Thanks, Brian Sidebotham.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Have you confused the word addressing requirements and the byte requirements.

Also if the Z is not correctly adjusted then any atempt at writting to flah can go belly up.
PLease find attached code for mega8 this works with XMODEM

Mike

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Mike!

Thanks for your reply again.

doesn't seem to be an attachment there, I will simulate the AVR109 code though to see how the simulator responds to the SPM instruction

When I execute a page erase, or page write command I expect to see the RWWSB bit in SPMCR get set, but it doesn't seem to.

I have added a wait while SPMEN is 1 at the end of my DO SPM routine, and then I have added a RWW section re-enable to the end. The datasheet seems to think this will be necessary as I am flipping in and out of both types of memory.

Thanks again,

Brian Sidebotham.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Lets try again with the code

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Mike,

Thanks again for the code. It seems like I had to chuck the whole erase_page + write_page routines into NRWW memory. I have done that, and it simulates fine now. Changes as I expect, etc.

Thank you very much for your help. Now I need to see if it's quick enough to do what I want to do ;)

Thanks, Brian.