Skip to content

12 · Adding a new MCU to the Lab

Goal: take a microcontroller that embeddyn's Renode fork already models and make it a first-class Dev boards part in the Lab — LED instruments, push buttons, serial monitor and demo firmware included — using the LP-MSPM0C1104 LaunchPad (TI MSPM0C1104, Cortex-M0+) as the worked example. Everything shown here ships in the repository, so you can read the real files as you follow along.

You need: the Python package, arm-none-eabi-gcc for the demo firmware, and a Renode build of the embeddyn fork (see Build Renode with custom cores) for the headless check and for actually running the board. The first two steps need neither.

Step 0 — know what already exists

Before adding anything, check what the embeddyn tree already provides. A new MCU usually needs work at only one or two of these layers:

Layer Where MSPM0C1104 status
Renode peripheral models (C#) externals/renode/src/.../Peripherals/MSPM0/ done — MSPM0_IOMUX, MSPM0_UART, MSPM0_GPIO, timers, ADC, DMA, flash controller…
Renode CPU platform (.repl) externals/renode/platforms/cpus/ti/mspm0c1103.repl, mspm0c1104.repl done — memory map, NVIC wiring, all peripherals
Renode board file (.repl) externals/renode/platforms/boards/ti/lp_mspm0c1104.repl done — LED1 and button S1 wired to the pin mux
MCU emulation profile (toolchain) embeddyn/agents/mcu_emu/profiles/mspm0c1103.json done — GNU Arm + TI MSPM0 SDK flags
Lab dev-board part embeddyn/mechatronics/devboards.py this tutorial
Demo firmware examples/mechatronics/firmware/devboards/ this tutorial

If the CPU platform or the peripheral models are missing, that is a much bigger project — the full-MCU emulation workflow covers it. This tutorial assumes the silicon is already modelled and only the board and the Lab part are missing.

Which Renode?

The .repl file alone is not enough — the peripheral models are compiled into Renode itself. The system-wide upstream Renode (e.g. C:\Program Files\Renode) does not contain the MSPM0.* models and will fail with unknown-type errors, or hang. Point RENODE_BIN at the embeddyn fork build.

Step 1 — the quick path: Renode MCU (generic)

For a one-off experiment you need no code changes at all. Write a script mspm0c1104.resc:

mach create "c1104"
machine LoadPlatformDescription @platforms/boards/ti/lp_mspm0c1104.repl
sysbus LoadELF $bin
logLevel 3

and a bindings file mspm0c1104-bindings.yaml:

adapter: renode
machine: c1104
bindings:
  - signal: mcu.led
    endpoint: {object: sysbus.iomux, property: gpio_state, pin: 22, direction: output}
  - signal: operator.button
    endpoint: {object: sysbus.iomux, property: gpio, pin: 16, invert: true, direction: input}

Then drag Renode MCU (generic) onto the schematic and set script, firmware (your .elf), machine (c1104), port (auto) and bindings in the inspector.

MSPM0 pin numbering

The whole MSPM0 family is bound through the iomux peripheral, one flat pin number per GPIO:

PA0..PA31 -> pins 0..31
PB0..PB31 -> pins 32..63     (G/L series only — the C110x has GPIOA alone)

So PA22 → pin 22, PB27 → pin 59. The LaunchPad routes LED1 to PA22 and S1 to PA16 (active low); the board file in the Renode tree already wires them:

using "platforms/cpus/ti/mspm0c1104.repl"

led1: Miscellaneous.LED @ iomux 22

iomux:
    22 -> led1@0

s1: Miscellaneous.Button @ iomux 16
    invert: true
    -> iomux@16

The quick path works, but every user has to redo the wiring by hand. The rest of this tutorial makes it permanent.

Step 2 — the demo firmware

Each dev board runs a small bare-metal demo out of the box: LED 0 blinks, the UART console counts the blinks, and while the button is held the second LED lights (on one-LED boards the first stays on). The shared logic lives in examples/mechatronics/firmware/devboards/common/demo.c; each board only supplies a small hardware layer in boards/<mcu>.c implementing four functions:

void board_init(void);        /* pin mux, GPIO directions, console UART */
void led_set(int index, int on);
int  button_pressed(void);
void uart_putc(char c);

For the C1104, copy boards/mspm0g3507.c and adapt it — this is the actual boards/mspm0c1104.c that ships in the tree:

#define GPIOA 0x400A0000u
#define IOMUX 0x40428000u
#define UART0 0x40108000u
#define PINCM(n) (IOMUX + 0x4u + 4u * ((n) - 1u))
#define KEY 0x26000001u

void board_init(void)
{
    REG32(GPIOA + 0x800u) = KEY;                    /* PWREN */
    REG32(UART0 + 0x800u) = KEY;
    REG32(PINCM(23)) = (1u << 7) | 1u;              /* PA22: GPIO (LED1) */
    REG32(PINCM(17)) = (1u << 7) | (1u << 18) | (1u << 17) | 1u;   /* PA16: input, pull-up (S1) */
    REG32(PINCM(18)) = (1u << 7) | 2u;              /* PA17: UART0 TX */
    REG32(GPIOA + 0x12A0u) = 1u << 22;              /* DOUTCLR */
    REG32(GPIOA + 0x12D0u) = 1u << 22;              /* DOESET */
    REG32(UART0 + 0x1008u) = 1u << 3;               /* CLKSEL: BUSCLK */
    REG32(UART0 + 0x1110u) = 13;                    /* IBRD: 115200 from 24 MHz */
    REG32(UART0 + 0x1114u) = 1;                     /* FBRD */
    ...
}

Three things needed real adaptation — this is what you have to figure out for any new MCU:

  1. The PINCM indices are device-specific. Pinmux register n does not map to pin n. The truth is in the SDK device header, already extracted into the Renode model MSPM0_PinMux.cs — generated from the TI MSPM0 SDK by externals/renode/tools/mspm0/gen_pinmux.py. On the C110x: PA16 = PINCM17, PA17 = PINCM18, PA22 = PINCM23. The function-select value is the position in that table entry (GPIO is always function 1; UART0_TX on PA17 is function 2).
  2. The clock is different. The C110x runs at 24 MHz where the G3507 runs at 32 MHz, so the UART baud divisor changes: 24 MHz / (16 · 115200) ≈ 13.02 → IBRD = 13, FBRD = 1. The blink DELAY scales with it (110000 vs 150000 loops).
  3. Only GPIOA exists. The G3507 firmware uses GPIOB for its RGB LED; the C110x has a single port, and the demo must not touch 0x400A2000.

Add the build target

In examples/mechatronics/firmware/devboards/Makefile, add the board id to BOARDS and one row — source cpu flash-origin flash-length ram-origin ram-length defines:

lp_mspm0c1104 = mspm0c1104.c cortex-m0plus 0x00000000 16K 0x20000000 1K -DDELAY=110000

The memory sizes come straight from the .repl (flash/sram blocks) — the C1104 has 16 KB flash and 1 KB SRAM; the C1103 variant has 8 KB. Build it:

make -C examples/mechatronics/firmware/devboards bin/lp_mspm0c1104.elf

No make on Windows? The rule is one compile; this is exactly what it does:

cd examples/mechatronics/firmware/devboards
printf 'MEMORY\n{\n    FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 16K\n    RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 1K\n}\nINCLUDE common/sections.ld\n' > build/lp_mspm0c1104.ld
arm-none-eabi-gcc -mcpu=cortex-m0plus -mthumb -Os -g -Wall -Wextra -ffreestanding \
    -ffunction-sections -fdata-sections -Icommon -DDELAY=110000 -nostdlib -nostartfiles \
    -Wl,--gc-sections -T build/lp_mspm0c1104.ld -o bin/lp_mspm0c1104.elf \
    common/startup.c common/demo.c boards/mspm0c1104.c -lgcc

Sanity-check the result — the vector table must sit at the flash origin, with the initial stack pointer at the top of RAM (0x20000000 + 0x400 for 1 KB, little-endian 00 04 00 20):

arm-none-eabi-size bin/lp_mspm0c1104.elf          # text ~1.1 KB, fits 16K/1K easily
arm-none-eabi-objdump -s -j .vectors bin/lp_mspm0c1104.elf

Step 3 — the DevBoard entry

The Lab's dev boards are declared in embeddyn/mechatronics/devboards.py. The entry added for this board:

DevBoard("lp_mspm0c1104", "LP-MSPM0C1104 LaunchPad", "MSPM0C1104", "ti/lp_mspm0c1104", "mspm0c1104", "uart0",
         (Led("led1", "iomux", 22, color=RED, label="LED1 (PA22)"),),
         (Button("s1", "iomux", 16, active_low=True, label="S1 (PA16)"),),
         notes="XDS110 back-channel UART on UART0 (PA17/PA18). GPIOA is the only port; "
               "the C1103 is the same part with 8 KB flash."),

The positional arguments are:

DevBoard(id, display_name, mcu_name, renode_board_platform, machine_name, console_uart,
         leds, buttons, ...)
  • renode_board_platform is the board file under platforms/boards/ without the .repl suffix. If no board file exists for your hardware, write one that usings the CPU platform and wires the LEDs and buttons as the LaunchPad file does — that is also where external sensors and displays attach.
  • machine is the Renode machine name; make it unique per board type.
  • LEDs and buttons name the GPIO peripheral (iomux on MSPM0, gpioPortA on STM32, gpio0 on nRF52) and the flat pin number; active_low=True inverts both the instrument and the stimulus so the firmware sees what the real switch does.

That one declaration is the whole job. The machinery generates the rest:

  • the .resc script, the inline GPIO bindings (gpio_state out, gpio in) and the console UART hookup;
  • an LED instrument per LED, a momentary switch per button and a serial monitor, dropped next to the board and already wired;
  • optional extras you can declare the same way: displays=(Display(...),) adds a Video.DisplayFrame readout card, feeds=(Feed(...),) adds sliders that write sensor-model properties live, and shields=(...) loads further .repl files on top (see the X-NUCLEO-IKS01A2 entry for all three).

Step 4 — generate and verify

python -m embeddyn.mechatronics.devboards scripts   # writes examples/mechatronics/renode/devboards/<id>.resc
python -m embeddyn.mechatronics.devboards list      # every registered board
python -m embeddyn.mechatronics.devboards check lp_mspm0c1104   # boots the demo headless, expects blink output

check needs RENODE_BIN pointing at the embeddyn fork build. It loads the board exactly as the Lab would, runs two virtual seconds and passes when the console counted at least two blinks.

The regression tests in tests/mechatronics/test_devboards.py cover every registered board — run them after any change:

pytest tests/mechatronics/test_devboards.py -q

They verify that the generated scripts are in sync with the registry, the demo ELFs are built, the board files and peripherals exist in the Renode tree, and every board instantiates as a Lab part with its companions correctly wired. Nothing MSPM0-specific was needed: adding the entry makes the board part of all of them.

Finally, document the board in the table in Dev boards in the Lab.

Beyond dev boards: other reusable Lab parts

Not every component is a firmware board. The Lab's part library lives in embeddyn/mechatronics/gui/parts.py and has four kinds:

Kind What it is How to add
instance a co-simulation instance: Python plant, Renode MCU, ngspice circuit, FMU… write the model class, register it in _PLANTS or _BOARDS
source a live operator control (slider, switch) declaration only
instrument an observer (scope, meter, LED, serial monitor) declaration if existing rendering suffices; frontend work otherwise
scene a 3-D body whose pose follows signals declaration in _SCENE

For a Python plant — a motor, a sensor, a thermal mass — implement the class contract from Write a Python plant in embeddyn/mechatronics/plants.py (or comms/*.py for a bus device), add port units to PORT_UNITS, and register one tuple:

("embeddyn.mechatronics.plants:MyPlant", "my_plant", "My plant", "Mechanical", "mechanical",
 "motor", "Description shown in the part browser."),

Constructor defaults become editable parameters; inputs/outputs become the schematic pins. After restarting the Lab it appears in the part browser under its category.

For MCU boards, prefer the DevBoard path of this tutorial over hand-registering in parts.py: it already handles bindings, console, companions, script generation and headless verification.

Checklist for your own board

  1. Silicon modelled? Look for platforms/cpus/<vendor>/<mcu>.repl in the Renode fork. Missing → the full-MCU workflow, not this tutorial.
  2. Board file at platforms/boards/<vendor>/<board>.repl with LEDs/buttons wired, or write one.
  3. LED pins (+ active level), button pins (+ active level), console UART and its TX/RX pins — from the schematic or the vendor SDK board files, not guesswork.
  4. boards/<mcu>.c hardware layer: pinmux indices, peripheral clock, baud divisor, existing ports only.
  5. Makefile row with the exact flash/RAM layout from the .repl.
  6. DevBoard entry, devboards scripts, devboards check, pytest tests/mechatronics/test_devboards.py.

To debug the firmware at source level once it runs, continue with Debug emulated firmware with cortex-debug.