Skip to content

Getting Started#

This guide walks you through setting up your first micro-LF project.

Prerequisites#

The code generator requires:

Platform-specific tools:

Platform Additional Requirements
Native cmake
Zephyr Python 3, west, Zephyr SDK
RIOT make 4.0+, ARM cross-compiler
Pico CMake, ARM cross-compiler, picotool
FreeRTOS CMake, ARM cross-compiler
ESP-IDF Python 3, CMake, ESP-IDF toolchain

Quick Start#

1. Clone micro-LF#

git clone https://github.com/lf-lang/reactor-uc.git --recurse-submodules
export REACTOR_UC_PATH=$(pwd)/reactor-uc

2. Clone a template repository#

Choose a template for your target platform (except "Native", which does not need a template repo):

git clone https://github.com/lf-lang/lf-zephyr-uc-template.git my-project
cd my-project
python3 -m venv venv && source venv/bin/activate
pip install west
west update
pip install -r deps/zephyr/scripts/requirements.txt
west zephyr-export
git clone https://github.com/lf-lang/lf-riot-uc-template.git my-project
cd my-project
git submodule update --init --recursive
git clone https://github.com/lf-lang/lf-pico-uc-template.git my-project
cd my-project
git submodule update --init --recursive
git clone https://github.com/lf-lang/lf-esp-idf-uc-template.git my-project
cd my-project
git submodule update --init --recursive
cd esp-idf && ./install.sh esp32 && source ./export.sh && cd ..

3. Build and run#

ulfc src/MyProgram.lf
bin/MyProgram
west build -t run  # Native simulation
# Or for hardware:
west build -b <board> -p always
west flash
make BOARD=native all term  # Native simulation
# Or for hardware:
make BOARD=<board> flash
cmake -Bbuild
cmake --build build
picotool load -x build/Blink.elf
cmake -Bbuild -DESP_IDF_BOARD=esp32 \
      -DCMAKE_TOOLCHAIN_FILE=$IDF_PATH/tools/cmake/toolchain-esp32.cmake \
      -GNinja
cmake --build build
cd build && ninja flash

Your First Reactor#

Each template includes example applications. Here's a simple Blinky reactor:

target uC

main reactor {
  timer t(0, 500 ms)
  state led_on: bool = false

  reaction(startup) {=
    // Initialize LED GPIO
  =}

  reaction(t) {=
    self->led_on = !self->led_on;
    // Toggle LED based on self->led_on
  =}
}

This reactor:

  1. Declares a timer t that fires immediately (0) and repeats every 500 ms
  2. Maintains state led_on to track the LED status
  3. Has a reaction to startup for initialization
  4. Has a reaction to timer t that toggles the LED

To build a different application, set the LF_MAIN variable:

west build -p always -- -DLF_MAIN=MyApp
make LF_MAIN=MyApp all
cmake -Bbuild -DLF_MAIN=MyApp
cmake --build build

Next Steps#

  • Platforms


    Detailed setup instructions for each supported platform.

    Platforms

  • Philosophy


    Understand the reactor model, logical time, and deterministic concurrency.

    Philosophy

  • Documentation


    API reference, annotations, and compile flags.

    Documentation