boot sector on ATmega128

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply
razvan784

boot sector on ATmega128

Post by razvan784 » Tue Dec 02, 2008 5:10 pm

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

Grendel
Rank 4
Rank 4
Posts: 167
Joined: Sat Dec 16, 2006 9:53 pm
Location: Oregon, USA
Contact:

Post by Grendel » Wed Dec 03, 2008 1:47 am

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.

Post Reply