pub(crate) fn init_psram(config: PsramConfig) {
    let mut config = config;

    utils::psram_init(&config);

    if config.size.is_auto() {
        const MAX_MEM_SIZE: usize = 4 * 1024 * 1024;

        // Reading the device-id turned out to not work as expected (some bits flipped
        // for unknown reason)
        //
        // As a workaround we just map 4m (maximum we can do) and
        // probe if we can access top of PSRAM - if not we assume it's 2m
        //
        // This currently doesn't work as expected because of https://github.com/esp-rs/esp-hal/issues/2182
        utils::s_mapping(EXTMEM_ORIGIN as u32, MAX_MEM_SIZE as u32);

        let guessed_size = unsafe {
            let ptr = EXTMEM_ORIGIN as *mut u8;
            for i in (1023..MAX_MEM_SIZE).step_by(1024) {
                ptr.add(i).write_volatile(0x7f);
            }

            let mut last_correctly_read = 0;
            for i in (1023..MAX_MEM_SIZE).step_by(1024) {
                if ptr.add(i).read_volatile() == 0x7f {
                    last_correctly_read = i;
                } else {
                    break;
                }
            }

            last_correctly_read + 1
        };

        info!("Assuming {} bytes of PSRAM", guessed_size);
        config.size = PsramSize::Size(guessed_size);
    } else {
        utils::s_mapping(EXTMEM_ORIGIN as u32, config.size.get() as u32);
    }

    unsafe {
        crate::soc::MAPPED_PSRAM.memory_range = EXTMEM_ORIGIN..EXTMEM_ORIGIN + config.size.get();
    }
}
Initializes the PSRAM memory on supported devices.

Returns the start of the mapped memory and the size
esp-hal/src/soc/esp32/psram.rs