[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] bootloader
From: |
Torsten Mohr |
Subject: |
Re: [avr-gcc-list] bootloader |
Date: |
Sun, 17 Jul 2005 08:43:28 +0200 |
User-agent: |
KMail/1.8 |
Hi,
thanks for your answers to my question.
Still, i experience problems with my bootloader. The bootloader
gets some commands via USB, that way i can also read back where
a programming failure occurred. I sometimes experience some bit
failures at random addresses, an example:
flash.pl: at 0x000118, should be 0x2B, is 0x29
The bootloader is at 0x1e000, the lock bits byte is 0xff.
When programming i first erase the complete flash from 0x0000 to 0x1dfff.
If an erase of a page fails, i repeat the erase of that page up to five times.
I then transfer the data (with CRC checksum) of one page and program it.
I then verify it and this sometimes leads to a failure.
Down below i attached the relevant part of the code that i use for this.
Can anybody see a reason why i experience problems (the code is based on
the examples in avr-libc-user-manual-1.2.3)?
Can this be HW related (i did not program that chip too often, maybe 100
i estimate)? The supply voltage also looks stable.
When i reprogram the whole chip with avrdude, it all works fine again.
Best regards,
Torsten.
// program a page
void fbl_sector(uint32_t addr, uint8_t* data, uint16_t len) {
uint16_t i;
uint8_t sreg;
uint16_t d;
sreg = SREG;
cli();
eeprom_busy_wait();
for(i = 0; i < SPM_PAGESIZE; i += 2) {
if(i < len) {
d = *data++;
d += (uint16_t)(*data++) << 8;
}
else {
d = 0xffff;
}
boot_page_fill(addr+i, d);
}
boot_page_write(addr);
boot_spm_busy_wait();
boot_rww_enable();
SREG = sreg;
}
// verify
uint8_t fbl_compare(uint32_t addr, uint8_t* data, uint16_t len) {
uint16_t i;
uint8_t d;
for(i = 0; i < SPM_PAGESIZE; i++) {
if(i < len) {
d = *data++;
}
else {
d = 0xff;
}
if(pgm_read_byte_far(addr++) != d) {
return 0;
}
}
return 1;
}
// the part that drives the erasing
case FBL_ERASE:
fail = 0;
for(addr = 0; addr < FBL_LAST_ADDRESS; addr += SPM_PAGESIZE) {
if(!fbl_sector_is_clear(addr)) {
fbl_sector_clear(addr);
}
if(!fbl_sector_is_clear(addr)) {
if(fail == 0) {
fail = 1; // do this only once
fail_addr = addr;
}
}
}
> Torsten,
>
> From within a bootloader (i.e. in-system reprogramming), erasing the
> flash page is only necessary once before writing it. Make sure you
> have the boot lock bits set correctly.
>
> -B
>
> On Jul 14, 2005, at 12:36 PM, Torsten Mohr wrote:
> > Hi,
> >
> > browsing through the sources of avrdude, i found that erasing a
> > chip is repeated up to 5 times until the chips flash is erased.
> > So the erase command is not only performed ONCE, but up to
> > five times.
> >
> > Is the same necessary or useful when from within a bootloader?
> >
> >
> > Programming bytes seems to be done only once, is that correct?
> > Does it make sense to repeat the programming of bytes (is that
> > even possible)?
> >
> >
> > Best regards,
> > Torsten.
> >
> >> Hi,
> >>
> >> the bootloader i write at the moment basically works, but i
> >> experience the
> >> problem that erasing/programming sometimes fails when programming
> >> with my own bootloader.
> >>
> >> When programming via avrdude via the parallel port, all works fine.
> >>
> >> So now i wonder if my strategy for erasing/programming is wrong.
> >>
> >>
> >> 1. In the documentation in avr-libc-usermanual-1.2.3 it says
> >> boot_page_erase(page). It should say boot_page_erase(address),
> >> is that right?
> >>
> >> 2. I only call erase/program once and i verify the erase/program
> >> directly after that. Can this be a problem?
> >>
> >>
> >> What else could be a problem when just using the supplied functions
> >> in avr-libc-1.2.3? Should it work exactly the same as with avr-dude
> >> via parallel port?
> >>
> >>
> >> Best regards,
> >> Torsten.
> >>
> >>
> >> _______________________________________________
> >> AVR-GCC-list mailing list
> >> address@hidden
> >> http://lists.nongnu.org/mailman/listinfo/avr-gcc-list
> >
> > _______________________________________________
> > AVR-GCC-list mailing list
> > address@hidden
> > http://lists.nongnu.org/mailman/listinfo/avr-gcc-list
>
> ========================================================
> One machine can do the work of fifty ordinary men. No machine can do
> the work of one extraordinary man.
> --Elbert Hubbard