Building and Deploying MicroFMU on ESP32

Overview

This guide explains how to compile MicroPython with MicroFMU for ESP32 and deploy it to the microcontroller.

Prerequisites

  • ESP32 board

  • Installed ESP-IDF toolchain

  • MicroPython source code (micropython_dir set correctly)

  • USB serial drivers for ESP32

Steps

  1. Navigate to the ESP32 port directory

    cd "$micropython_dir/ports/esp32"
    
  2. Initialize ESP-IDF and set environment variables

    . $HOME/esp/esp-idf/export.sh
    
  3. Compile MicroPython with MicroFMU

    make submodules
    make USER_C_MODULES=$micropython_dir/MicroFMU-library/micropython.cmake
    
  4. Flash MicroPython onto ESP32

    make erase
    make deploy USER_C_MODULES=$micropython_dir/MicroFMU-library/micropython.cmake
    
  5. Run FMU Simulation on ESP32

    Connect via serial and run:

    >>> import ufmu as fmu
    >>> simulation = fmu.setup_simulation(0, 3, 0.1)
    >>> for step, time, h, _, v, _, g, e in simulation:
    ...     print(time, h)