Skip to content

223 SPI Flash ​

223-spi-flash.mc describes a basic four-wire SPI flash connection.

MCU_SPI exposes an SPI master interface, and FLASH_SPI exposes an SPI slave interface. The master drives CS, SCLK, and MOSI to the flash. The flash drives MISO back to the master. Both components share V3V3 and GND.

Parse 223-spi-flash.mc:

bash
eval "$(../mcc/scripts/mcc-slot.sh)"
MCC_SYSTEM_ROOT="$(cd .. && pwd)" "$MCC_BIN" --local parse 22-interface-recipes/223-spi-flash.mc --lib mcode --pass1 --pass2

Generate HTML for 223-spi-flash.mc:

bash
eval "$(../mcc/scripts/mcc-slot.sh)"
MCC_SYSTEM_ROOT="$(cd .. && pwd)" "$MCC_BIN" --local parse 22-interface-recipes/223-spi-flash.mc --lib mcode --viz -o 22-interface-recipes/223-spi-flash.html

Source ​

text
// Example: SPI Flash
// Goal: Connect an SPI controller to a flash memory device.
// Library focus: SPI, DC.

component MCU_SPI
{
    name = "MCU with SPI"
    pins = [
        io 1:4 = SPI0::SPI(MASTER)
        5 = VCC
        6 = GND
    ]
}

component FLASH_SPI
{
    name = "SPI Flash"
    pins = [
        io 1:4 = SPI0::SPI(SLAVE)
        5 = VCC
        6 = GND
    ]
}

module main
{
    io GND
    io V3V3

    DC.SRC PWR(3.3V, 100mA)
    MCU_SPI U_MCU
    FLASH_SPI U_FLASH

    PWR.1 -> V3V3
    PWR.2 -> GND

    V3V3 -> U_MCU.VCC
    V3V3 -> U_FLASH.VCC
    U_MCU.GND -> GND
    U_FLASH.GND -> GND

    U_MCU.SPI0._CS -> U_FLASH.SPI0._CS
    U_MCU.SPI0.SCLK -> U_FLASH.SPI0.SCLK
    U_MCU.SPI0.MOSI -> U_FLASH.SPI0.SI
    U_FLASH.SPI0.SO -> U_MCU.SPI0.MISO
}

MCode Bench is the public face of the MCode stack. Closed capabilities are served through the MCode gateway.