Mecrisp-Cube, Forth for the STM32 Ecosystem
Mecrisp-Stellaris Forth for the STM32 Cube ecosystem.

Forth is an interactive and extensible language, with built-in lexical analysis (tokenizer, parser) and interpreter/compiler, needs less than 20 KiB Flash and 4 KiB RAM, unbelievable for a self-contained (self-hosted) system.

Forth is perfect for embedded systems where some sort of user interactivity like CLI and extensibility (at runtime) are needed.

C & Forth in the 21st Century. C and Forth are both about 50 years old. To combine the strength of this two worlds results in a powerful system that outperforms other much newer systems like Python. Good design withstands the test of time.

The goal of Mecrisp-Cube is to be a complete Forth programming environment for STM32 MCUs. There are three flavors available:

Sources on GitHub. See ForthSTM32WB for standard Mecrisp-Stellaris for the STM32WB.


USB, BLE (for STM32WB55) and other Middlewares

STM32 Forth without BLE, USB, Filesystems, RTOS etc. is not complete, to build this in Forth by myself from the scratch overwhelms me. I would like to go the reverse way and use the STM tools like CubeIDE, HAL, CubeMX and integrate the Mecrisp-Cube Forth into it. Forth as an interactive extension for the STM32 ecosystem. Mecrisp-Cube Forth is running as a CMSIS-RTOS thread.

Already done Yes / Done

Integration in STM32 Cube Ecosystem


  • Forth as CMSIS-RTOS thread.
  • CMSIS-RTOS API to use FreeRTOS from Forth.
  • Buffered terminal I/O (5 KiB buffer for UART Rx). Interrupt driven and RTOS aware, key and emit block the calling thread.

USB Device

  • USB-CDC Device for serial communication via USB. Redirect console I/O like cdc-emit, cdc-key
  • USB-MSC Device: The USB mass storage device class (also known as USB MSC or UMS). You can use your Forth system as a flash drive (also thumb drive [US], memory stick [UK], and pen drive/pendrive elsewhere) with two LUNs: 0 for flash disk, 1 for microSD disk.


Board Support Package (BSP)

  • Onboard LEDs: LED1 (blue), LED2 (green), LED3 (red)
  • Switches: SW1, SW2, SW3
  • Digital port pins: D0 to D15
  • Analog port pins: A0 to A5
  • PWMs
  • Input capture, Output compare
  • SPI (e.g. for display, memory)
  • I2C: (external peripherals e.g. pressure)
  • Real Time Clock (32 bit UNIX time stamp, valid times are from 1.1.2000 to 31.12.2099 because of the STM32WB RTC peripheral) time!, time@, and .time (YYYY-MM-DDTHH:MM:SS ISO 8601).
  • Watchdog
  • Assertation and Logging


  • BLE 5.0 GAP Peripheral Role (STM32WB)
    • DIS Device Information Service
    • HRS Heart Rate Service (heart rate depends on A0 for Nucleo and A2 for Dongle)
    • CRS Cable Replacement Server service (proprietary service from STM, similar to Classic Bluetooth SPP). Redirect console I/O like crs-emit, crs-key.

Floating-Point Unit

  • Support for the floating-point unit FPU, single precision for M4F MPUs and double precision for M7 MPUs

External Peripherals (e.g. Feather Wings)


Planned TODO

  • BLE 5.0 GAP Peripheral Role (STM32WB)
    • BLE Event driven programming like LAIRD's smartBASIC, WAITEVENT ONEVENT.
    • BLE GATT (Characteristics, Services, Profiles)
    • Current Time Service
  • BLE 5.0 GAP Central Role (STM32WB)

Built With

  • STM32CubeIDE is an all-in-one multi-OS development tool, which is part of the STM32Cube software ecosystem. The IDE is used for development, GCC tools are included. Eclipse is not my favorite preferred development environment. I would like to replace it with VS Code and makefiles. VSCodeCubeMX
  • STM32CubeMX is a graphical tool that allows a very easy configuration of STM32 microcontrollers and microprocessors, as well as the generation of the corresponding initialization C code for the Arm® Cortex®-M core or a partial Linux® Device Tree for Arm® Cortex®-A core), through a step-by-step process.
  • STM32CubeProg is an all-in-one multi-OS software tool for programming STM32 products. the Java GUI does not work for me, but the CLI does. See STM Wiki

21st Century Forth

What's good about Forth

  • small
  • easy to understand
  • extendable
  • adaptable to programmer
  • interactive
  • open compiler/interpreter
  • simple architecture
  • source code available
  • helpful in learning about hardware and software

What's bad about Forth

  • NIH (not invented here)
  • cryptic reverse polish notation
  • difficult to learn
  • documentation sometimes lacking or unavailable
  • unconventional syntax
  • no linkage with other languages
  • getting more complex
  • lack of data typing
  • source (proprietary protection problem)

What 21st Century Forth should be

  • work in embedded applications
  • work with networks and Internet
  • work with large systems (operating systems, graphic user interface)
  • be able to be taught to programmers and engineers

What Forth needs

  • reuseable binaries (other languages & headers)
  • more/better/useable libraries
  • safety (year 2000)
  • better documentation
  • more examples
  • workable standards
  • better gui/window editor w/more information
  • package confidence
  • more debugger integration
  • works with newer CPUs (embedded systems, MCU)
  • publications
  • big daddy $$$
  • educational opportunities
  • more types of multitasking/multiprocessing pre-emtive multitasking

21st Century Forth desires and vision

  • real/virtual machines/core
  • scriptmaking (language to taste)
  • real compile toggle (memory, speed, optimization)
  • integratable applications
  • "browser" environment *
  • environments (such as voice) interpretation (fuzzy)
  • pda's bases, smart cards, etc
  • servants (robots, etc) applications

Forth 2012




This project Mecrsip-Cube is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Mecrsip-Cube is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Mecrsip-Cube. If not, see


-- Peter Schmid - 2019-12-29

Creative Commons License
This work by Peter Schmid is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Topic attachments
I Attachment History Action Size Date Who Comment
JPEGjpg Jost_Brgis_Logarithmentafel.jpg r1 manage 174.5 K 2022-12-30 - 16:41 PeterSchmid  
JPEGjpg feather-adaptor.jpg r1 manage 477.1 K 2021-05-22 - 08:15 PeterSchmid  
PNGpng mecrisp-cube-4th-logo.png r1 manage 10.8 K 2024-01-22 - 20:41 PeterSchmid  
PNGpng mecrisp-cube-logo-red-50.png r1 manage 1.2 K 2024-01-22 - 20:43 PeterSchmid  
JPEGjpg nucleo-header-logo.jpg r1 manage 39.1 K 2020-05-17 - 20:16 PeterSchmid  
PNGpng nucleo_wb55rg_arduino_left.png r1 manage 521.0 K 2020-04-30 - 08:44 PeterSchmid  
PNGpng nucleo_wb55rg_arduino_right.png r1 manage 528.2 K 2020-04-30 - 08:44 PeterSchmid  
PNGpng nucleo_wb55rg_morpho_left.png r1 manage 608.4 K 2020-04-30 - 08:44 PeterSchmid  
PNGpng nucleo_wb55rg_morpho_right2.png r1 manage 554.6 K 2020-04-30 - 08:44 PeterSchmid  
Edit | Attach | Watch | Print version | History: r179 < r178 < r177 < r176 < r175 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r179 - 2024-05-24 - PeterSchmid
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback