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.

Sources on GitHub.

See ForthSTM32WB for standard Mecrisp-Stellaris for the STM32WB.

NEW There is a new flavor for Mecrisp-Cube: MecrispCubeF405 for Adafruit's Feather STM32F405. And a variant for the ST32WB Feather Dev Board.

BLE Terminal in a browser.

USB, BLE and other Middlewares

STM32WB 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 Mecrips Forth into it. Forth as an interactive extension for the STM32 ecosystem. Mecrisp Forth running as a CMSIS-RTOS thread.

Already done Yes / Done

  • Integrated in STM32 Cube ecosystem. Create C code from CubeMX for internal peripherals and use it in Forth.
  • 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-CDC for serial communication via USB. Redirect console I/O like cdc-emit, cdc-key
  • microSD and internal Flash mass storage for blocks and FAT filesystem.
  • Calling C Functions from Forth and vice versa
  • vi Editor origin in BusyBox tiny vi. Workflow development: begin Edit EVALUATE while SaveFile repeat
  • Board Support Package BSP (for other boards see Adafruit Feather STM32F405, STM32WB5MM Discovery Kit, and STM32WB Feather development board)
    • LEDs: LED1 (blue), LED2 (green), LED3 (red)
    • Switches: SW1, SW2, SW3 (dongle: SW1)
    • Digital port pins: D0 to D15 (Dongle: D0, D1, D6, D10 to D15)
    • Analog port pins: A0 to A5 (Dongle: A2, A3)
    • PWM: D3, D6, D9 (Dongle: D6)
    • Input capture: A2
    • Output compare: D0, D1, D5 (Dongle: D0, D1)
    • SPI: D11 MOSI, D12 MISO, D13 SCK (e.g. for display, memory)
    • I2C: D14 SDA, D15 SCL (external peripherals e.g. pressure)
  • BLE 5.0 GAP Peripheral Role
    • 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.
  • 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).
  • OLED Display 128x32, I2C
  • Markdown manual pages

Planned TODO

Getting Started

These instructions will get you a copy of the project up and running on your local machine (STM32 Nucleo board) for development and testing purposes.


  • STM32WB Nucleo Board - The highly affordable STM32 Nucleo boards allow anyone to try out new ideas and to quickly create prototypes with any STM32 MCU. The STM32 Nucleo boards integrate an ST-Link debugger/programmer, so there is no need for a separate probe.
  • Terminal emulator application for PC, e.g.:
    • PuTTY - Windows and Linux
    • Tera Term - Windows
    • Realterm - Windows
    • minicom, microcom, screen - Linux
    • Use the built in Eclipse console (but no LF)

Flash the Mecrisp-Cube binary or the FS binary with local filesystem and some tools to the Nucleo Board.

  1. Connect the Nucleo Board USB ST-LINK to the PC
  2. Copy binary (MecrispCube.bin) to the USB mass storage NODE_WB55RG

Start the terminal emulator application on the PC. Check for the serial communication port (e.g. for Linux /dev/ttyACM0) and set the speed to 115200 baud. I set the putty terminal configuration to

  • Implicit CR in every LF
  • Local echo: Auto
  • Local line editing: Auto
  • Keyboard Backspace: Control-H
  • Keyboard Function: Keys VT100
  • Remote character set: CP850

Mecrisp-Stellaris RA 2.5.4 by Matthias Koch. 

Mecrisp-Cube 1.4.1 for STM32WB55, 63/128 KiB RAM/FLASH dictionary (C) 2020
  * Firmware Package STM32Cube FW_WB V1.10.0, USB-CDC, BLE Stack 5.0 (C) 2020 STMicroelectronics 
  * CMSIS-RTOS V2 FreeRTOS wrapper, FreeRTOS Kernel V10.2.1 (C) 2017
  * FatFs for internal flash and microSD - Generic FAT fs module  R0.12c (C) 2017 ChaN
  * tiny vi - part of BusyBox (C) 2000, 2001 Sterling Huxley

23 5 / .[CR] 4  ok.
: hello ." World" ;[CR]  ok.
hello[CR] World ok.


A step by step series of examples that tell you how to get a development env running

Install the IDE STM32CubeIDE, it is Eclipse and GCC based. STM32CubeMX is included in the IDE, you need a stand alone installation only if you do not want to use the STM32CubeIDE.

Get the sources from github:

psi@homer:~> git clone
Klone nach 'Mecrisp-Cube' ...
remote: Enumerating objects: 106, done.
remote: Counting objects: 100% (106/106), done.
remote: Compressing objects: 100% (71/71), done.
remote: Total 106 (delta 33), reused 106 (delta 33), pack-reused 0
Empfange Objekte: 100% (106/106), 938.96 KiB | 2.39 MiB/s, Fertig.
Löse Unterschiede auf: 100% (33/33), Fertig.

Import the project into the IDE:

File -> Import -> General -> Existing Projects into Workspace -> Select root directory
Copy project into workspace
Browse to Mecrisp-Cube directory

Generate code from the STM32CubeMX MecrispCube.ioc file:

Project -> Generate Code 

Restore changed source files

$ git status
{list of changed files}
$ git restore {files to restore} 

Select the Build Configuration (Debug if you want to debug the project) and Build the project:

Project -> Build Configurations -> Set Active -> Debug/Reelease 
Project -> Build Project

STM32WB Development Boards

STM32WB Nucleo Board


nucleo wb55rg arduino left.png
Arduino left
nucleo wb55rg arduino right.png
Arduino right
nucleo wb55rg morpho left.png
Morpho left
nucleo wb55rg morpho right2.png
Morpho right

STM32WB Feather Development Board

This Adafruit Feather compatible development board is from Reclaimer Labs. You can find more information about this excellent board on the Reclaimer Labs Site and an overview of the Adafruit Feather boards.

Board Support Package BSP for STM32WB Feather development board

STM32WB55 Discovery Kit STM32WB5MM-DK

Board Support Package BSP for the STM32WB5MM Discovery Kit.

Nucleo Dongle - Feather Adaptor

Remove the USB Type A plug from the dongle and add a Adafruit Micro B breakout board. It is convenient to have a Micro-SD breakout board (level shifter is not needed) and JTAG connector (I prefer the 14 pin STM variant to have a serial interface by the ST-LINK). Everything mounted on headers on the backside of FeatherWing Tripler Mini Kit.

Description Dongle Function Feather Micro-SD JTAG 14pin
GND CN1.1 GND JP1.13 GND GND 5, 7, 11
NRST CN1.2 RES JP1.16 RST   12
PA13 CN1.3 SWDIO -   4
PA14 CN1.4 SWDCLK -   6
PB3 CN1.5 SWO A4?   8
3V3 CN1.6 3V3 JP1.14/15 3V3 3V 5V 3
PB2 CN1.7 SPI_CS - CS  
PA5 CN1.8 D13 SCK JP1.6 SCK CLK  
PA6 CN1.9 D12 MISO JP1.4 MISO DO  
PA7 CN1.10 D11 MOSI JP1.5 MOSI DI  
PB8 CN2.1 D15 SCL JP3.11 SCL    
PB9 CN2.2 D14 SDA JP3.12 SDA    
PA0 CN2.3 A3 JP1.9 A3    
PA2 CN2.4 D1 JP1.2 D1    
PA3 CN2.5 D0 JP1.3 D0    
PB6 CN2.6 UARTRX     13
PA9 CN2.7 D9 JP3.8 D9    
PB7 CN2.7 UARTTX     14
PA8 CN2.8 D6 JP3.9 D6    
PA1 CN2.10 A2 JP1.10 A2    
USB5V   5V JP3.3 USB    
BOOT0   BOOT0 JP1.1 B0    
PB0 AT2 ?     JP1.12 A0    
PB1 AT2 ?     JP1.11 A1    
PB3 ? CN1.5 SWO JP1.8 A4?   8
      JP1.7 A5    
      JP3.1 VBAT    
      JP3.2 EN    

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.
  • 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

Flash Mecrisp-Cube to the Target

Alternate ways to flash Mecrisp-Cube to the target. For the easy way see WebHome#Prerequisites.

Nucleo Board

Connect Nucleo's ST-LINK USB to you PC. Erase the flash e.g. by openOCD, we use 768 KiB Right 192 sectors.

$ telnet localhost 4444
Trying ::1...
telnet: connect to address ::1: Connection refused
Connected to localhost.
Escape character is '^]'.
Open On-Chip Debugger
> reset init
Unable to match requested speed 500 kHz, using 480 kHz
Unable to match requested speed 500 kHz, using 480 kHz
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08003aae msp: 0x20000430
> flash erase_sector 0 0 192
erased sectors 0 through 192 on flash bank 0 in 4.583453s
> flash write_image mecrisp-stellaris-stm32wb55.hex
device idcode = 0x20016495 (STM32WB5x - Rev: 2.1)
flash size = 1024kbytes
flash mode : single-bank
Padding 4 bytes to keep 8-byte write size
block write succeeded
wrote 15404 bytes from file mecrisp-stellaris-stm32wb55.hex in 0.329747s (45.620 KiB/s)

> shutdown
shutdown command invoked
Connection closed by foreign host.

USB Dongle

The USB Dongle does not have a ST-Link interface, but the STM32WB has a built-in boot-loader. This bootloader works via USB. As programming tool I use the CLI from the STM32CubeProg package.

$ alias cubepgmcli='/opt/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin/STM32_Programmer_CLI'
$ cubepgmcli -c port=USB1 -e [0 191]
$ cubepgmcli -c port=USB1 -d Release/MecrispCube.bin 0x8000000 
$ cubepgmcli -c port=USB1 -ob displ

BTW you can flash the Nucleo Board in the same way.

Update BLE Stack

You can find the BLE Stack and FUS in STM32CubeWB or from GitHub, in the directory Projects/STM32WB_Copro_Wireless_Binaries.

Nucleo board: Using USB_USER interface and the built-in bootloader (activate with jumper between CN7.5 and CN7.7)

$ alias cubepgmcli='/opt/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin/STM32_Programmer_CLI'
$ cd STM32Cube_FW_WB_V1.6.0/Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x
$ cubepgmcli -c port=USB1 -fwdelete
$ cubepgmcli -c port=USB1 -fwupgrade stm32wb5x_FUS_fw_1_0_2.bin 0x080EC000 firstinstall=0
$ cubepgmcli -c port=USB1 -fwupgrade stm32wb5x_FUS_fw.bin 0x080EC000 firstinstall=0
$ cubepgmcli -c port=USB1 -fwupgrade stm32wb5x_BLE_Stack_full_fw.bin 0x080CB000 firstinstall=1

Using STM32 Cube Programmer (here to show the option bytes, SBRV : 0x32C00 means start address 4 * SBRV + 0x08000000 = 0x080CB000, 3D000 means there is no stack):

psi@homer:~/Dropbox/wbForth/CubeWB> cubepgmcli -c port=SWD -ob displ
                        STM32CubeProgrammer v2.4.0                  

ST-LINK SN  : 066BFF313335415043141250
ST-LINK FW  : V2J36M26
Voltage     : 3,22V
SWD freq    : 4000 KHz
Connect mode: Normal
Reset mode  : Software reset
Device ID   : 0x495
Device name : STM32WB55xx
Flash size  : 1 MBytes
Device type : MCU
Device CPU  : Cortex-M0+/M4


  Bank          : 0x00
  Address       : 0x58004020
  Size          : 104 Bytes

[==================================================] 100% 


   Read Out Protection:

     RDP          : 0xAA (Level 0, no protection) 

   BOR Level:

     BOR_LEV      : 0x0 (BOR Level 0 reset level threshold is around 1.7 V) 

   User Configuration:

     nBOOT0       : 0x1 (nBOOT0=1 Boot from main Flash) 
     nBOOT1       : 0x1 (Boot from code area if BOOT0=0 otherwise system Flash) 
     nSWBOOT0     : 0x1 (BOOT0 taken from PH3/BOOT0 pin) 
     SRAM2RST     : 0x0 (SRAM2 erased when a system reset occurs) 
     SRAM2PE      : 0x1 (SRAM2 parity check disable) 
     nRST_STOP    : 0x1 (No reset generated when entering the Stop mode) 
     nRST_STDBY   : 0x1 (No reset generated when entering the Standby mode) 
     nRSTSHDW     : 0x1 (No reset generated when entering the Shutdown mode) 
     WWDGSW       : 0x1 (Software window watchdog) 
     IWGDSTDBY    : 0x1 (Independent watchdog counter running in Standby mode) 
     IWDGSTOP     : 0x1 (Independent watchdog counter running in Stop mode) 
     IWDGSW       : 0x1 (Software independent watchdog) 
     IPCCDBA      : 0x0  (0x0) 

   Security Configuration Option bytes:

     ESE          : 0x1 (Security enabled) 
     SFSA         : 0xCB  (0xCB) 
     FSD          : 0x0 (System and Flash secure) 
     DDS          : 0x1 (CPU2 debug access disabled) 
     C2OPT        : 0x1 (SBRV will address Flash) 
     NBRSD        : 0x0 (SRAM2b is secure) 
     SNBRSA       : 0xF  (0xF) 
     BRSD         : 0x0 (SRAM2a is secure) 
     SBRSA        : 0xA  (0xA) 
     SBRV         : 0x32C00  (0x32C00) 

   PCROP Protection:

     PCROP1A_STRT : 0x1FF  (0x8000FF8) 
     PCROP1A_END  : 0x0  (0x8000008) 
     PCROP_RDP    : 0x1 (PCROP zone is erased when RDP is decreased) 
     PCROP1B_STRT : 0x1FF  (0x8000FF8) 
     PCROP1B_END  : 0x0  (0x8000008) 

   Write Protection:

     WRP1A_STRT   : 0xFF  (0x80FF000) 
     WRP1A_END    : 0x0  (0x8000000) 
     WRP1B_STRT   : 0xFF  (0x80FF000) 
     WRP1B_END    : 0x0  (0x8000000)

Alternate way to erase the flash memory (change the Memory Read Protection from Level 1 to level 0):

$ cubepgmcli -c port=swd -ob rdp=0xbb
$ cubepgmcli -c port=swd -rdu

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 feather-adaptor.jpg r1 manage 477.1 K 2021-05-22 - 08:15 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: r146 < r145 < r144 < r143 < r142 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r146 - 2021-11-18 - PeterSchmid
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2021 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback