[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-chat] ATmega2561: bootloader can not write in application section
From: |
Thomas Richter |
Subject: |
[avr-chat] ATmega2561: bootloader can not write in application section |
Date: |
Fri, 09 Mar 2007 14:06:23 +0100 |
User-agent: |
Thunderbird 1.5.0.10 (Windows/20070221) |
Hi,
why it is not possible for my bootloader application to write into
application flash section?
I use ATmega2561. My code uses the AVR libc functionality (installed
with WinAVR-20070122 package). To prevent protection mode I set all boot
loader lock bits to "1".
Here the important parts of my code:
in main():
{
...
#if defined(__AVR_ATmega2561__)
// no restrictions for SPM or (E)LPM accessing the Application Section
boot_lock_bits_set_safe((1<<BLB12)); // please compare tables 149
& 150 at pages 342, 343
boot_lock_bits_set_safe((1<<BLB11));
boot_lock_bits_set_safe((1<<BLB02));
boot_lock_bits_set_safe((1<<BLB01));
// boot_lock_bits_set_safe(1<<LB2); // no memory lock features
enabled
// boot_lock_bits_set_safe(1<<LB1);
#endif // __AVR_ATmega2561__
...
}
The function to write my data (stored at gBuffer) one page into flash:
uint8_t writeFlashPage(uint16_t waddr, pagebuf_t size)
{
uint32_t pagestart = (uint32_t)waddr;
uint32_t baddr = pagestart;
uint16_t data;
char *tmp = gBuffer;
uint8_t result = OK;
// infront writing erase the flash page
if (eraseFlashPage(waddr) == OK)
{ // Erase Ok
do {
data = *tmp++;
data |= *tmp++ << 8;
boot_page_fill(baddr, data); // call asm routine.
baddr += 2; // Select next word in memory
size -= 2; // Reduce number of bytes to write by two
} while (size); // Loop until all bytes written
boot_page_write(pagestart); // Store buffer in flash page
boot_spm_busy_wait(); // Wait until the memory is written.
boot_rww_enable(); // Re-enable the RWW section
}
else // erase was not possible
result = NOK;
return (result);
}
The function to erase one flash page:
uint8_t eraseFlashPage(uint16_t waddr)
{
uint32_t pagestart = (uint32_t)waddr;
uint16_t data = 0;
uint8_t result = OK;
uint16_t i = 0;
boot_page_erase (pagestart); // erase the page
boot_spm_busy_wait (); // Wait until the memory is erased.
for (i=0; i<SPM_PAGESIZE; i+=2) // over all words in memory
{
#if defined(RAMPZ)
data = pgm_read_word_far(pagestart+i);
#else
data = pgm_read_word_near(pagestart+i);
#endif
if (data != 0xFFFF) result = NOK; // NOK
}
return (result);
}
Thanks for any help.
Regards,
Thomas
- [avr-chat] ATmega2561: bootloader can not write in application section,
Thomas Richter <=
- RE: [avr-chat] ATmega2561: bootloader can not write in application section, Eric Weddington, 2007/03/09
- Re: [avr-chat] ATmega2561: bootloader can not write in application section, Thomas Richter, 2007/03/09
- RE: [avr-chat] ATmega2561: bootloader can not write in application section, Eric Weddington, 2007/03/09
- Message not available
- Re: [avr-chat] ATmega2561: bootloader can not write in application section, Thomas Richter, 2007/03/09
- RE: [avr-chat] ATmega2561: bootloader can not write in applicationsection, Eric Weddington, 2007/03/09
- [avr-chat] RE: ATmega2561: bootloader can not write in applicationsection, freemanland, 2007/03/19
- RE: [avr-chat] RE: ATmega2561: bootloader can not write inapplicationsection, Eric Weddington, 2007/03/19