RTOS & Firmware Stacks

# MicroPython firmware and C-module CI

Boot compiled MicroPython firmware.elf images on board twins, drive REPL scripts over UART and inject real bus faults.

Custom MicroPython builds bundle native C modules and frozen bytecode that break silently when heap limits shrink or machine.I2C raises OSError. Testing on the unix port skips every real bus driver.

Running the cross-compiled firmware.elf on an STM32, RP2040 or ESP32-C3 board twin exercises the real C binding, REPL UART framing and attached sensor registers in CI.

## MicroPython CI checks on twins

| Layer                 | Verified behavior                        | Failure caught                           |
| --------------------- | ---------------------------------------- | ---------------------------------------- |
| Boot & frozen main.py | REPL banner and startup script execution | SyntaxError or MemoryError during boot   |
| C user modules        | Memory layout and FFI register calls     | HardFault or GC pointer corruption       |
| machine.I2C / SPI     | Real register reads from attached twins  | Unhandled OSError(ENODEV) on sensor NACK |

## Local CLI workflow

Shell - run MicroPython ELF with sensor twin

```
make -C ports/stm32 BOARD=NUCLEO_F767ZI USER_C_MODULES=../../../modules/micropython.cmake
ct run --json --board nucleo-f767zi --device bme280 ports/stm32/build-NUCLEO_F767ZI/firmware.elf
```

## Suite & fault configuration

tests/micropython.suite.yaml

```
version: 1
board: nucleo-f767zi
firmware: ports/stm32/build-NUCLEO_F767ZI/firmware.elf
tests:
  - name: repl-sensor-read-and-nack
    timeout_ms: 4000
    faults:
      - at_ms: 1200
        bus: I2C1
        kind: nack
        address: 0x76
        count: 2
    expect:
      console_contains: "SENSOR_OK"
      exit_code: 0
```

## CI pipeline integration

.github/workflows/micropython-ci.yml

```
name: MicroPython Twin CI
on: [push, pull_request]
jobs:
  mpy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: make -C ports/stm32 BOARD=NUCLEO_F767ZI
      - uses: circuittwin/action@v1
        with:
          suite: tests/micropython.suite.yaml
```

## Troubleshooting checklist

| Symptom                              | Fix                                                                                   |
| ------------------------------------ | ------------------------------------------------------------------------------------- |
| REPL prompt never appears on console | Confirm MICROPY\_HW\_UART\_REPL matches the board VCP UART (USART3 on NUCLEO-F767ZI). |
| OSError ENODEV when scanning I2C bus | Verify the twin address matches your Python driver (0x76 vs 0x77 on BME280).          |

## Frequently asked questions

| Question                                                                  | Answer                                                                                                                                                  |
| ------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Why test MicroPython on an MCU twin instead of the MicroPython unix port? | The unix port lacks real STM32/RP2040/ESP32 machine.I2C, machine.SPI and DMA peripherals and cannot catch C-module memory faults or bus error handling. |

## Related boards & component twins

[Board: nucleo-f767zi](https://circuittwin.ai/boards/nucleo-f767zi) [Board: rpi-pico](https://circuittwin.ai/boards/rpi-pico) [Board: esp32c3-devkitm](https://circuittwin.ai/boards/esp32c3-devkitm) [Twin: BME280](https://circuittwin.ai/twins/bme280) [Twin: SSD1306](https://circuittwin.ai/twins/ssd1306) [Twin: MPU-6050](https://circuittwin.ai/twins/mpu-6050) [CI integration guide](https://circuittwin.ai/docs/ci)

## More in RTOS & Firmware Stacks

[Zephyr RTOS CI without hardware benches](https://circuittwin.ai/guides/zephyr-rtos-ci-without-hardware) [FreeRTOS headless testing in CI](https://circuittwin.ai/guides/freertos-headless-testing) [ESP-IDF CI simulation for ESP32, S3 & C3](https://circuittwin.ai/guides/esp-idf-ci-simulation) [PX4 Pixhawk 6C simulation on real ARM ELF](https://circuittwin.ai/guides/px4-pixhawk-6c-simulation)

> ## Run this workflow on your own ELF
>
> Start free on CircuitTwin to run local board twins, fault matrices and CI checks with zero per-run credits.
>
> [Start now](https://app.circuittwin.ai/try) [Read the quickstart](https://circuittwin.ai/docs/quickstart) [Connect a coding agent](https://circuittwin.ai/docs/agents)
