Skip to content

EEPROM.length() returns zero by default? #2280

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
aphelps opened this issue Jan 6, 2019 · 4 comments
Closed

EEPROM.length() returns zero by default? #2280

aphelps opened this issue Jan 6, 2019 · 4 comments
Labels
Status: Stale Issue is stale stage (outdated/stuck)

Comments

@aphelps
Copy link

aphelps commented Jan 6, 2019

Is there a design reason that EEPROM.length() is returning the value of _user_defined_size rather than _size? It would appear that the _user_defined_size is only set by the constructors and is never used, whereas the size specified to EEPROM.begin() is the one that all other EEPROM functions use to limit the writable area.

To be consistent with the Arduino EEPROM API for AVRs (where EEPROM.length() returns the actual EEPROM limit for the chip), it would seem to be more logical for EEPROM.length() to either return the size specified in EEPROM.begin() or to return SPI_FLASH_SEC_SIZE when _user_defined_size hasn't been set.

I'd be happy to submit a patch if appropriate.

For context, I'm working on converting some personal library code to work on my existing boards and a new one based on the Esp32, and ran into this probably while doing so.

@lbernstone
Copy link
Contributor

It is certainly worth discussion, as the current result seems overly simplistic. I haven't really used _user_defined_size. Are there situations where it would not just be length = _user_defined_size ? _user_defined_size : _size?

@aphelps
Copy link
Author

aphelps commented Jan 18, 2019

Its not at all clear to me what the intent of _user_defined_size is. The only size used for limits on the IO in this class is the one passed into EEPROM.begin(size_t size),_user_defined_size only appears in the initializer and EEPROM.length(). ie in the current code:

void EEPROMClass::write(int address, uint8_t value) {
  if (address < 0 || (size_t)address >= _size)
    return;
  if (!_data)
    return;

So as I think it would just need to be:

uint16_t EEPROMClass::length ()
{
  return _size;
}

_user_defined_size seems to me like something that was intended by the original author to be used for something that was never implemented.

@stale
Copy link

stale bot commented Aug 1, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Status: Stale Issue is stale stage (outdated/stuck) label Aug 1, 2019
@stale
Copy link

stale bot commented Aug 15, 2019

This stale issue has been automatically closed. Thank you for your contributions.

@stale stale bot closed this as completed Aug 15, 2019
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
Status: Stale Issue is stale stage (outdated/stuck)
Projects
None yet
Development

No branches or pull requests

2 participants