I found a peculiar bevaviour when fiddling with some bootloader code.
My bootloader is progamming the Flash from an external 512kB SRAM. This SRAM is mapped in (and paged) at 0x8000-0xFFFF.
I have a function to fill each flash page for the SPM. This includes setting the RAMPZ depending on which Flash page I'm going to program.
It all goes well, until I fill a page that is using data from the LAST 256 bytes of RAM.
The loop looks like this (wp is a word ptr to the data) :
for (i = 0; i < nWords; i++, wp++) SpmBufferFill(i, *wp);
When wp is 0xFF00, the last tour through the for loop will cause the pointer to wrap to 0, although it's never accessed at that value.
When this happens, the page programmed will be all FF's !!!
As a test, I tried decrementing wp by 2 before the loop, so it will not wrap, and everything was fine again.
It seems the wrapping causes the problems, perhaps it's affecting RAMPZ or something.
It sure is weird.
I worked around the problem by copying the RAM block to a local internal RAM block before the loop.
Have anyone had similar problems, or done any obervations that shows a similar behaviour ?
I will contact Atmel, to hear what they have to say about this one.