Skip to content

Krake Memory Size Sketch, #436

@ForrestErickson

Description

@ForrestErickson

Memory Size on ESP32,

Asked an AI:

Is there a sketch to load to test the allowed code size on my ESP32 WROOM?

Memory Reporting Code

It came back with this code:

/*
ESP32_CODE_SIZE
*/

#include <Arduino.h>
#include "esp_ota_ops.h" // For partition info

void setup() {
  Serial.begin(115200);
  delay(2000); // Wait for Serial Monitor

  Serial.println("\n--- ESP32 Flash & Partition Report ---");

  // 1. Total Physical Flash Size
  uint32_t flashSize = ESP.getFlashChipSize();
  Serial.printf("Total Physical Flash: %u bytes (%.2f MB)\n", 
                flashSize, flashSize / (1024.0 * 1024.0));

  // 2. Current App Partition Size (The "Allowed" Code Size)
  const esp_partition_t* running = esp_ota_get_running_partition();
  if (running != NULL) {
    Serial.printf("Current App Partition Label: %s\n", running->label);
    Serial.printf("Allowed Code Size: %u bytes (%.2f MB)\n", 
                  running->size, running->size / (1024.0 * 1024.0));
  }

  // 3. Current Code Usage
  uint32_t sketchSize = ESP.getSketchSize();
  uint32_t freeSpace = ESP.getFreeSketchSpace();
  Serial.printf("Current Sketch Size: %u bytes\n", sketchSize);
  Serial.printf("Remaining Space in Partition: %u bytes\n", freeSpace);

  Serial.println("---------------------------------------\n");
}

void loop() {
  // Do nothing
}

The Code Ran and Reported

ets Jul 29 2019 12:21:46

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:4832
load:0x40078000,len:16460
load:0x40080400,len:4
load:0x40080404,len:3504
entry 0x400805cc

--- ESP32 Flash & Partition Report ---
Total Physical Flash: 4194304 bytes (4.00 MB)
Current App Partition Label: app0
Allowed Code Size: 1310720 bytes (1.25 MB)
Current Sketch Size: 288464 bytes
Remaining Space in Partition: 1310720 bytes
---------------------------------------


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions