Emulate a UART network of many MCUs¶
embeddyn.mechatronics.uartnet puts N copies of a dev board in one Renode emulation, every node running the
same firmware, their UARTs on one shared line (Renode's UARTHub: what a node sends, every other node
receives, like RS-485). It monitors the line, decodes the frames, and deploys a new build to every node in one
step. The worked example is examples/mechatronics/firmware/mspm0c1104-uartnet: 124 LP-MSPM0C1104 nodes.
The network file¶
name: line
board: lp_mspm0c1104 # any dev board: python -m embeddyn.mechatronics.devboards list
nodes: 124 # node001..node124, ids 1..124 (or a list of {name, id})
firmware: build/lp_mspm0c1104.elf # the one firmware, relative to this file
build: ./build.sh release # what deploy runs first
uart: sysbus.uart0 # the node UART on the line
baud: 115200
node_id: {address: 0x3FF8, width: 4, count: true} # per node: id | node count << 16
quantum: 0.0001 # <= one character time
line: {} # UARTHub faults: bit_flip_rate, dropped_rate, frame_error_rate
monitor: {protocol: uartnet, topic: net}
One firmware, many addresses. After loading the ELF, Renode writes each node's configuration word
(node_id.address): the id in the low byte and, with count: true, the node count in bits 16-31. On a real
product that word is programmed at production; the firmware reads it at start-up, so the same binary serves
every node.
Run, monitor, deploy¶
| Command | What it does |
|---|---|
python -m embeddyn.mechatronics.uartnet run uartnet.yaml [--seconds S] [--log frames.jsonl] |
starts the network, prints a status line per second (frames, nodes heard, bad frames, firmware versions, the master's summary), keeps Renode's monitor on a TCP port; Ctrl+C stops |
... deploy uartnet.yaml [--no-build] |
runs build, then loads the ELF into every node of the running network, writes the ids again and restarts all nodes at the same virtual instant (124 nodes: about 8 s) |
... monitor uartnet.yaml [--all] |
follows the line of the running network: status lines, or every frame decoded |
... script uartnet.yaml |
writes .uartnet/<name>.resc (and the tap) without running |
... stop uartnet.yaml |
stops it |
The example's .vscode/tasks.json makes network: deploy the default build task: edit, Ctrl+Shift+B, every
node runs the new code.
The monitor reads a tap on the hub (DataTransmitted, a small Renode Python script): every byte with its sender
and virtual time, in .uartnet/<name>.tap. protocol: uartnet splits it into the example's frames
(0x7E dst src len cmd payload CRC-8); protocol: gap splits on idle time for any other protocol.
In the Lab¶
A Renode instance with options.network: uartnet.yaml is the whole network (lab.yaml of the example):
instances:
line:
domain: firmware
options: {backend: renode, launch: true, port: auto, network: uartnet.yaml,
inline_bindings: [{signal: line.master_led, machine: node001, object: sysbus.iomux,
property: gpio_state, pin: 22, direction: output}]}
metadata:
analyzer: {topics: [net], uart: {protocol: uartnet}}
Every frame becomes an Analyzer row (UART, sender and addressee by node name, POLL / STATUS / SUMMARY decoded,
bad CRCs flagged) and can be exported as a pcap. Bindings with machine: <node> reach single nodes' pins and
registers. Run uses the newest build. Keep step_seconds long (50 ms): each step runs all nodes; frames keep
their own times.
Timing and limits¶
- Renode runs the nodes in lock-step quanta; a byte reaches the other nodes at their next synchronisation point.
Keep
quantumat or below one character time (87 us at 115200 8N1; 0.0001 is verified with 124 nodes, no bad frame). Larger quanta are faster but garble frames with many nodes;load_specwarns. - The MSPM0 UART model receives at most one character per character time (
PaceReceive, default on), as a real UART does; enable the 4-entry FIFO in firmware (DL_UART_Main_enableFIFOs). - Nodes should sleep (
__WFI()) between events: busy-wait firmware costs host CPU for every node. With the example, 124 nodes need about 1 GB of RAM, 20 s to load and run about 110 times slower than real time on a 12-core host (one poll round of 123 nodes, 0.24 s of virtual time, in about 25 s). - The hub has no collisions: two nodes talking at once interleave their bytes at the receivers. Protocols must keep one talker at a time (polling, tokens, time slots), as on RS-485.