MCUdude / MegaCore

Arduino hardware package for ATmega64, ATmega128, ATmega165, ATmega169, ATmega325, ATmega329, ATmega640, ATmega645, ATmega649, ATmega1280, ATmega1281, ATmega2560, ATmega2561, ATmega3250, ATmega3290, ATmega6450, ATmega6490, AT90CAN32, AT90CAN64 and AT90CAN128
Other
384 stars 118 forks source link

Ring / Circular buffer + write to own flash? #174

Closed rkertesz closed 3 years ago

rkertesz commented 3 years ago

I'm wondering if you know of a library or method to use the write to flash to buffer data but to do so in a way that can allow me to do so in an addressable circular buffer?

MCUdude commented 3 years ago

Hi!

I don't know any libraries or functions that can do that. I don't have much experience with circular buffers in general, other than that the Arduino Serial interface uses a circular buffer, and that it's quite useful for certain applications.

Care to explain why you would need to use the flash memory as a circular buffer, and what the use-case is? Maybe I'm able to point you in the right direction 👍 Also, you're thinking about a circular buffer living in RAM, right?

If you utilize the Flash.h library, you'll typically have a buffer as big as a flash page size you can do whatever you want with.

rkertesz commented 3 years ago

I'm thinking of using the flash. The example is as a datalogger where each new reading is available at a different address and we use one read pointer and one write pointer. Thr device can take a reading every 5 minutes and advance the write pointer each time. We can interrogate the device every hour and then read each measurement/timestep, progressing from the start address of the read pointer up until readptr matches writeptr. If we fail to interrogate for a long long time, the write pointer rolls over and starts overwriting old readings.

So basically the use case is a datalogger.

I'll have a looks at some datalogger examples and see if they employ circular buffers in flash

Thank you!

rkertesz commented 3 years ago

realized that EEPROM has plenty more writes than flash and there are a few EEPROM ring buffers out there