Skip to content

EEPROM.length() always returns zero if using the default global EEPROM instance #5773

Closed
@hideakitai

Description

@hideakitai

Hardware:

Board: ESP32 Dev Module
Core Installation version: 1.0.6, 2.0.0
IDE name: Arduino IDE
Flash Frequency: 80Mhz
PSRAM enabled: No
Upload Speed: 921600
Computer OS: Windows 10

Description:

EEPROM.length() always returns zero if using the default global EEPROM instance. Using my own instance, like the eeprom_class example, I can get the length defined in the constructor (_user_defined_size) not the size defined in begin(size) (_size). Related to #2280.

Sketch: (leave the backquotes for code formatting)

#include "EEPROM.h"

void setup() {
  Serial.begin(115200);
  delay(1000);

  EEPROM.begin(0x100);
  Serial.println(EEPROM.length());  // always zero for global EEPROM instance
}

void loop() {
}

Expected behavior

EEPROM.length() should return the available size of EEPROM even if using the global instance.

Possible improvements

I have created two pull requests. If it looks good for you, please consider merging one of them.

#5774 Add EEPROM::capacity() method to get _user_defined_data and EEPROM::length() returns _size

  • capacity() method returns _user_defined_size that is set by the constructor
  • length() returns _size that is the true available size of EEPROM

#5775 Remove _user_defined_size and just use _size

I think this is better because _user_defined_size seems to be redundant for me. Just using _size is much clear.

  • _user_defined_size is removed because it is redundant in the current code
  • length() returns _size that is the true available size of EEPROM

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