SPM from application area?

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

Today, I tried to programm a "Bootloader-Update" Prgoram.
It should be flashed as a regular programm and then copy the new bootloader to the bootloader section.

The AVR in question is the AT90PWM316, configured to 1k bytes bootloader size. Neighter application ROM nor Bootloader Area is protected by lock bits are programmed.

So, the application area is 0x000-0x3bFF and BL area is 0x3C00-0x3FFF.

However, the programm does not work as expected:
It seems, that I cannot SPM from the "application area". The calls are simply ignored.

I made the follwing experiment: I linked the code to 0x3800. The controller is erased. When I set the BL Size to 2k, flash only the BL (chip erased before that) the programm works.
(copying some bytes to 0x3c00).

When I reduce the size of the bootloader to 1k, and redo that on the (erased) controller, it won't copy the bytes.

Has someone also seen this, that you cannot SPM if your code runs outside the configured bootloader section?

I thought, it only needed to be in the RWW section....

(note, the code is *really* executed, even if the reset vector is "0", Verified with a dragon, and also by manually jumping to the right address... Interrupts are never enabled.

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

You should read the bootloader section of an avr datasheet some more. From the ATMega32 datasheet:

Quote:
The Application section is the section of the Flash that is used for storing the application code. The protection level for the application section can be selected by the Application Boot Lock bits (Boot Lock bits 0), see Table 95 on page 247. The Application section can never store any Boot Loader code since the SPM instruction is disabled when executed from the Application section

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

thanks... I missed that section...

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

You're welcome. AFAIU, the disabling of SPM from application space was a decision to improve stability by disallowing self-modifying code. But, I haven't read definitive documentation stating that.

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

kmr wrote:
You're welcome. AFAIU, the disabling of SPM from application space was a decision to improve stability by disallowing self-modifying code. But, I haven't read definitive documentation stating that.

Probably. But the downside is, that it also disables other useful things. (For example data storage in flash, for "almost const data" and having a (seperated) bootloader at the same time.

(Selfmodifing code. Right, ugly. But if the user decides to do that against all advices, I think he gonna learn it the hard way. But this is no excuse for a hw lock.)

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

Only the SPM instruction itself needs to be executed from the bootloader
area. So you could always simply call a function within the bootloader
area to have it perform the actual SPM, and still retain the normal
bootloader functionality.

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.