Skip to content

035 SPI Flash Component ​

035-spi-flash-component.mc binds four pins to SPI(Master) and SPI(Slave). CS, SCLK, and MOSI are written from the MCU toward the flash; MISO is written from the flash toward the MCU.

The syntax is the same interface-binding pattern from UART and I2C. The new lesson is mostly interface vocabulary: SPI has four named members instead of two or three, and direction-sensitive signal names make the connections easier to review.

bash
eval "$(../mcc/scripts/mcc-slot.sh)"
MCC_SYSTEM_ROOT="$(cd .. && pwd)" "$MCC_BIN" --local parse 03-define-components-and-interfaces/035-spi-flash-component.mc --lib mcode --pass1 --pass2
MCC_SYSTEM_ROOT="$(cd .. && pwd)" "$MCC_BIN" --local parse 03-define-components-and-interfaces/035-spi-flash-component.mc --lib mcode --viz -o 03-define-components-and-interfaces/035-spi-flash-component.html

Source ​

text
// Example: SPI Flash Component
// Goal: Define master and slave components with SPI interfaces.
// Language focus: four-member interface binding and directional signal naming.

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

component FLASH_SPI
{
    name = "SPI Flash"
    pins = [
        io [1:4] = SPI0::SPI(SLAVE)
        psnk [5,6] = [VCC, 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

    // Each interface member is connected to the matching peer member.
    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.