Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- ESP32-H2: Fix direct-boot feature
- ESP32-C6: Support FOSC CLK calibration for ECO1+ chip revisions
- Fixed CI by pinning the log crate to 0.4.18 (#600)
- ESP32-S3: Fix calculation of PSRAM start address

### Changed

Expand Down
4 changes: 4 additions & 0 deletions esp-hal-common/src/soc/esp32/psram.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
const PSRAM_VADDR: u32 = 0x3F800000;

pub fn psram_vaddr_start() -> usize {
unsafe { PSRAM_VADDR_START as usize }
}

cfg_if::cfg_if! {
if #[cfg(feature = "psram_2m")] {
const PSRAM_SIZE: u32 = 2;
Expand Down
4 changes: 4 additions & 0 deletions esp-hal-common/src/soc/esp32s2/psram.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
const PSRAM_VADDR: u32 = 0x3f500000;

pub fn psram_vaddr_start() -> usize {
unsafe { PSRAM_VADDR_START as usize }
}

cfg_if::cfg_if! {
if #[cfg(feature = "psram_2m")] {
const PSRAM_SIZE: u32 = 2;
Expand Down
27 changes: 24 additions & 3 deletions esp-hal-common/src/soc/esp32s3/psram.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
const PSRAM_VADDR: u32 = 0x3C030000;
static mut PSRAM_VADDR: u32 = 0x3C000000;

pub fn psram_vaddr_start() -> usize {
unsafe { PSRAM_VADDR as usize }
}

cfg_if::cfg_if! {
if #[cfg(feature = "psram_2m")] {
Expand All @@ -14,8 +18,6 @@ cfg_if::cfg_if! {

pub const PSRAM_BYTES: usize = PSRAM_SIZE as usize * 1024 * 1024;

pub const PSRAM_VADDR_START: usize = PSRAM_VADDR as usize;

/// Initialize PSRAM to be used for data.
///
/// Currently only QSPI is supported.
Expand Down Expand Up @@ -65,6 +67,25 @@ pub fn init_psram(_peripheral: impl crate::peripheral::Peripheral<P = crate::per
) -> i32;
}
unsafe {
const MMU_PAGE_SIZE: u32 = 0x10000;
const ICACHE_MMU_SIZE: usize = 0x800;
const FLASH_MMU_TABLE_SIZE: usize = ICACHE_MMU_SIZE / core::mem::size_of::<u32>();
const MMU_INVALID: u32 = 1 << 14;
const DR_REG_MMU_TABLE: u32 = 0x600C5000;

// calculate the PSRAM start address to map
let mut start = PSRAM_VADDR;
let mmu_table_ptr = DR_REG_MMU_TABLE as *const u32;
for i in 0..FLASH_MMU_TABLE_SIZE {
if mmu_table_ptr.add(i).read_volatile() != MMU_INVALID {
start += MMU_PAGE_SIZE;
} else {
break;
}
}
log::debug!("PSRAM start address = {:x}", start);
PSRAM_VADDR = start;

// Configure the mode of instruction cache : cache size, cache line size.
rom_config_instruction_cache_mode(
CONFIG_ESP32S3_INSTRUCTION_CACHE_SIZE,
Expand Down
2 changes: 1 addition & 1 deletion esp32s3-hal/examples/psram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static ALLOCATOR: esp_alloc::EspHeap = esp_alloc::EspHeap::empty();
fn init_psram_heap() {
unsafe {
ALLOCATOR.init(
soc::psram::PSRAM_VADDR_START as *mut u8,
soc::psram::psram_vaddr_start() as *mut u8,
soc::psram::PSRAM_BYTES,
);
}
Expand Down