Skip to content

USE_RAM_DESCRIPTORS checks incorrectly calculate RAM usage #135

@hraftery

Description

@hraftery

In LUFAConfig.h, USE_RAM_DESCRIPTORS is set if (RAMEND - RAMSTART) >= 512. Assumedly this is to free up Flash by putting the USB Descriptor structs in RAM if the MCU has at least 512 bytes of SRAM.

But RAMEND is the last address of RAM, so RAMEND - RAMSTART returns one less than the RAM size. For example, for the atmega16u2, RAMEND is defined as (RAMSTART + RAMSIZE - 1) where RAMSIZE is 512.

The USB Descriptors seem to occupy 138 bytes, so assumedly would fit in the 16u2's 512 bytes of SRAM. Alas, there's a second issue - HoodLoader2 reserves the first 386 bytes for the rx/tx buffers! So the check fails anyway, because 386 + 138 > 512.

So I think the fix should be to compensate for RAM_OFFSET in the LUFAConfig check, and maybe for the size of the descriptors if we can get that accurate, but I'm not quite sure where responsibility lies...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions