Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hideakitai opened this issue Oct 18, 2021 · 0 comments · Fixed by #5775
Closed

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

hideakitai opened this issue Oct 18, 2021 · 0 comments · Fixed by #5775

Comments

@hideakitai
Copy link
Contributor

hideakitai commented Oct 18, 2021

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
me-no-dev pushed a commit that referenced this issue Oct 25, 2021
Summary

Related to the issue #5773 and #2280.

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

_user_defined_size is removed from EEPROMClass
EEPROMClass::length() returns _size that is the true available size of EEPROM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant