M168 bootloader

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

Hi @ all,

I've already a well working bootloader for the tiny85, but I have now problems with the Mega168.

I'm storing values to a page, I'd like to update. Unchanged values are read and stored again. I'm able to erase the page but the following page write doesn't work!
If I remove the page erase, the write works!!??!!

Any experiences, ideas?

best regards

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

missing 'boot_spm_busy_wait();' after erase?

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

I guess not!
After every spm command I call this function:

waitforflash:
in R19,SPMCSR
sbrc R19,0 ;selfprgen
rjmp waitforflash
ret

curtvm wrote:
missing 'boot_spm_busy_wait();' after erase?

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

Then I would suggest taking a look at the datasheet for '168, section 25.

I'm guessing (again) that you are not clearing the RWWSB bit via the RWWSRE bit ('85 does not have these).

Without much info provided, its hard to help.

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

Wulfinator83 wrote:
I've already a well working bootloader for the tiny85, but I have now problems with the Mega168.

Without code its absolutely unable to see your fault.

But you can look at my bootloader (User Projects).

There are two different programming methods for tiny and mega.

Please watch, that the Mega48 was an exception, it must be programmed like a tiny.

Peter

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

Hi folks! Thanks for your replies.

I've already read the datasheet and I thought I do it accordingly!
I'll paste my code, when I'm at home!
BUT, 2 questions!
1. Danni, I saw in your code, that you wait for the SPMEN flag every time you write a byte into the latch! (function do_spm) Is that needed?
2. I've just realized, that I'm erasing the page, reenabling the RWW, write the page and reenable the RWW again. Danni you do the reenabling just after programming! Could that be my failure? (at least, it seems to be unnecessary)

thx

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

Wulfinator83 wrote:
I've just realized, that I'm erasing the page, reenabling the RWW...
'The temporary buffer will auto-erase after a Page Write operation or by writing the RWWSRE bit in SPMCSR', which means if you have the temporary buffer filled, erase a page, then enable the rww section, you have then just erased the temporary buffer.

That's my third guess.

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

Wulfinator83 wrote:

1. Danni, I saw in your code, that you wait for the SPMEN flag every time you write a byte into the latch! (function do_spm) Is that needed?

I wrote a single function to do all the SPM stuff, thus checking the flag was also done on byte loading (doesn't harm).

Wulfinator83 wrote:

2. I've just realized, that I'm erasing the page, reenabling the RWW, write the page and reenable the RWW again. Danni you do the reenabling just after programming! Could that be my failure? (at least, it seems to be unnecessary)

If you not want to read the user flash until the next reset, maybe reenabling may not be needed (doesn't harm also).

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

curtvm wrote:
Wulfinator83 wrote:
I've just realized, that I'm erasing the page, reenabling the RWW...
'The temporary buffer will auto-erase after a Page Write operation or by writing the RWWSRE bit in SPMCSR', which means if you have the temporary buffer filled, erase a page, then enable the rww section, you have then just erased the temporary buffer.

That's my third guess.

That's it! Thank you folks!