Skip to content
STM8 eForth: a user-friendly Forth for cheap µCs with docs >>>
Assembly Forth Python Awk C Makefile Other
Branch: master
Clone or download
Latest commit 48a3474 Aug 17, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
C0135 fixed #189 Enable UART simulation on Port E Apr 13, 2018
CORE #265 full featured 4095 bytes binary Aug 16, 2019
DCDC fixes #194 Improve behavior of serial interface w/ shared LED-Display… Apr 15, 2018
DOUBLECOM fixed #189 Enable UART simulation on Port E Apr 13, 2018
MINDEV fixed #189 Enable UART simulation on Port E Apr 13, 2018
STM8L-DISCOVERY STM8L-Disco: LCD driver, short usage. May 17, 2018
STM8L051F3 fixes 16: STM8L051F3 USART TX:PA2/RX:PA3 as the default May 27, 2018
STM8S001J3 Basic info for the STM8S001J3 Sep 25, 2018
STM8S105K4 fixed #189 Enable UART simulation on Port E Apr 13, 2018
STM8S207RB fixed #189 Enable UART simulation on Port E Apr 13, 2018
SWIMCOM fixed #189 Enable UART simulation on Port E Apr 13, 2018
W1209-CA fixed #189 Enable UART simulation on Port E Apr 13, 2018
W1209-FD fixed #189 Enable UART simulation on Port E Apr 13, 2018
W1209 fixed #189 Enable UART simulation on Port E Apr 13, 2018
W1219 fixed #189 Enable UART simulation on Port E Apr 13, 2018
W1401 fixes #194 Improve behavior of serial interface w/ shared LED-Display… Apr 15, 2018
XH-M188 fixed #189 Enable UART simulation on Port E Apr 13, 2018
XH-M194 fixes #128 RTC burst-mode Apr 15, 2018
XY-LPWM Added makefile rules 'term' for run e4thcom terminal May 11, 2018
XY-PWM Basic support for XY-PWM/HW-0515 PWM generator board May 14, 2018
barebones Move barebones files into own directory Jun 15, 2017
docs #265 dictionary test Aug 16, 2019
examples 2018 version of VOC I2C example Dec 27, 2018
inc #265 full featured 4095 bytes binary Aug 16, 2019
lib #265 full featured 4095 bytes binary Aug 16, 2019
mcu add UART_DIV Feb 11, 2019
test #265 dictionary test Aug 16, 2019
tools #265 dictionary test Aug 16, 2019
.gitignore fixes #76 test automation facilities, console based smoke test Oct 1, 2017
.travis.yml use SDCC-DOCKER:V3.8.6 May 26, 2019
CONTRIBUTING.md Update CONTRIBUTING.md Sep 30, 2017
LICENSE.md issue #32 Build framework feature #include Jul 2, 2017
Makefile closes #243 tools features Jan 11, 2019
README.md Release 2.2.23 May 26, 2019
forth.asm #265 full featured 4095 bytes binary Aug 16, 2019
forth.h Initial set of files based on STM8EF, Version 2.1, 13jul10cht from ht… Jul 2, 2016
main.c issue #128: initial commit for XH-M194 7S-LED, keys, outputs Apr 13, 2018

README.md

STM8 eForth (stm8ef)

Travis-CI

STM8 eForth is a very compact interactive Forth system for STM8 µCs. It provides a binary release, a library, a plug-in system for board support and automated tests with uCsim. Core features include simple multitasking with interactive parameter setting and autostart-operation.

It runs on an STM8 µC as a compiler-interpreter and interacts with the user through a console (e.g. using e4thcom or a serial terminal).

STM8EF Wiki

STM8 eForth is based on Dr. C.H. Ting's eForth for the STM8S Discovery. With the kind permission of the original author it has a permissive FOSS license.

Forth is a simple but highly extensible programming language. "Hello World" is as simple as this:

: hello ."  Hello World!" ;

STM8 eForth is configurable: a full featured binary needs between 4.7K and 5.5K, a basic interactive Forth fits in just 3.5K. The unique ALIAS feature provides access to headerless Forth words enables interactive programming even on the smallest available STM8 device (e.g. STM8S003F2 with 4K Flash memory).

The Forth console works with an STM8 UART, a pair of GPIOs, or even any single GPIO and 3-wire or 2-wire communication. Up to two UARTs and a simulated serial interface are supported. The console can be configured for any type of character I/O (e.g. keyboard and display), even at runtime!

The Wiki on GitHub covers various topics, e.g. using Breakout Boards, or the conversion of low-cost Chinese thermostats, voltmeters, or DC/DC-converters into Forth powered embedded control boards.

Generic targets

Generic target binaries are provided as examples and for evaluation:

  • STM8S Low Density devices (e.g. STM8S003x3, STM8S103x3, STM8S903x3 or STM8S001J3)
    • CORE, a basic configuration for STM8S Low Density devices, some features are disabled (e.g. no background task)
    • SWIMCOM, a full feature set, and 2-wire communication through PD1/SWIM (i.e. the ICP pin)
    • DOUBLECOM console through the SWIM interface, UART I/O words are provided for applications
    • STM8S001J3 like SWIMCOM but with console through PD5/UART_TX in half-duplex mode (this binary is compatible with all STM8S Low Density devices)
  • STM8S105K4 for STM8S Medium Density devices (Value Line / Access Line)
  • STM8S207RB initial support for STM8S High Density devices (Performance Line)
  • STM8L051J3 support for STM8L Low Density devices (see issue)
  • STM8L-DISCOVERY support for STM8L Medium Density devices

Various STM8 Discovery boards and breakout boards for Low-, Medium-, and High-Density devices can be used. Initial support for STM8L Medium Density devices is available.

Board support:

TG9541/STM8EF provides board support for several common "Chinese gadgets" like the following:

  • MINDEV for the STM8S103F3P6 $0.65 "minimum development board"
  • C0135 "Relay-4 Board" - it can be used as a Nano PLC
  • W1209 $1.50 thermostat board w/ 3 digit 7S-LED display, full- or half-duplex RS232
  • W1219 low cost thermostat with 2x3 digit 7S-LED display, half-duplex RS232 through PD1/SWIM
  • W1401 (also XH-W1401) thermostat with 3x2 digit 7S-LED display, half-duplex RS232 through SWIM
  • DCDC hacked DCDC converter with voltmeter
  • XH-M194 Timer board with 6 relays, RTC with clock display, and 6 keys
  • XY-PWM PWM board w/ 3 digit 7S-LED display, 3 keys, dual PWM and full-duplex RS232
  • XY-LPWM PWM board w/ 2x4 digit 7S-LCD display, 4 keys, PWM and full-duplex RS232

The Wiki lists other supported "Value Line Gadgets", e.g. voltmeters & power supplies, breakout boards, and thermostats.

Feature Overview

In addition to basic eForth, STM8 eForth offers many features:

  • Subroutine Threaded Code (STC) with improved code density
    • native BRANCH (JP), and EXIT (RET)
    • relative CALL where possible (2 instead of 3 bytes)
    • TRAP as pseudo-opcode for literals (3 instead of 5 bytes)
    • ALIAS words for indirect dictionary entries (even in EEPROM!)
  • compile Forth to NVM (Non Volatile Memory) with IAP (In Application Programming)
    • Words NVM and RAM switch between volatile (RAM) and non volatile (NVM) modes (REMEMBER execute RAM after NVM if you want your new words to be available after power-cycle or COLD)
    • RAM allocation for VARIABLE and ALLOT is transparent in NVM mode (basic RAM management)
    • autostart feature for embedded applications
  • Low-level interrupts in Forth
    • lightweight context switch with SAVEC and IRET
    • example code for HALT is in the Wiki
  • preemptive background tasks BG
    • INPUT-PROCESS-OUTPUT task indepent of the Forth console
    • fixed cycle time (configurable, default: 5ms)
    • on supported boards ?KEY reads board keys, EMIT uses board display
    • robust context switch with "clean stack" approach
  • cooperative multitasking with 'IDLE
    • idle task execution while there is no console input
    • very fast idle loop (< 10µs)
  • configuration options for serial console or dual serial interface
    • UART: ?RX and TX!
    • any GPIO or pair of GPIOs from ports PA through PD can be used as a simulated COM port
    • GPIO w/ Port edge & Timer4 interrupts: ?RXP .. TXP!
    • half-duplex "bus style" communication using simulated COM port or UART
    • option for TX! .. ?RX on simulated COM port, and ?RXP .. TXP! on UART
  • configurable vocabulary subsets for binary size optimization
    • configuration possible down to the level of single words
    • export of ALIAS definitions for unlinked words
  • Extended vocabulary:
    • CREATE ... DOES> for defining defining words
    • Vectored I/O: 'KEY? and 'EMIT
    • Loop structure words: DO .. LEAVE .. LOOP, +LOOP
    • STM8S ADC control: ADC!, ADC@
    • board keys, outputs, LEDs: BKEY, KEYB?, EMIT7S, OUT, OUT!
    • EEPROM, FLASH lock/unlock: LOCK, ULOCK, LOCKF, ULOCKF
    • native bit set/reset: B! (b a u -- ), [ .. ]B! (and more)
    • native 16bit STM8 timer register access: 2C@, 2C!
    • compile to Flash memory: NVR, RAM, WIPE, RESET
    • autostart applications: 'BOOT
    • EVALUATE for interpreting text strings (even in the idle task!)
    • many words that were missing in eForth compared to Forth systems popular in the 1980s
  • board support for STM8S based very-low-cost boards:
    • STM8S103F3P6 "$0.80" breakout board
    • Termostats, e.g. W1209, W1219, or W1401
    • Low cost power supply boards, e.g. XH-M188, DCDC w/ voltmeter
    • C0135 Relay Board
    • configuration folders for easy application to new boards

Other changes to the original STM8EF code:

  • "ASxxxx V2.0" syntax (the free SDCC tool chain allows mixing Forth, assembly, and C)
  • hard STM8S105C6 dependencies removed (e.g. initialization, clock, RAM layout, UART2)
  • flexible RAM layout, basic RAM memory management, meaningful symbols for RAM locations
  • conditional code for different target boards with a subdirectory based configuration framework
  • original code bugs fixed (e.g. COMPILE, DEPTH, R!, PICK)
  • significant binary size reduction

Disclaimer, copyright

This is a hobby project! Don't use the code if support or correctness are required.

Additional licenses might apply to the code which might require derived work to be made public! Please refer to LICENSE.md for details.

You can’t perform that action at this time.