Flash page size for Atmega32U4: 128 or 256 bytes?

I am updating my bootloader-programmer to handle the Leonardo which has a Atmega32U4 processor.

According to the datasheet the flash page size is 128 words (therefore 256 bytes) however when uploading with that as the page size I get multiple errors.

Changing to 128 byte page size the bootloader uploads without errors. However that is not consistent with the datasheet.

Has anyone found anything along these lines before? Is the documentation wrong? The page size documented for the Atmega328P is 64 words (128 bytes) and the bootloader-programmer has been working fine in the past using that figure.

The iom32u4.h file has SPM_PAGESIZE as (128), which is also used in the caterina bootloader (although it isn't immediately obvious in the bootloader whether it's using it as a byte count or word count.) iom328p.h also has SPM_PAGESIZE as 128...

Looking at avrdude.conf for this chip I see:

        memory "flash"
        paged           = yes;
        size            = 32768;
        page_size       = 128;
        num_pages       = 256;

The only way you can get 128 out of 256 pages from 32768 is if 128 is bytes and not words.

Also I found a PDF about using avrdude ( ftp://gnu.mirrors.pair.com/savannah/avrdude/avrdude-doc-5.6.pdf ) which states in the section about the configuration file:

memory <memtype>
    paged = <yes/no> ; # yes / no
    size = <num> ; # bytes
    page_size = <num> ; # bytes
    num_pages = <num> ; # numeric
    min_write_delay = <num> ; # micro-seconds

So that strongly supports the idea that the page size is 128 bytes. So the datasheet must be wrong? I got the latest one from Atmel and it still says 128 words.

Somebody else seems to have come across this issue at http://www.avrfreaks.net/forum/page-size-confusion.

The responses were pretty dismissive, however I don't believe that it was ever resolved properly. The OP just said it worked (for reasons he couldn't understand) if he disregarded the datasheet and used a page size of 128 bytes.

According to the USB DFU Bootloader Datasheet the page size is 128 bytes. All the evidence indicates a mistake in the processor datasheet.

Going to report it to Atmel?

How? I've looked at their page a few times and they seem to just refer you off to forums like AVR Freaks if you have questions.

Hmmm. I can remember seeing an email address for such things. I'll see if I can dig it up.

Don't worry, I made a myAtmel account, I'm getting closer to being able to submit a support request.

I don't think this is the email I had seen but several datasheets have literature@atmel.com in the boilerplate so I suspect that would work.

Oh, and I think CrossRoads has been through the experience. He may be able to help.

I managed to put in a support request so we'll see what happens. :slight_smile:

Maybe I'll get the same treatment on the AVR Freaks forum that the other guy did, that they just said he didn't understand the difference between bytes and words. :stuck_out_tongue:

A pretty hard mistake to make when you are writing code that programs chips successfully.

Anyway, the upshot of all this is that I am happy that my programmer now will program the Leonardo bootloader.

Atmega bootloader programmer

Senior members are sometimes condescending to each other so there is a high probability you are headed for a mocking.

I got a response from Atmel:

Created By: Rajaiswarya S (10/27/2014 4:00 AM)
[Recipients: Nick Gammon]

Hi Nick Gammon,

Unfortunately this is a typo in the Datasheet. This has been reported to our internal team. Thank you for reporting this.

The correct data is :
Flash is 64Words x 256Pages
Eeprom is 4Bytes x 256Pages

Sorry for any inconvenience caused.

Was the response through myAtmel or literature@atmel.com?

Hello all, I just take a chance to clear up words a bit.

Actually, checking on Wikipedia, which I did when reading on the Atmel datasheet, a word is a generic number and it has the width of the system it is referred to.

So, in a 8-bit system, a word is actually a byte, while it goes up in larger systems according to their architecture.

I suggest everyone including me to clear up completely every word in a sentence when it doesn't make sense, because the answer is most of the time in words incorrectly defined, or incorrect definition applied, and this single fact opens up to higher speed in general understanding.

myAtmel.

I swear that notifications in this forum are not working properly.

Bonven_III:
So, in a 8-bit system, a word is actually a byte, while it goes up in larger systems according to their architecture.

No, Atmel use "word" to refer to a 16-bit quantity, on their 8-bit systems.

Seems haphazard to me as well.