Skip to main content

OpenCPLC ⚒️ Forge

Forge is a console app that makes working with OpenCPLC easier. Its job is to set up your environment so you can focus on building apps instead of fighting with configs and compilation. Available as a Python pip package or standalone opencplc.exe from 🚀Releases (in that case add its location to system PATH manually).

pip install opencplc

Pick a folder (your workspace), open CMD and type:

opencplc -n <project_name> -b <board>
opencplc -n myapp -b uno

This creates projects/<project_name> (nested folders when the name holds /). Inside it Forge creates main.c and main.h, all a project needs. Don't delete them or move them to subfolders.

When you have more projects, you can switch between them freely:

opencplc <project_name>
opencplc myapp

You can also pick projects by number from the list:

opencplc -l  # show project list
opencplc 3   # load project #3 from list

Every project owns its makefile and flash.ld, and makefile in the workspace root points at the active one. Loading a project regenerates these files, which turn all sources (project and framework .c, .h, .s) into .bin and .hex files ready to flash.

Changing PRO_x values in main.h or project structure (adding, moving, deleting or renaming files) needs a reload. make does it by itself: when main.h or any source is newer than makefile, it runs Forge first and then builds. Editing function bodies needs no reload, make handles that on its own. You can also reload by hand, without the project name when it's active or when you're inside its folder:

opencplc <project_name>
opencplc -r

Flags such as -m and -o configure a project only when it's created. Later configuration lives in main.h: edit it and reload.

-b and -c also build an existing project for other hardware, with its memory and clock, while main.h stays as it is:

opencplc test/flash -c STM32WB55

make keeps that choice until you load the project without them. Tests and demos for any board leave PRO_BOARD, PRO_CHIP and memory out of main.h, so every load names the hardware.

📂 Local project

A project can live outside the workspace, in a repository of its own. A path names it, ./app or D:/repos/app, while a plain name stays a project of the workspace:

cd C:/workspace
opencplc D:/repos/app
cd D:/repos/app
make

The first load runs in the workspace, since nothing ties the project to it before then. From then on its makefile names the workspace, so make and opencplc -r work in its folder. It builds with the framework of the workspace into its own folder under build/local/ and never becomes the active project. Forge writes makefile, flash.ld and .vscode/ into its folder, overwriting them as it does in the workspace. They hold paths of this computer, so the repository of the project should ignore them. opencplc -n D:/repos/app creates a new local project.

📄 Your files

main.c is yours and Forge never overwrites it. A PLC board project starts from this skeleton:

#include <opencplc.h>

static void loop(void)
{
  while(1) {
    RGB_Set(&RGB, RGB_Green);
    delay(1000);
    RGB_Rst(&RGB);
    delay(1000);
  }
}

stack(stack_plc, 256);
stack(stack_dbg, 256);
stack(stack_loop, 1024);

int main(void)
{
  thread(PLC_Main, stack_plc); // PLC thread
  thread(DBG_Loop, stack_dbg); // logs and console
  thread(loop, stack_loop); // your application
  vrts_init(); // start thread switching
  while(1);
}

Your application runs as a VRTS thread next to PLC and debugger threads (logs and console). Add your own modules as more files in the project folder and its subfolders.

main.h holds configuration Forge reads on every load. PRO_* definitions describe board, chip, PLC layer, framework version and memory sizes, while LOG_LEVEL and SYS_CLOCK_FREQ are yours to change. Extra framework drivers go there too: #define PRO_DRIVERS "shtc3, hd44780".

Here (roughly) ends Forge's job, and further work goes like any embedded project, with ✨Make.

✨ Make

With makefile generated by ⚒️Forge, open a console in your workspace to build the program and flash the PLC:

make build  # build C project to binary
make flash  # upload binary to PLC memory
# or
make run    # run = build + flash

make in workspace root works on the active project. Any project can be built directly, independently of the active one: make -C projects/myapp. Full list of targets:

  • make build or just make: Builds C project to .bin, .hex, .elf files
  • make flash: Uploads program to PLC (microcontroller) memory
  • make run: Does make build, then make flash
  • make test: Builds every .tests/*.c into a program for this computer and runs it, see Tests; make test T=name runs one
  • make lint: Checks the build with Forge rules, cppcheck and gcc analyzer, see Lint
  • make clean or make clr: Removes built files of the project
  • make clean_all or make clr_all: Removes built files of all projects
  • make dist: Packs the release into the project folder: .hex for programmers and, under the bootloader, .bin for updates; make dist TAG=1.2.0 names them <name>-1.2.0.hex and .bin, and CIPHER= encrypts the .bin with a cipher key
  • make update: Sends the update image of the build over the console (under the bootloader, with CMD_BOOT ON); FILE= sends another image, PORT= picks the port
  • make erase: Completely wipes microcontroller memory (erase full chip; on STM32WB the radio stack stays)
  • make stack: Flashes radio stack of the second core (STM32WB); make stack FUS=1 also provisions a factory-fresh board, once and irreversibly

Built files land in build/projects/<project_name>/: .elf, .hex, .bin and .map next to opencplc/ with framework objects and project/ with yours. Programmers flash -dist.hex, and under the bootloader -dist.bin beside it carries updates. Every project compiles the framework on its own, so switching projects never links objects built with another configuration. After linking Forge reports memory use, including stack of each thread against the limit its margin allows:

FLASH 70.7kB / 72kB (98%)
RAM 34.3kB / 36kB (95%)
STACK loop 556B / 2048B (28%, max 75%)

🥾 Bootloader

A project whose main.h includes boot.h runs behind Core's bootloader, which Forge builds with it, and takes updates without a programmer; -B sets this up for new projects. opencplc --sign acme 3 adds product keys to BOOT_KEYS in boot.h, and from then on the bootloader starts only images signed with them. opencplc --cipher acme-enc makes a cipher key, and make dist CIPHER=acme-enc encrypts the update file with it, so nobody reads it on its way to devices. --lock closes the board to programmers for production, with or without bootloader. Both and their security: 🥾 Bootloader and 🔒 lock.

⚙️ Config

With the first project ⚒️Forge creates config file opencplc.json. It contains:

  • version: Default OpenCPLC framework version for new projects. Value latest means newest stable version.
  • stlink: Programmer bound to a project, so make flash hits the right board when several ST-Links are connected. Set it with opencplc myapp -s <serial>, clear it with opencplc myapp -s. Read the serial from OpenOCD log of make flash with one programmer connected.
  • ignore: Projects left off -l and its numbers, as .gitignore patterns, e.g. ["demo/"] hides all demos. Projects named directly still load. Add this key by hand when needed.
  • available-versions: List of all available framework versions. Set automatically, used offline.

Workspace layout is fixed: projects/ with your projects, opencplc/ with framework versions and build/ with built files. Copy project folders by hand, and Forge finds them on its next run.

🤔 How works?

Who does what: Forge prepares the environment, Make builds and flashes, you write code.

flowchart LR
  CORE[repo Core] -->|clone| FW["opencplc/0.4.3"]
  FORGE[Forge] --> GEN["projects/myapp/makefile, flash.ld"]
  FW --> GEN
  YOU[your code] --> PRO["projects/myapp/main.c"]
  GEN --> MAKE[make]
  PRO --> MAKE
  MAKE --> BIN["build/projects/myapp/myapp.hex"]

On Windows ⚒️Forge brings its own Make, GNU Arm Embedded Toolchain, OpenOCD and MinGW into %LOCALAPPDATA%\OpenCPLC, no admin rights needed, and Git through winget. After the first run open a new console, so make is on PATH. On Linux tools come from your distribution.

Then, when needed, it clones OpenCPLC framework from its repository into opencplc/<version>. New projects take their version from opencplc.json, or from -f --framework:

opencplc <project_name> --new -f 0.4.3
opencplc <project_name> --new -f develop

Alone the flag only downloads, so you can read a version before any project points at it:

opencplc -f develop

📌 Project versioning

Each project keeps in main.h the framework version it was created with (PRO_FRAMEWORK). That version builds it and gets cloned when missing, so old projects compile even after framework updates. If cloning fails, Forge warns and builds with the workspace default.

To try another version without touching main.h, pass -f when loading: the project builds with that version until a load without -f, and Forge says so.

Projects inside a framework version, such as its compile tests, load by path: opencplc opencplc/develop/.tests/g081. They have no PRO_FRAMEWORK and build with the framework they lie in, into build/opencplc/develop/.tests/g081/. opencplc opencplc/develop loads the framework itself, and make test runs its tests.

🧩 Boards

Boards come from the framework: each brd/<board>/ folder with an .ini manifest is one. Its manifest gives new projects their defaults: whether the board needs the PLC layer, chip, initial memory and clock, and drivers:

name = Uno
chip = STM32G0C1
plc = true
flash_kB = 492
ram_kB = 144
clock_Hz = 59904000
reserve_kB = 20
drivers = max31865

reserve_kB is optional: flash the board keeps for itself, taken off the top like the third value of -m, so projects start with what is left.

name is how the board reads in main.h and messages, PRO_BOARD_Uno, while its folder name stays in paths. The two compare without case or underscores, so CardG0 and card_g0 are one board, and None means no board.

Adding boards means adding folders to the framework, with no change in Forge. These are defaults, not rules: -c swaps chips (memory follows the chip, clock stays with the board), and --plc adds the PLC layer to boards without it. Only plc = true binds: such boards do not build without their layer.

Without a board main.h holds PRO_BOARD_None, and PRO_PLC decides the rest: -c <chip> alone is bare metal (HAL and libraries only), -c <chip> -P adds the PLC layer on your own hardware, where peripheral mapping and PLC_Main are yours to write.

Device drivers live in drv/, outside the PLC layer, so any project can use them. Folders under drv/ group them by kind: temp/ for thermometers, acc/ for accelerometers, disp/ for displays. A driver goes by its file name, wherever it sits. Boards take the ones their manifests name, and projects add more with --drv at creation or in main.h: #define PRO_DRIVERS "shtc3, hd44780". Only named drivers reach the build.

Above all, Forge writes these files:

  • projects/<name>/flash.ld: defines RAM and FLASH memory layout (overwrites, STM32 only)
  • projects/<name>/makefile: contains build, clean and flash rules (overwrites)
  • makefile: points at the active project (overwrites)
  • c_cpp_properties.json: sets header paths and IntelliSense config in VS Code (overwrites)
  • launch.json: configures debugging in VSCode (overwrites)
  • tasks.json: describes tasks like compile or flash (overwrites)
  • settings.json: sets local editor preferences (creates once, not overwritten)
  • extensions.json: suggests useful VSCode extensions (creates once, not overwritten)

More helpers come through 🚩flags.

🗂️ Workspace structure

workspace/
├─ opencplc.json   # workspace config
├─ makefile        # active project (generated by Forge)
├─ .vscode/        # VSCode config (generated by Forge)
├─ opencplc/       # framework (downloaded automatically)
│  ├─ 0.4.3/
│  └─ develop/
├─ projects/       # user projects
│  ├─ myapp/
│  │  ├─ main.c
│  │  ├─ main.h
│  │  ├─ .tests/   # tests on the computer, `make test`
│  │  ├─ makefile  # generated by Forge
│  │  └─ flash.ld  # generated by Forge, STM32 only
│  ├─ firm/app/    # projects can be nested
│  └─ demo/        # projects from the Demo repository, `opencplc -e`
└─ build/          # compiled binary files
   ├─ projects/myapp/
   └─ local/       # local projects, a folder each

If IntelliSense stops working, use F1 → C/C++: Reset IntelliSense Database.

🖥️ Host

Forge supports Host platform for developing and testing code on a PC (Windows/Linux) without embedded hardware:

opencplc -n myapp -c host # desktop project

Such a project compiles with native GCC (MinGW on Windows) instead of ARM toolchain, and make run starts the program. Useful for:

  • Testing algorithms and logic without hardware
  • Developing protocol parsers and data processing
  • Unit testing framework components
  • Quick prototyping before deploying to PLC

Host platform provides stubs for hardware modules (GPIO, timers, etc.), so code stays compatible with STM32 targets.

🧪 Tests

Every .c file directly in .tests/ of a project is a test program, which make test builds and runs on this computer, in STM32 projects too. Tests include the modules they check, so they run firmware code itself. One workflow file runs the same on GitHub on every push. Writing, running and CI: 🧪 Tests.

🔍 Lint

make lint checks a chip build: Forge rules on VRTS, thread stacks, values and headers, then cppcheck and gcc -fanalyzer. Findings print like compiler warnings and cite norms behind their rules, such as CWE, CERT C or MISRA C. Projects turn on extra rules in their lint.yaml, such as no-heap, and keep exceptions there with reasons. Rules, norms and exceptions: 🔍 Lint.

🚩 Flags

Beyond flags above, a few more are worth knowing. Full list:

Basic

  • name: Project name, the default first argument. It also sets project path projects/name, and output files (.bin, .hex, .elf) follow it. A number from -l works too. A path, ./app or D:/repos/app, loads a local project.
  • -n --new: Creates a new project with that name.
  • -e --demo: Downloads Demo repository into projects/demo. Load a demo like any project: opencplc demo/blinky.
  • -r --reload: Regenerates project files. Without name it takes the active project, or the one whose folder you're in.
  • -d --delete: Deletes project name.
  • -g --get: Downloads a project from Git (GitHub, GitLab, ...) or a remote ZIP as a new project. A second argument after the link picks a reference (branch, tag). Without name it reads @name from main.h.

Hardware config

  • -b --board: Board from the framework (uno). It sets chip, memory, clock and PLC layer of new projects; -c and --plc override that. On an existing project it picks another board until a load without it.
  • -c --chip: Microcontroller or platform: STM32G081, STM32G0C1, STM32WB55, HOST (compile for PC). Without -b --board a project has no PLC layer, only HAL and standard framework libraries, as on Nucleo boards or custom hardware. On an existing project it picks another chip until a load without it.
  • -P --plc: Adds PLC layer to projects without a board, on your own hardware.
  • -D --drv: Framework drivers of a new project, comma separated (shtc3, hd44780). Later ones go into PRO_DRIVERS in main.h.
  • -B --boot: Puts new projects behind Core's bootloader: boot.h beside main.h and its #include, see Bootloader.
  • -m --memory: Memory in kB: FLASH RAM [RESERVED]. RESERVED is memory for config and EEPROM, taken off FLASH in linker file flash.ld (STM32 only).

Build config

  • -f --framework: Framework version: latest, develop, 0.4.3. For new projects it becomes PRO_FRAMEWORK, existing ones build with that version until a load without it, and alone it only clones the version into opencplc/.
  • -o --opt-level: Compiler optimization level: O0, Og (default), O1, O2, O3, Os. Levels O2 and O3 show a warning for STM32 (timing, debugging).
  • -s --stlink: Binds ST-Link serial to the project, -s alone clears it.

Info

  • -l --list: Lists existing projects.
  • -i --info: Basic info of the given or active project, project and framework versions included.
  • -F --framework-versions: Lists all available OpenCPLC framework versions.
  • -v --version: Shows ⚒️Forge version and repository link.

Tools

  • -a --assets: Downloads helper materials (chip documents and errata, board pinouts, style guides of Core). Optionally takes a destination folder.
  • -u --update: Replaces Forge executable with the given version (default: latest), while pip installs update through pip.
  • --program: Sends a .hex to the board through the programmer. Alone it takes what make dist left in the active project, the newest of several after confirmation.
  • --sign: Makes or takes product key NAME with spares, COUNT keys in all (default 1), and adds their public parts to BOOT_KEYS in boot.h of the active project, with an optional password, see Bootloader.
  • --cipher: Makes cipher key NAME of a product, or shows its fingerprint and, once confirmed, the key; with FILE encrypts that update image, make dist CIPHER= uses it, see Bootloader.
  • --upload: Sends update image FILE over the console, optionally to PORT; make update uses it.
  • --lock: Locks the board for production: RDP1 by default, 2 for good, 0 unlocks and erases flash, see Lock.
  • -p --pack: Packs the image for flash: under the bootloader with it in front and CRC and signature behind, with update binary beside; make uses it after linking.
  • -z --size: Reports FLASH and RAM use of an .elf, and, given CPU, Core and project, stack of each thread; make uses it after linking.
  • --test: Runs test programs, each in a clean folder of its own with one minute to finish; make test uses it.
  • --lint: Checks the project's build with Forge rules, cppcheck and gcc analyzer; make lint uses it.
  • -y --yes: Auto-confirms all prompts (non-interactive mode).

Hash utilities

  • -hl --hash-list: Generates an enum with DJB2 hashes from a tag list.
  • -ht --hash-title: Enum type name for the hash generator.
  • -hd --hash-define: Uses #define instead of enum for hash output.

🗑️ Delete and 💾 copy projects directly in your file manager. Each project keeps everything it needs in main.h, and Forge finds it on startup.

📟 Console

⚒️Forge and ✨Make are console programs. Essential for working with OpenCPLC.

Many apps give you a system console: Command Prompt, PowerShell, Git Bash, even the terminal of VSCode. Forge finds its workspace from any folder inside, so a project folder works as well.

When something goes wrong:

  • Forge lands in a wrong workspace: a stray opencplc.json sits between your project and the real root, remove it.
  • make not found right after the first run: the console still has old PATH, open a new one.
  • A tool misbehaves: remove %LOCALAPPDATA%\OpenCPLC and run Forge again, it reinstalls its packages.
  • make stops at opencplc -r with an error about version or board: main.h points at something this framework lacks, fix that entry and run make again.
  • A project is missing from -l: its folder has no main.h.

📋 Usage examples

# Creating new project
opencplc -n myapp -b uno                    # project for OpenCPLC Uno board
opencplc -n myapp -b uno -m 128 36          # project for Uno with 128kB/36kB memory
opencplc -n myapp -c STM32G081 --plc        # own hardware with PLC layer (no peripheral mapping)
opencplc -n myapp -c STM32G081              # bare-metal project for STM32G081 (e.g. Nucleo)
opencplc -n myapp -c STM32G081 --drv shtc3  # bare metal with the shtc3 driver
opencplc -n myapp -c host                   # desktop project (Windows/Linux)

# Managing projects
opencplc myapp              # load project 'myapp'
opencplc 3                  # load project #3 from list
opencplc -r                 # reload active project
opencplc -l                 # list all projects
opencplc -i                 # info about active project
opencplc myapp -s 066AFF49  # bind ST-Link to 'myapp'

# Demo projects
opencplc -e           # download Demo to projects/demo
opencplc demo/blinky  # load project 'blinky'

# Downloading projects
opencplc -g https://github.com/user/repo
opencplc -g https://github.com/user/repo v1.0.0

# Updates
opencplc -u  # update Forge to latest version
opencplc -F  # show available Core versions

Metadata

Release files for opencplc 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for opencplc 0.6.0
File Size Uploaded Provenance Actions
opencplc-0.6.0.tar.gz 222.8 kB With provenance Details for opencplc-0.6.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for opencplc 0.6.0
File Interpreter ABI Platform Actions
opencplc-0.6.0-py3-none-any.whl Python 3 none any Details for opencplc-0.6.0-py3-none-any.whl

Total release size: 393.3 kB

Release files / opencplc-0.6.0.tar.gz

Download URL opencplc-0.6.0.tar.gz
Size 222.8 kB
Tags Source
SHA-256 checksum
How to use checksums
703b895d955badd132c179045db16d1b9b23eeefdee8cce3f6334a1224b457ef
BLAKE2b-256 checksum
How to use checksums
7f39f5d4c9df4cdcbd8e272a18f02c9423ffe3aa59db6e3fb7d2f1b0344c1a5f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Release files / opencplc-0.6.0-py3-none-any.whl

Download URL opencplc-0.6.0-py3-none-any.whl
Size 170.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a251474010e046caec0b23fcf293d1733a69f9f042193f67319472365cdba21a
BLAKE2b-256 checksum
How to use checksums
9ca8b7d15152763ccd7591be63008259ca7ef2c0c03d83a52b8c44cf1e23c8b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Security for opencplc 0.6.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for opencplc-0.6.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page