Skip to content
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

[ESP8266] Conflict if EEPROM is used in main code. #41

Closed
miky2k opened this issue May 21, 2019 · 12 comments · Fixed by #61
Closed

[ESP8266] Conflict if EEPROM is used in main code. #41

miky2k opened this issue May 21, 2019 · 12 comments · Fixed by #61
Assignees
Labels
enhancement New feature or request

Comments

@miky2k
Copy link

miky2k commented May 21, 2019

I use in my esp8266 emulated EEPROM in main code and begin it with (4096) in size for main
code purpose(only 1024 byte used), is possible to avoid in library eeprom size call and add start pointer so i can initialize bigger area and put ina2xx data upper o lower main code data?

@miky2k
Copy link
Author

miky2k commented May 21, 2019

EEPROM.put((deviceNumber *sizeof(inaEE))+1024,inaEE);

EEPROM.get((deviceNumber *sizeof(inaEE))+1024,inaEE);

Should put data at 1024 start address.

@SV-Zanshin SV-Zanshin self-assigned this May 21, 2019
@SV-Zanshin
Copy link
Collaborator

Adding the 1024 byte offset would break all other implementations, so making that change to the base software is not possible.

It might be possible to change the class instantiation to have an optional offset for the beginning of the EEPROM used by the library, e.g. INA_Class INA(1024); // instantiate the class with EEPROM offset 1Kb

@SV-Zanshin SV-Zanshin added the enhancement New feature or request label May 21, 2019
@miky2k
Copy link
Author

miky2k commented May 21, 2019

And if offset is specified in istantiation no EEPROM.begin should be done in library.

@SV-Zanshin
Copy link
Collaborator

At the moment, the INA library initializes with a EEPROM.begin(512) for the 8266. So in order to remain backwards compatible, I wouldn't want to change this. I would expect that if the library has already been initialized a second call won't re-initialize it. Can you check the 8266 code to see what would happen with a second call to begin()?

@miky2k
Copy link
Author

miky2k commented May 22, 2019

void EEPROMClass::begin(size_t size) {

  if (size <= 0)
    return;
  if (size > SPI_FLASH_SEC_SIZE)
    size = SPI_FLASH_SEC_SIZE;

  size = (size + 3) & (~3);

  //In case begin() is called a 2nd+ time, don't reallocate if size is the same
  if(_data && size != _size) {
    delete[] _data;
    _data = new uint8_t[size];
  } else if(!_data) {
    _data = new uint8_t[size];
  }

  _size = size;

  noInterrupts();
  spi_flash_read(_sector * SPI_FLASH_SEC_SIZE, reinterpret_cast<uint32_t*>(_data), _size);
  interrupts();

  _dirty = false; //make sure dirty is cleared in case begin() is called 2nd+ time
}```

Seems that second call destroy data from first call.

@SV-Zanshin
Copy link
Collaborator

The code indicates that the old data is only destroyed and space re-allocated if the size is different. Perhaps then adding 2 parameters to the instantiation call might be the solution :

INA_Class INA(2056,1024); // instantiate the class with EEPROM size 2Kb and offset 1Kb

@SV-Zanshin
Copy link
Collaborator

I'm on the road (or, better put, at sea) at the moment and don't have access to an Arduino. Once I get access I'll look into making these changes and will see if that can be implemented.

@SV-Zanshin
Copy link
Collaborator

I've just looked into the open issues - sorry for the delay. I'll see about changing the class instantiation to accommodate this

@SV-Zanshin
Copy link
Collaborator

Sorry for the lengthy delay, this issue slipped between the cracks. Now that I have some time on my hands I will look into it.

@SV-Zanshin
Copy link
Collaborator

Here's an option - I can expose a public variable, "EEPROM_offset", which will be applied to all EEPROM Read & Write commands. The default is "0" but another value can be written to the variable before the begin() method is called. That way a specific number of bytes at the beginning of the EEPROM range can be reserved.

@fg89o
Copy link

fg89o commented Jul 11, 2020

What is the state of this issue? I have the same problem with an ESP32

@SV-Zanshin
Copy link
Collaborator

SV-Zanshin commented Jul 12, 2020

I still don't want to change the instantiation or add ESP32 and ESP8266 specific code, so I think that the last suggestion, exposing a variable "_EEPROM_offset" which can be set prior to calling "begin()" which will apply an offset to the first EEPROM address used.

SV-Zanshin pushed a commit that referenced this issue Jul 12, 2020
SV-Zanshin pushed a commit that referenced this issue Jul 12, 2020
Added offset to the begin() method and reformatted document with clang-format
SV-Zanshin pushed a commit that referenced this issue Jul 12, 2020
@SV-Zanshin SV-Zanshin mentioned this issue Jul 12, 2020
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants