Skip to main content

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 sector 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 block erase
48///
49/// # Safety
50///
51/// The `block_number` * block_size should not exceeds the size of flash.
52pub unsafe fn spiflash_erase_block(block_number: u32) -> Result<(), i32> {
53    match chip_specific::spiflash_erase_block(block_number) {
54        0 => Ok(()),
55        value => Err(value),
56    }
57}
58
59/// Low-level SPI NOR Flash write
60///
61/// # Safety
62///
63/// The `dest_addr` + `len` should not exceeds the size of flash.
64/// The `data` expected to points to word-aligned buffer with size greater or
65/// equals to `len`.
66pub unsafe fn spiflash_write(dest_addr: u32, data: *const u32, len: u32) -> Result<(), i32> {
67    match chip_specific::spiflash_write(dest_addr, data, len) {
68        0 => Ok(()),
69        value => Err(value),
70    }
71}