Skip to content

033 UART Interface Binding ​

033-uart-interface-binding.mc groups two related pins into the tutorial's first interface binding:

text
io [1:2] = UART0::UART.TTL(DCE)
  • [1:2] assigns the two physical pins as one group. Pin ranges are no longer new here; the new part is the expression on the right.
  • UART0 is the local name chosen for this interface on the component.
  • :: binds that local name to the library interface type UART.TTL.
  • (DCE) selects the DCE role of the interface. That role provides the named members TX and RX in the order required by the two-pin range.
  • U_MCU.UART0.TX is a nested member path: select instance U_MCU, its bound interface UART0, and finally member TX.

The circuit connects MCU TX and RX plus a separate ground pin to a three-pin debug header. UART.TTL describes the data signals; GND remains an ordinary power pin because it is the shared electrical reference rather than a UART data member.

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

Source ​

text
// Example: UART Interface Binding
// Goal: Define a small component with a UART interface and connect it to a header.
// Language focus: interface binding, interface roles, interface member access.

component MCU_UART
{
    name = "MCU with UART"
    pins = [
        // Pins 1 and 2 become UART0.TX and UART0.RX.
        io [1:2] = UART0::UART.TTL(DCE)
        psnk [3,4] = [VCC, GND]
    ]
}

module main
{
    io GND
    io V3V3

    DC.SRC PWR(3.3V, 100mA)
    MCU_UART U_MCU
    HDR.1X3 J_DEBUG

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

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

    // UART0 is the bound interface name; TX and RX are its members.
    U_MCU.UART0.TX -> J_DEBUG.1
    U_MCU.UART0.RX -> J_DEBUG.2
    GND -> J_DEBUG.3
}

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