Skip to content

Commit e6e7a41

Browse files
committed
Guard against an MMU table with no trailing empty entries
Previously the call to cache_dbus_mmu_set would have likely failed instead. This is more explicit.
1 parent bec390c commit e6e7a41

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

esp-hal/src/soc/esp32s3/mmu.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ const DBUS_VADDR_BASE: u32 = 0x3C000000;
77
const DR_REG_MMU_TABLE: u32 = 0x600C5000;
88
const ENTRY_INVALID: u32 = 1 << 14;
99
const ICACHE_MMU_SIZE: usize = 0x800;
10-
const TABLE_SIZE: usize = ICACHE_MMU_SIZE / core::mem::size_of::<u32>();
1110

1211
pub(super) const ENTRY_ACCESS_SPIRAM: u32 = 1 << 15;
1312
pub(super) const PAGE_SIZE: usize = 0x10000;
13+
pub(super) const TABLE_SIZE: usize = ICACHE_MMU_SIZE / core::mem::size_of::<u32>();
1414

1515
extern "C" {
1616
/// Set DCache mmu mapping.

esp-hal/src/soc/esp32s3/psram.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ pub(crate) fn init_psram(config: PsramConfig) {
151151
// bigger than a flash page - i.e. we will see an unmapped memory slot
152152
// start from the end and find the last mapped flash page
153153
let psram_start_index = mmu::last_mapped_index().map(|e| e + 1).unwrap_or(0);
154+
if psram_start_index >= mmu::TABLE_SIZE {
155+
panic!("PSRAM cannot be mapped as MMU table has no empty trailing entries");
156+
}
154157
let start = mmu::index_to_data_address(psram_start_index);
155158
debug!("PSRAM start address = {:x}", start);
156159

0 commit comments

Comments
 (0)