Recent

Author Topic: RasPi (3B+) store data persistent NOT on SD-card  (Read 2045 times)

af0815

  • Hero Member
  • *****
  • Posts: 1289
RasPi (3B+) store data persistent NOT on SD-card
« on: May 16, 2019, 03:51:28 pm »
Is there a way to store some data persistent (not lost on power fail) ? But i need the data after a powerfail or reboot. The amount is 100-200 bytes only.

SD-Card: I didnt want to use the SD-card, because the data is changing often (second) and i didnt want to stress it.
USB-Stick: Same as SD-Card
SATA: To much overhead, price, power and no room for it

Have anybody experience with NVRAM or FRAM and how to access it with pascal ?

I have seen a FRAM Module from ADA-fruit working (maybe) with SPI. And an very old RasPi Project (2014) Ironman.
 
 
regards
Andreas

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: RasPi (3B+) store data persistent NOT on SD-card
« Reply #1 on: May 16, 2019, 07:53:18 pm »
I have AvrCo Pascal code for MCP7940 RTC (only 64 bytes of battery or supercap backed SRAM via I2C), and for AT45DG161 and similar (from 1 up to 32Mbit via SPI). FRAM driver exists in AvrCo so I didn't bother to write my own, but some others did so you can take a look here:
https://forum.e-lab.de/topic.php?t=3258&page=fst_unread&highlight=fram

AvrCo Pascal
is not FPC, but close enough to be more useful then some Arduino code. PM me if you need it.

RTC is easiest but needs battery, and you would have to find a model with more SRAM (like DS3234 with 256 bytes). AT45xxxx is cheaper and with bigger capacity, but access is through blocks, not bytes. FRAM is the fastest, has byte access, and doesn't need battery, but is much more expensive. If building something up to tens or hundreds of pieces - I would recommend to go for FRAM because engineering hours are high percentage of total cost and choosing more expensive component will not impact that much or can even be a time saver. But if you are building tens to hundreds thousands of pieces - you will save a lot if you avoid FRAM because hardware is then high percentage of total cost.

EDIT: Seeing now that you need to write data every second, AT45xxxx is out unless you design a battery backup with enough power to write cached data block only on application exit or before detected power loss shuts off your pi. Sooner or later power failure will happen during writing and your data will fail or become incomplete. So, with RTC or FRAM you will probably need to either use some CRC for each write (if you can tolerate bad write by checking CRC), or some kind of battery backup and power loss detection (if you can not tolerate bad write and good write must always happen).
« Last Edit: May 16, 2019, 08:57:14 pm by avra »
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

sash

  • Sr. Member
  • ****
  • Posts: 366
Re: RasPi (3B+) store data persistent NOT on SD-card
« Reply #2 on: May 17, 2019, 11:57:37 am »
Did you consider battery backup/UPS option?

This way you can flush your data to disk (sdcard/usb) in case of power outage.
Lazarus 2.0.10 FPC 3.2.0 x86_64-linux-gtk2 @ Ubuntu 20.04 XFCE

af0815

  • Hero Member
  • *****
  • Posts: 1289
Re: RasPi (3B+) store data persistent NOT on SD-card
« Reply #3 on: May 18, 2019, 01:09:58 pm »
Thx, i have now to study the infos.

Ups is not the preferred soloution. you have to maintain the batteries. Price is not the goal, it should work with raspian and fpc, without special kernels or modules.

if the capacity is enough i can work with a ringbuffer and crc. so i have the last good value. if i lost one point at shutdown, it will be ok.
« Last Edit: May 18, 2019, 01:16:54 pm by af0815 »
regards
Andreas

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: RasPi (3B+) store data persistent NOT on SD-card
« Reply #4 on: May 18, 2019, 04:09:26 pm »
EEPROMS are very practical for your application. If you choose the right size, you will not write over the same cell a million times in 20 years.

20*366*24*60*60/1000000 = 633 Seconds

If you write over the same area once every 633 seconds (or more), you can use the EEPROM for 20 years.

You need to save 200 bytes every second. You need an EEPROM size:
200*633=126600 bytes or 124 KB

128 KB is the smallest needed size.

Please consider the temperature of operation, it will affect the number of times you can write over the same cell, and adjust the size accordingly. Also, instead of 200 use a bigger number for future modification.

Add two bytes in your record as increasing counter. When you restore power, to find the last record.

af0815

  • Hero Member
  • *****
  • Posts: 1289
Re: RasPi (3B+) store data persistent NOT on SD-card
« Reply #5 on: May 18, 2019, 05:39:19 pm »
with the idea oft the eeprom, is it possible to write or read sequentiell on a normal usbdrive ? if i can use a usb-device block by block, i can do the same like a eeprom.
regards
Andreas

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: RasPi (3B+) store data persistent NOT on SD-card
« Reply #6 on: May 18, 2019, 07:29:08 pm »
The idea should work if you can guarantee not to write to any location a number of times more than its limit, and if you know the limit.

Probably with the huge capacity it should work. With basic math, if you have 1GB you'll write on the same location less than 120 times in 20 years.

It might take longer to find the location of the last record at start up.

af0815

  • Hero Member
  • *****
  • Posts: 1289
Re: RasPi (3B+) store data persistent NOT on SD-card
« Reply #7 on: May 18, 2019, 08:09:42 pm »
i know the time and so i can calculate a window for the search, if i can detemistic write to the device.
regards
Andreas

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: RasPi (3B+) store data persistent NOT on SD-card
« Reply #8 on: May 18, 2019, 10:30:25 pm »
Before you settle for a solution, I would suggest that you read about the different types of USB flash drives. And this endurance test might give you some idea.

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: RasPi (3B+) store data persistent NOT on SD-card
« Reply #9 on: May 19, 2019, 12:39:16 am »
if the capacity is enough i can work with a ringbuffer and crc. so i have the last good value. if i lost one point at shutdown, it will be ok.
I would choose FRAM then. It can even come in an easy to solder DIP package (tinier packages are much cheaper), or as a ready to use breakout board with I2C or SPI interfaces.

https://eu.mouser.com/productdetail/cypress-semiconductor/fm25l16b-g?qs=pA5MXup5wxEESa0K%2FsoVeQ%3D%3D
https://eu.mouser.com/ProductDetail/ROHM-Semiconductor/MR45V200BRAZAARL?qs=sGAEpiMZZMtsPi73Z94q0LLtWXL8TrlCe%252BuUWI%2FO1UE%3D
https://www.adafruit.com/product/1897
https://www.adafruit.com/product/1895
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

 

TinyPortal © 2005-2018