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.UART0is the local name chosen for this interface on the component.::binds that local name to the library interface typeUART.TTL.(DCE)selects the DCE role of the interface. That role provides the named membersTXandRXin the order required by the two-pin range.U_MCU.UART0.TXis a nested member path: select instanceU_MCU, its bound interfaceUART0, and finally memberTX.
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.htmlSource
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
}