Coder Social home page Coder Social logo

d00616 / arduino-nvm Goto Github PK

View Code? Open in Web Editor NEW
26.0 4.0 4.0 36 KB

Direct flash memory access, round robin virtual pages and EEPROM like memory.

License: GNU Lesser General Public License v2.1

C++ 96.57% C 3.43%
arduino-library nrf51822 nrf52832 eeprom nvram

arduino-nvm's Introduction

arduino-NVM

Build Status

This library allows the usage of internal Flash memory. To enhance the limited erase cycles a VirtualPage layer is available. On top of VirtualPage, there is an NVRAM class to allow a lot of writes by using a log-based storage.

For Arduino compatibility, a subset of avr/eeprom.h functionality and a complete port of EEPROM.h is provided.

Accessing bytes via NVRAM or EEPROM is faster than an AVR controller until the internal log is full. At this point, a new page must build. This process takes up to 3400ms (nRF51) or 1300ms (nRF52) depending on your hardware and the highest written address.

To find out more about timing, please run "test_all" example.

This code is not compatible with any SoftDevice. You have to use the radio notification and VirtualPage.clean_up()/NVRAM.write_prepare(NUMBER) to ensure that writes are only used in a time without radio activation.

Flash.h

This class is the hardware abstraction to the Flash controller. Please look into Flash.h for a more detailed description.

Please read the documentation of your microcontroller to find out limitations about writing into flash. You can use the FLASH_... defines in your code to take care about quirks.

VirtualPage.h

This class provides manages Flash pages. This helps you to reach more erase cycles and handle page faults. The underlying Flash page needs to hold some metadata so a VirtualPage is some bytes smaller than 4k. The size can differ between different hardware.

If you need to allocate VirtualPages in performance critical situations, call VirtualPage.clean_up(), when you have a time slot of more than 100ms.

For VirtualPages the last 16k(nRF51) or 32k(nRF52) are used. This allows the same number of erase cycles on both platforms.

NVRAM.h

This class provides a 3072 bytes large memory. You can access this memory in a random order without needing to take care of the underlying flash architecture. This class is stateless, this means there is nothing cached in RAM. With every access, the data structure is parsed. This saves RAM and avoids conflicts when you have more than one instance of NVRAM class in your code.

To reach a maximum of write cycles and performance, place all your data at the beginning of the memory. This allows a maximum of write cycles.

When you only use the first 8 Bytes of the NVRAM, you have 5,100,000 write cycles per byte. If you use all 3072 bytes, you have only 3,300 write cycles per byte.

For your own calculation of write cycles, you can calculate the sum of available writes with: (VirtualPage.length()-4-HIGHEST_ADDRESS/4)*40,000

Reading or writing the NVRAM is fast until the internal log is full. On nRF51 you can calculate with 1.2ms and on nRF52 with 0,5ms. If the log is full a new VirtualPage is allocated and written. This procedure can take a time of 3400ms (nRF51) or 1300ms (nRF52).

If you use this code in performance critical situations. Use NVRAM.write_prepare(NUMBER) before to guarantee a fast write for the given number of bytes.

EEPROM.h and avr_eeprom.h

Both libraries are for Arduino compatibility. Instead of avr/eeprom.h, you have to include avr_eeprom.h. This file maps a limited set of functions to NVRAM.

The EEPROM.h is fully compatible with the AVR version without committing changes.

If you use one of both files, please keep in mind that writing a single byte is fast until the log becomes full. In that case, a single write operation can take up to 3400ms (nRF51) or 1300ms (nRF52).

arduino-nvm's People

Contributors

d00616 avatar per1234 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

Watchers

 avatar  avatar  avatar  avatar

arduino-nvm's Issues

Read/write simple example

Hello,

I just want to do the following:

Before I power off device save to a variable let's say value 0x69

Once the device wakes up I want to read the exact same address and read the content to modify it.

How can I do it?

I don't understand any of the examples.. what are the pages?

Any help would be appreciated.

Toni

Data write not persisting

Hi I am having trouble getting data I write to stay as each time I try to read it back after restarting its not there anymore.

  char* testword_in;
  char* testword = "TestWord";

  //  NVRAM.write_block((uint8_t *)&testword, 0, sizeof(testword));
  NVRAM.read_block((uint8_t *)&testword_in, 0, sizeof(testword));
  print_compare((uint32_t)testword, (uint32_t)testword_in);

This is what I am using to test. I will uncomment the write line and run the code. It will return "OK" but then I comment out the write line and test it again and it fails and returns "ERROR".

II am testing this on a NRF51822. Is there something I am doing wrong here?

Writing data to Flash using Pstorage or fstorage module of nordic

Hello Everyone,

Correct me if I am wrong. According to this link: http://infocenter.nordicsemi.com/index.jsp?topic=/com.nordic.infocenter.s130.sds/dita/softdevices/s130/sd_resource_reqs/hw_block_interrupt_vector.html&cp=3_7_2_0_6_0
if softdevice is enabled, the flash can be written only through SoftDevice API sd_flash_write commands.
https://github.com/d00616/arduino-NVM : This uses writing to flash using registers.
Is it possible to use pstorage or fstoarge implementation in arduino?

Tests bricked my Nano 33 BLE

I couldn't get this to work in another project (like, yes, it does actually complain about unknown/incompatible architecture but you'd guess that's just because of the different defines) and so I decided to try the tests.
Expectedly everything died.

Now I don't really know how much this project is still cared for (it's funny to think the last time the main branch was touched, this board wasn't even a thing), but if not a code fix or adding official support, I believe at least a warning would be due.

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.