Skip to content

Support for EEPROM #166

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
jgfoster opened this issue Oct 2, 2020 · 7 comments · Fixed by #183
Closed

Support for EEPROM #166

jgfoster opened this issue Oct 2, 2020 · 7 comments · Fixed by #183

Comments

@jgfoster
Copy link
Member

jgfoster commented Oct 2, 2020

As @per1234 explained here, SPI and Wire are platform bundled libraries and I see that mocks are included for them in arduino_ci. Is EEPROM similar? Should it be part of the base or an add-on like LiquidCrystal?

jgfoster pushed a commit to jgfoster/arduino_ci that referenced this issue Oct 3, 2020
@per1234
Copy link
Contributor

per1234 commented Oct 3, 2020

The primary difference between the EEPROM vs SPI and Wire libraries is that not all boards platforms have a bundled EEPROM library. The reason being that not all microcontrollers have EEPROM. Some boards platforms of microcontrollers without EEPROM provide an EEPROM library that uses flash memory to simulate EEPROM (example).

Platform Has EEPROM library
arduino:avr Y
arduino:megaavr Y
arduino:sam N
arduino:samd N
arduino:mbed N
arduino-beta:mbed N
arduino:arc32 Y

@ianfixes
Copy link
Collaborator

ianfixes commented Oct 5, 2020

Is this "bundled library" characteristic related to #140 ?

@per1234
Copy link
Contributor

per1234 commented Oct 5, 2020

No. It only means that the library is only available when compiling for one of the boards of the platform the library is bundled with.

For example, if you have the Arduino AVR Boards installed, then the EEPROM library is also installed and you can use it when compiling for the Uno. However, if you then try to compile a sketch that uses the EEPROM library for the Zero, compilation will fail:

fatal error: EEPROM.h: No such file or directory

 #include <EEPROM.h>
          ^~~~~~~~~~

The reason for this is that the library is AVR-specific. Making it accessible to other platforms would only be harmful, since it won't compile for other architectures.

@jgfoster
Copy link
Member Author

jgfoster commented Oct 5, 2020

How can I tell if EEPROM is supported by the board? In cpp/arduino/arv/ there are over 40 files that include #define EEPROM_SIZE but when I build for mega2560 that macro is not defined. It seems that it ought to be defined. Shall I just add it to iom2560.h? Or should it be added to iomxx0_1.h with the other EEPROM things (such as __EEPROM_REG_LOCATIONS__)?

@per1234
Copy link
Contributor

per1234 commented Oct 5, 2020

AVR has an E2END macro:
https://www.nongnu.org/avr-libc/user-manual/group__avr__io.html

As for a way to determine EEPROM support for any arbitrary board of any architecture, I don't know.

Another thing to consider might be that there is a significant difference in the way the ESP8266 and ESP32 libraries work. A sketch that uses the EEPROM library perfectly on AVR won't work at all on the Espressif boards if it doesn't call EEPROM.begin() and EEPROM.commit()/EEPROM.end() in order to write the data to flash. I don't know whether that's outside the scope of the project.

@ianfixes
Copy link
Collaborator

ianfixes commented Oct 6, 2020

It might be worth instrumenting the .begin() / .end() in GODMODE, if nothing else, so that library writers can validate their assumptions about these functions being called. I'm not familiar enough with how that's used in practice to say how that should be implemented though.

@per1234
Copy link
Contributor

per1234 commented Oct 6, 2020

Documentation of the additional API of the ESP9266/ESP32 boards platforms that extends the official Arduino EEPROM library API is here:
https://arduino-esp8266.readthedocs.io/en/2.7.4_a/libraries.html#eeprom

jgfoster pushed a commit to jgfoster/arduino_ci that referenced this issue Nov 9, 2020
* Introduce EEPROM support (Arduino-CI#166)
* Update CHANGELOG.md
* Only include EEPROM if board supports it.
* Add EEPROM_SIZE to mega boards.
* Move `EEPROM_SIZE` macro to `misc/default.yml`.
* Use E2END to calculate EEPROM_SIZE.
* EEPROM is tested by uno and due so we don't need to add mega2560 (one less file changed).
* Simplify reference to EEPROM library.
* adding tests for EEPROM
* test high memory and array read.
* add setup to reset memory before each test
* Add documentation of EEPROM (fix Arduino-CI#190).

Co-authored-by: Ian <[email protected]>
Co-authored-by: Elizabeth Ventura <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants