Page 1 of 1

boot sector on ATmega128

Posted: Tue Dec 02, 2008 5:10 pm
by razvan784
The latest version (20081126) doesn't work from the boot sector in ATmega128 and probably other devices when the code needs to read from Flash at >64k. As a workaround, I modified usbportability.h to use far reads (ELPM instead of LPM), but it's not elegant, as non-boot code should use the faster near reads (LPM).

Code: Select all

#if defined (__AVR_ATmega128__)
#define USB_READ_FLASH(addr)    pgm_read_byte_far(addr)
#else
#define USB_READ_FLASH(addr)    pgm_read_byte(addr)
#endif

Posted: Wed Dec 03, 2008 1:47 am
by Grendel
Hm, w/ gcc this could be modified to

Code: Select all

#if FLASHEND > 0xFFFF
#define USB_READ_FLASH(addr)    pgm_read_byte_far(addr)
#else
#define USB_READ_FLASH(addr)    pgm_read_byte(addr)
#endif

to generally allow for devices w/ more than 64k flash. avr/io.h defines FLASHEND based on the selected device.