esp_storage/
ll.rs

1//! # Low-level API
2//!
3//! ⚠️ This is a low-level API and should be used with caution. ⚠️
4//!
5//! This gives you access to the underlying low level functionality.
6//! These operate on raw pointers and all functions here are unsafe.
7//! No pre-conditions are checked by any of these functions.
8
9use crate::chip_specific;
10
11/// Low-level SPI NOR Flash read
12///
13/// # Safety
14///
15/// The `src_addr` + `len` should not exceeds the size of flash.
16/// The `data` expected to points to word-aligned pre-allocated buffer with size
17/// greater or equals to `len`.
18pub unsafe fn spiflash_read(src_addr: u32, data: *mut u32, len: u32) -> Result<(), i32> {
19    match chip_specific::spiflash_read(src_addr, data, len) {
20        0 => Ok(()),
21        value => Err(value),
22    }
23}
24
25/// Low-level SPI NOR Flash unlock
26///
27/// # Safety
28pub unsafe fn spiflash_unlock() -> Result<(), i32> {
29    match chip_specific::spiflash_unlock() {
30        0 => Ok(()),
31        value => Err(value),
32    }
33}
34
35/// Low-level SPI NOR Flash erase
36///
37/// # Safety
38///
39/// The `sector_number` * sector_size should not exceeds the size of flash.
40pub unsafe fn spiflash_erase_sector(sector_number: u32) -> Result<(), i32> {
41    match chip_specific::spiflash_erase_sector(sector_number) {
42        0 => Ok(()),
43        value => Err(value),
44    }
45}
46
47/// Low-level SPI NOR Flash write
48///
49/// # Safety
50///
51/// The `dest_addr` + `len` should not exceeds the size of flash.
52/// The `data` expected to points to word-aligned buffer with size greater or
53/// equals to `len`.
54pub unsafe fn spiflash_write(dest_addr: u32, data: *const u32, len: u32) -> Result<(), i32> {
55    match chip_specific::spiflash_write(dest_addr, data, len) {
56        0 => Ok(()),
57        value => Err(value),
58    }
59}