Code Monkey home page Code Monkey logo

eeprom_rotate's Introduction

Hello ๐Ÿ‘‹

Thanks for visiting my GitHub profile. Some info about me:

  • ๐Ÿง‘โ€๐Ÿญ I work as Product Owner at RAKwireless
  • ๐Ÿ’ป I'm a freelancer working on IoT projects, know more about me on my blog: Tinkerman
  • ๐ŸŽ“ But actually, I studied asthrophysics. Loved it, but hard to make a living out of it.
  • ๐ŸŒ Based in: Sant Pol de Mar, Catalunya
  • ๐Ÿ‘ป Profiles: Linkedin, Twitter, Telegram

Xose's github stats

Readme Card Readme Card Readme Card Readme Card Readme Card Readme Card

eeprom_rotate's People

Contributors

per1234 avatar xoseperez avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

eeprom_rotate's Issues

Library no persisting data

Hi all,

Guys, you should specify somewhere in the documentation that by default " you can't write the first 3 bytes of memory, or that it does not have any effect. Until someone understands how things work, and how the first 3 bytes are used by your library, and discovers that these are not somewhere hidden, and are the first 3 bytes of the memory block, it might drive him crazy. Yes are read the docs now, but it is not clear that the 3 bytes are part of the first 3 bytes we can access.

Thank you.

EEPROMr Begin getting into strange loop

I am using espurna. Recently i started getting this strange error -
After factory reset also the settings wont vanish. I looked all over in the code and all, but couldn't find something.
Then i checked into this library's code and added few more debug points and found out this that if magic values in sectors has this sort of pattern then the library will always pick up the last stored values and factory reset wont help. I think we might need to check the logic for .begin method again.
Below is debug log for better understanding the issue.

// Entering Begin Function
Checking Current Sector : 1019 
Magic value for sector #1019 is 128
Calculated CRC: 0xD769
Stored CRC    : 0xD769
Checking Current Sector : 1018 
Magic value for sector #1018 is 129
Calculated CRC: 0x92AB
Stored CRC    : 0x92AB
Found this sector to be new 1018 
Checking Current Sector : 1017 
Magic value for sector #1017 is 130
Calculated CRC: 0x92AE
Stored CRC    : 0x92AE
Found this sector to be new 1017 
Checking Current Sector : 1016 
Magic value for sector #1016 is 127
Calculated CRC: 0xD76B
Stored CRC    : 0xD76B
Found this sector to be new 1016 
Current sector is #1016
Current magic value is #127


// Entering Commit Function 

We re going to write now 
Current Sector Value : 127 
Writing to sector #1019
Writing magic value #128
Commited

// Entering Commit Function 
We re going to write now 
Current Sector Value : 128 
Writing to sector #1018
Writing magic value #129
Committed

From log its clear i have 4 sectors - 1019,1018,1017,1016
My program always does a commit, after initializing for the first time. And it does another commit after i send restart. So if the program keep doing 2 commits it'll enter into a loop, where it'll always start with sector 1016 and magic value 127. While everytime its always writing to sector 1018 and 1019....

Persist data after reboot

Hello, this lib can be used to persist data over reboots, like configuration values?

Thanks for your great job :)

Understanding how example code works

Hello. I am very interested to learn how to save EEPROM life expectancy. I have slightly changed the example code "basic" but whenever I write to EEPROM and try to read back from it, I always read 0. .

My full code:

/*
 *  This sketch shows sector hoping across reboots
 */

#include <EEPROM32_Rotate.h>

EEPROM32_Rotate EEPROMr;

void setup() {

    // Init DEBUG --------------------------------------------------------------

    Serial.begin(115200);
    delay(2000);
    Serial.println();
    Serial.println();

    // Init EEPROM32_Rotate ----------------------------------------------------

    // You can add partitions manually by name
    EEPROMr.add_by_name("eeprom");
    EEPROMr.add_by_name("eeprom2");

    // Or add them by subtype (it will search and add all partitions with that subtype)
    //EEPROMr.add_by_subtype(0x99);

    // Offset where the magic bytes will be stored (last 16 bytes block)
    EEPROMr.offset(0xFF0);

    // Look for the most recent valid data and populate the memory buffer
    EEPROMr.begin(4096);

    // -------------------------------------------------------------------------

    uint8_t data;
    uint8_t quantity;
    quantity = 10;
    Serial.printf("Position 0: 0x%02X\n", EEPROMr.read(0));
    Serial.printf("Position 1: 0x%02X\n", EEPROMr.read(1));
    Serial.printf("Position 2: 0x%02X\n", EEPROMr.read(2));
    Serial.printf("Position 5: 0x%02X\n", EEPROMr.read(5));
    Serial.printf("Position 6: 0x%02X\n", EEPROMr.read(6));
    Serial.printf("Data      : 0x%02X\n", data = EEPROMr.read(5));

    Serial.println();
    Serial.printf("Writing 0x%02X to data\n", quantity);
    //EEPROMr.write(0, data + 1);
    EEPROMr.writeUShort(5, 10);

    Serial.println();
    Serial.printf("Commit %s\n", EEPROMr.commit() ? "OK" : "KO");
    Serial.printf("Position 0: 0x%02X\n", EEPROMr.read(0));
    Serial.printf("Position 1: 0x%02X\n", EEPROMr.read(1));
    Serial.printf("Position 2: 0x%02X\n", EEPROMr.read(2));
    Serial.printf("Position 5: 0x%02X\n", EEPROMr.read(5));
    Serial.printf("Position 6: 0x%02X\n", EEPROMr.read(6));
    Serial.printf("Data      : 0x%02X\n", data = EEPROMr.read(5));

    Serial.println("2ND TIME WRITING TO EEPROM");
    quantity = quantity +5;

    Serial.printf("Position 0: 0x%02X\n", EEPROMr.read(0));
    Serial.printf("Position 1: 0x%02X\n", EEPROMr.read(1));
    Serial.printf("Position 2: 0x%02X\n", EEPROMr.read(2));
    Serial.printf("Position 5: 0x%02X\n", EEPROMr.read(5));
    Serial.printf("Position 6: 0x%02X\n", EEPROMr.read(6));
    Serial.printf("Data      : 0x%02X\n", data = EEPROMr.read(6));
    
    
    Serial.printf("Data      : 0x%02X\n", data = EEPROMr.read(0));

    Serial.println();
    Serial.printf("Writing 0x%02X to data\n", quantity);
    //EEPROMr.write(0, data + 1);
    EEPROMr.writeUShort(6, quantity);

    Serial.println();
    Serial.printf("Commit %s\n", EEPROMr.commit() ? "OK" : "KO");
    Serial.printf("Position 0: 0x%02X\n", EEPROMr.read(0));
    Serial.printf("Position 1: 0x%02X\n", EEPROMr.read(1));
    Serial.printf("Position 2: 0x%02X\n", EEPROMr.read(2));
    Serial.printf("Position 5: 0x%02X\n", EEPROMr.read(5));
    Serial.printf("Position 6: 0x%02X\n", EEPROMr.read(6));
    Serial.printf("Data      : 0x%02X\n", data = EEPROMr.read(6));
    Serial.printf("Data      : 0x%02X\n", data = EEPROMr.read(0));

}

void loop() {}

I am doing 2 write cycles, first I write 10 to address 5, then I write 15 to address 6, during the read operation, I am not able to read back any of the values that I have set.

EEPROM.update support

Hello @xoseperez!
Original EEPROM library has update method, but you haven't added it into this lib. Are you checking previous data before writing (like original update) or it should be done outside?
And if you don't do that then could you, please, explain will check of the previous data outside improve something, or it's redundant?

Thank you in advance.

Request: Support external EEPROM

Hi there,

Understanding that you want to leave your lib as compatible with the arduino EEPROM as possible, it would be valuable if you could support external I2C EEPROMs too.

Those work well with Wire.h.
Only things to specify are

  • clock pin
  • data pin
  • page size
  • size of eeprom
  • adress

Out there, unfortunately, no compareble libs can be found.
If you lack of time, give me a message and we may figure something out together.

Thank you for you work and kind regards

Stretched wear leveling

I'd like to use a smaller emulated EEPROM and stretch it over multiple sectors to increase the life of the NOR flash. For example, I only want to store 8 bytes, but I want to update them once per minute. If I use a full sector to store these 8 bytes, that means I'll be erasing the sector over 40,000 times per month. With your clever rotation trick, I could use 4 sectors; then I will only use a little over 10,000 erases per month (per sector). That's still a lot.

But if I declare I only need 10 bytes, and if you store 2 more bytes for CRC, I should be able to do the same with only 24 erases per month per sector.

Start by erasing the "next" sector. Then write the 12 bytes (10 bytes+CRC) at offset 0. A minute later, store the next 12 bytes at offset 12. Keep going until the sector is full, then move on to the next sector.

If we keep the "next" sector erased in advance, there should be no need to track the "latest" value since it will be the last one that is not all 0xFF, whose CRC validates, and which is in the sector before the first erased one (since the "next" sector is always erased).

The EEPROM library already lets us write fewer bytes than a whole sector into flash. But it doesn't currently let us "append" to an already-erased sector.

Have you tried something like this? I think it will work, but it does depend on the spi-nor being used. From the code, it does appear the NOR or the SPI library requires us to write in 32-bit chunks; that's probably fine. I'd be happy getting by with only 100 PEC per year instead of 500,000.

Can't seem to enable debug output

Hi,

Sorry, this is a question but I can't find how to label it as such.

I want to see the debug output from EEPROM_Rotate.

I have added at the top of my Arduino sketch, before the #includes:

#define DEBUG_EEPROM_ROTATE_PORT Serial

so basically my sketch is like this:

#define DEBUG_EEPROM_ROTATE_PORT Serial
#include <EEPROM_Rotate.h>

EEPROM_Rotate EEPROMR;

void setup() {
  Serial.begin(74880);
  EEPROMR.size(4);
  EEPROMR.begin(512);
  // .......
}

Everything is working, but I'm not seeing any debug output such as this:

https://github.com/xoseperez/eeprom_rotate/blob/master/src/EEPROM_Rotate.cpp#L236

What am I missing?

Mb or MB??

In https://github.com/xoseperez/eeprom_rotate/blob/master/README.md you use Mb a lot.

I would immediately assume you mean MB (megabytes), but then it turns out that for whatever reason people sometimes do refer to 512kB flash size boards as "4Mb" with a lowercase b as in "4 megabit" which literally is equal to 512 kBytes.

So now I wonder whether you are actually correctly using Mb meaning megabits, or if you mean MB i.e. mehabytes.

_SPIFFS_end no longer defined on esp arduino

It seems that _SPIFFS_end will not be defined in future versions of esp8266 arduino,
and has been replaced with _FS_end (as well as other declarations):
esp8266/Arduino@a389a99

In this situation, I can not compile any example from this lib and the espurna project :(
error:

c:/programy/arduino/hardware/esp8266com/esp8266/tools/xtensa-lx106-elf/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: C:\TEMP\arduino_build_8160\libraries\eeprom_rotate\EEPROM_Rotate.cpp.o:(.text._ZN13EEPROM_Rotate8reservedEv+0x4): undefined reference to `_SPIFFS_end'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.