#persistent #ram #buffer #region #memory #file #stays

no-std persistent-buff

A buffer that stays persistent in ram between boots

9 releases

0.2.6 Jan 27, 2023
0.2.5 Nov 16, 2022
0.2.4 Oct 31, 2022
0.1.1 Oct 27, 2022

#324 in Embedded development

Download history 6/week @ 2024-03-11 6/week @ 2024-03-18 12/week @ 2024-04-01 8/week @ 2024-05-13

54 downloads per month

MIT/Apache

12KB
111 lines

persistent-buff

crates.io documentation

A buffer that persists between boot. Inspired by panic-persist

A region in RAM is reseved for this buffer. Your linker script should make sure the start and end of the buffer are outside of other sections

Usage

Linker script

You need to create a new reserved section for the buffer and make sure it's outside of other sections to avoid zero initializations.

Example

memory.x file before modification:

MEMORY
{
  /* NOTE 1 K = 1 KiBi = 1024 bytes */
  FLASH : ORIGIN = 0x00000000, LENGTH = 1024K
  RAM : ORIGIN = 0x20000000, LENGTH = 128K
}

memory.x file after modification to hold a 1K region:

MEMORY
{
  /* NOTE 1 K = 1 KiBi = 1024 bytes */
  FLASH : ORIGIN = 0x00000000, LENGTH = 1024K
  RAM : ORIGIN = 0x20000000, LENGTH = 128K - 1K
  PERSISTENT_BUFF: ORIGIN = ORIGIN(RAM) + LENGTH(RAM), LENGTH = 1K
}
_persistent_buff_start = ORIGIN(PERSISTENT_BUFF);
_persistent_buff_end   = ORIGIN(PERSISTENT_BUFF) + LENGTH(PERSISTENT_BUFF);

Program

#![no_std]

#[entry]
fn main() -> ! {
   let mut pbuff = persistent_buff::PersistentBuff::take_managed().unwrap();

   // Trivial way to initialize is to fill it with 0
   let buff = pbuff.validate(|b| b.fill(0));

   buff[0] = (buff[0] % 255) + 1;
   info!("Value is now {}", buff[0]);
}

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

No runtime deps