Replies: 1 comment 8 replies
-
I tried changing the //! Writes and reads flash memory.
//!
//! Uses flash address 0x9000 (default NVS)
//! See https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/partition-tables.html#built-in-partition-tables
//% FEATURES: esp-storage esp-hal/unstable esp-hal/psram esp-alloc/internal-heap-stats esp-hal/log
//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3
#![no_std]
#![no_main]
extern crate alloc;
use embedded_storage::{ReadStorage, Storage};
use esp_backtrace as _;
use esp_hal::main;
use esp_println::println;
use esp_storage::FlashStorage;
fn init_psram_heap(start: *mut u8, size: usize) {
unsafe {
esp_alloc::HEAP.add_region(esp_alloc::HeapRegion::new(
start,
size,
esp_alloc::MemoryCapability::External.into(),
));
}
}
#[main]
fn main() -> ! {
esp_println::logger::init_logger_from_env();
let peripherals = esp_hal::init(
esp_hal::Config::default()
.with_cpu_clock(esp_hal::clock::CpuClock::max())
.with_psram(esp_hal::psram::PsramConfig::default()),
);
let (start, size) = esp_hal::psram::psram_raw_parts(&peripherals.PSRAM);
init_psram_heap(start, size);
println!("Going to access PSRAM");
let mut large_vec = alloc::vec::Vec::<u32>::with_capacity(500 * 1024 / 4);
for i in 0..(500 * 1024 / 4) {
large_vec.push((i & 0xff) as u32);
}
println!("vec size = {} bytes", large_vec.len() * 4);
println!("vec address = {:p}", large_vec.as_ptr());
println!("vec[..100] = {:?}", &large_vec[..100]);
let string = alloc::string::String::from("A string allocated in PSRAM");
println!("'{}' allocated at {:p}", &string, string.as_ptr());
println!("{}", esp_alloc::HEAP.stats());
let mut bytes = [0u8; 32];
let mut flash = FlashStorage::new();
let flash_addr = 0x9000;
println!("Flash size = {}", flash.capacity());
println!();
flash.read(flash_addr, &mut bytes).unwrap();
println!("Read from {:x}: {:02x?}", flash_addr, &bytes[..32]);
bytes[0x00] = bytes[0x00].wrapping_add(1);
bytes[0x01] = bytes[0x01].wrapping_add(2);
bytes[0x02] = bytes[0x02].wrapping_add(3);
bytes[0x03] = bytes[0x03].wrapping_add(4);
bytes[0x04] = bytes[0x04].wrapping_add(1);
bytes[0x05] = bytes[0x05].wrapping_add(2);
bytes[0x06] = bytes[0x06].wrapping_add(3);
bytes[0x07] = bytes[0x07].wrapping_add(4);
flash.write(flash_addr, &bytes).unwrap();
println!("Written to {:x}: {:02x?}", flash_addr, &bytes[..32]);
let mut reread_bytes = [0u8; 32];
flash.read(flash_addr, &mut reread_bytes).unwrap();
println!("Read from {:x}: {:02x?}", flash_addr, &reread_bytes[..32]);
println!("Reset (CTRL-R in espflash) to re-read the persisted data.");
loop {}
} And it seems to work fine
|
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm using with
ESP32S3
a crate to read the partition table -esp-partition-table
. I'm also using PSRAM with that same application successfuly.Now I want to use it with
ESP32
and with a basic program it's working (basic meaning, not using PSRAM).Once I enable the feature
quad-psram
onesp-hal
it stops working showing the partitions data.From what I understand, all it does is use
esp-storage
to read the flash at the partition table location and parse the partitions. Enabling psram just on the feature flag (no change in code) breaks it.Is it a bug? a limitation of esp32 that flash can't be read when PSRAM is active? Any additional feature-flag I need to deal with to make it work?
This is the code, I minimized it as much as possible
These are the relevant lines from cargo:
Beta Was this translation helpful? Give feedback.
All reactions