litz-esp 0.0.1

ESP32-family chips for Litz: ESP32-C3/C6 RISC-V cores, memory maps, boot ROM loading and on-chip peripherals.
Documentation
//! ESP32-family chips.
//!
//! Only the RISC-V parts are in scope first: ESP32-C3 / C6 / H2 share the
//! RV32 core and the same peripheral vocabulary, and they run unchanged in
//! WebAssembly. Xtensa (ESP32, S2, S3) is a separate ISA core and lands later.
//!
//! The mask ROM is not vendored here. Espressif publishes the ROM ELFs under
//! Apache-2.0 at `espressif/esp-rom-elfs`; a chip loads one at runtime from a
//! path or from an embedded blob the caller supplies, so the crate stays free
//! of binaries and the licence question stays where Espressif put it.
#![no_std]
#![forbid(unsafe_code)]

extern crate alloc;

use litz_mcu::MemoryRegion;

/// Which chip a [`Config`] describes.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Chip {
    /// RV32IMC, 160 MHz, PLIC, no atomics.
    Esp32C3,
    /// RV32IMAC, 160 MHz, PLIC.
    Esp32C6,
    /// RV32IMAC, 96 MHz, PLIC, no radio.
    Esp32H2,
}

/// External flash layout, in the order the ROM expects to find images.
#[derive(Clone, Copy, Debug)]
pub struct FlashLayout {
    pub size: u32,
    /// Offset of the second-stage bootloader.
    pub bootloader_offset: u32,
    /// Offset of the partition table.
    pub partition_table_offset: u32,
    /// Offset of the application image.
    pub app_offset: u32,
}

impl Chip {
    pub const fn memory_map(self) -> &'static [MemoryRegion] {
        // Addresses are from the ESP32-C3/C6 technical reference manuals.
        match self {
            Chip::Esp32C3 | Chip::Esp32C6 | Chip::Esp32H2 => &PLIC_AND_RV_MAP,
        }
    }

    pub const fn flash_layout(self) -> FlashLayout {
        FlashLayout {
            size: 4 * 1024 * 1024,
            bootloader_offset: 0x0,
            partition_table_offset: 0x8000,
            app_offset: 0x1_0000,
        }
    }
}

const PLIC_AND_RV_MAP: [MemoryRegion; 6] = [
    MemoryRegion::new("irom", 0x4200_0000, 0x0040_0000),
    MemoryRegion::new("drom", 0x3C00_0000, 0x0040_0000),
    MemoryRegion::new("dram", 0x3FC8_0000, 0x0004_0000),
    MemoryRegion::new("irom-dram", 0x4037_C000, 0x0000_8000),
    MemoryRegion::new("peripherals", 0x6000_0000, 0x0010_0000),
    MemoryRegion::new("rtc", 0x5000_0000, 0x0001_0000),
];