esp-rs / esp-hal

no_std Hardware Abstraction Layers for ESP32 microcontrollers
https://docs.esp-rs.org/esp-hal/
Apache License 2.0
623 stars 167 forks source link

ESP32 PSRAM behaves erratically if flashed using 80Mhz flash mode #1566

Open daagaak opened 1 month ago

daagaak commented 1 month ago

I've been experiencing some erratic behaviour in my ESP32 trying to enable PSRAM on my WROOM-E module (confirmed to have an 8MB PSRAM module).

Attempting to synthesize this down to a broken test case, I generated a new esp-template project, and replaced the heap section with:

fn init_heap(p: PSRAM) {
    esp_hal::psram::init_psram(p);
    unsafe {
        ALLOCATOR.init(
            esp_hal::psram::psram_vaddr_start() as *mut u8,
            esp_hal::psram::PSRAM_BYTES,
        );
    }
}

And changed the init_heap call to be:

    init_heap(peripherals.PSRAM);

This actually works as expected when you espflash with the default settings. However, if you bump up the flash speed to 80mhz with -f 80mhz then I've seen it either:

I think this is because the esp32 HAL PSRAM code assumes that you're running in 40mhz Flash/40mhz PSRAM mode:

 345⋮    │        let mode = PsramCacheSpeed::PsramCacheF40mS40m; // How to make this configurable
MabezDev commented 1 month ago

I think this is because the esp32 HAL PSRAM code assumes that you're running in 40mhz Flash/40mhz PSRAM mode:

Could you try changing this locally in esp-hal and seeing if with the correct mode it works?

daagaak commented 1 month ago

Yes is does. I've been running with it set (unconditionally) to PsramCacheF80S80 since yesterday and it seems to work reliably.

bjoernQ commented 1 month ago

I think the comment // How to make this configurable is the key thing - we could use (another) cargo-feature for it but ideally, we should have #1111