Skip to content

SDRAM.begin can be repeated, possibly corrupting static allocation #1105

@JwX000

Description

@JwX000

Hello!
it seems that SDRAM.begin can be repeated with different parameters without warning. For example:

SDRAM.begin(SDRAM_START_ADDRESS + 2 * 1024 * 1024);
    // 2MB of contiguous memory available at the beginning

    uint32_t* framebuffer = (uint32_t*)SDRAM_START_ADDRESS;

    // We can't allocate anymore the huge 7MB array
    SDRAM.begin(SDRAM_START_ADDRESS);

    uint8_t* myVeryBigArray = (uint8_t*)SDRAM.malloc(7 * 1024 * 1024);
    if (myVeryBigArray == NULL) {
        Serial.println("Oops, too big :)");
    }

allocates 7MB without error

That can be problematic when - for example - Arduino_H7_Video for Arduino GIGA internally allocates nearly all SDRAM for framebuffers

#if defined(ARDUINO_GIGA)
  /* Configure SDRAM */
  SDRAM.begin(dsi_getFramebufferEnd());
#endif

and the user is not prevented from re-initializing it

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions