CForth for STM32G431, STM32F042 and STM32L476

CForth is a Forth interpreter system completely written in C language.
The intention is to make a straightforward user oriented Forth system,
specifically to organize interactive electronic control of art objects and installations or similar process control.

Primarily CForth is developed for a 32pin LQFP STM32G431KB processor.
I am a fan of these compact, high featured and easy to solder chips. Though originally bought for another project, the lockout time stimulated me to start this Forth development. My first Forth about 1992 was e-Forth with an 80C31 processor. Later I programmed some Forth for 68HC11 and AT90/ATmega. My last Forth interest was early 2000 a Windows console version written in C, which served as a first template for the actual project.

The first hardware design was a compact 1 layer etched PCB (not published). Because it is complicated to etch PCBs without appropriate tools, another Veroboard compatible layout (processor soldered on DIL breakout board like Adafruit 1163) was developed, which is presented here. A minimal breadboard setup is described in the DIY instruction.
An experimental small CForth based USB/DMX512 controller is presented at another place of this website.

As a side product, firmware and a Veroboard compatible hardware for 20pin TSSOP STM32F042F6 is developed too. It also works with STM32F070F6.
For this processsor, two differently specialized firmware versions are available:
One is equiped with an SPI interface instead (PA5=SCK, PA6=MISO, PA7=MOSI, new assigned 11Aug2020). So the limited number of processor I/O pins can be expanded. A compatible circuit is published at this website
The other version is provided with a MIDI interface. This firmware is compatible with a minimized STM32F042 board design, which is described at another place of this website.
A minimal Breadboard setup is shown below.

Another side product is a CForth version for STM32L476 Nucleo-64. It is optimized for a hardware design described at another place of this website.

Last not least a reduced version for an unmodified STM32G431 Nucleo-64 is derived.
But I am very disappointed about this Nucleo, it is an absolute downgrade of the Nucleo concept. Because the ST-LINK unit cannot be cut off and be used as a standalone programmer, it's effectively a playaround gadget and not useful for real projects. If I had known before, I would not have ordered it. Because the firmware modification for this board is quite easy, it is supported too.

Veroboard compatible PCB designs
Veroboard compatible PCB designs for CForth with STM32G431(LQFP32) and STM32F042(TSSOP20)
The STM32G431 version is enhanced with an DMX512 output

For all processor types an SPI interface is implemented.
Furthermore (except STM32F042), an I2C interface, two PWM pulse outputs and a random number generator is provided with the actual firmware versions.
For the STM32G431 Veroboard an optional DMX512 output is added.
All of these features are handled with specialized CForth kernel operators (Forth "words")..

Most essential features of CForth:

  • A basic set of standard Forth kernel operators ("words") is implemented
  • No attempt is made to comply with established Forth standards. Nevertheless, all typical features of most Forth dialects are supported.
  • No attempt is made to "program Forth by Forth". At the expensive of code length everything is programmed on rather flat subroutine nesting.
  • Where standard Forth systems compile sniblets of assembler code to manage runtime behaviour,
    I have introduced several specific "doAll" runtime operators for loops, conditionals, VARiables and CONSTants. So I think, I have got an acceptably fast and easy to understand and to manage Forth system.
  • Loops are organized more "C-programming style" than in traditional Forth.
  • A simple background process is implemented: selected Forth operators can be called via Terminal while another Forth thread is executing.
    This way constants and variables of the main thread can be modified externally during runtime,
    which allows interactive flow control of the executing thread.
    Furthermore single step execution can be switched on and off at any time and some debug information (like memory content) can be displayed via terminal during runtime of the main thread.
  • Any Forth User thread can be replaced by a new programmed one without "ripping" up the compiled code memory and complile it new. Change can be undone without reprogramming. This may be useful when a good idea comes later.
  • Line-end delimiter is "Carriage Return" (ASCII 13) only. To modify it into "Line Feed" (ASCII 10), exchange the numeric values of CRR and LFF in source file "globaldefines.h" and recompile.
F042 Breadboard minimal
Minimal breadboard setup with STM32F042. Colors of wires see schematic. The reset button is replaced by a yellow wire, which is plugged into the ground rail when ST-Link is connected and removed for firmware programming and CForth operation.
Usually C2 and C3 are not necessary.
Operation and CForth programming is done via USB virtual COM port. Additional components may be added, see DIY manual.

A detailled Forth Operating Manual (PDF file), and
a DIY Construction Manual (PDF file) is provided here.

A good tool for Forth source code upload is my DTerm Windows terminal software. It is surely not the best terminal emulator, but has been developed over the years for best fitness with my actual projects.

Downloads:
The subsequently downloadable material is copyrighted (c)2020 by Wolfgang Schemmert.
Assembly of the devices, programming and use of the software is permitted for free by everybody for any purpose ("freeware"). For commercial use, possible restrictions of third-party software contributors must be respected.
All information is based on best knowledge, but "as is" and without any warranty. Any responsibility is excluded. Use for dangerous, life-threatening and medical applications is forbidden.

PCB layout for the "STM32G431 board" PCB (1:1 TIF format. BOTTOM layer as well as component placement view are "from component side", i.e. BOTTOM layer shown mirrored "through the PCB" (as needed for PCB production))

PCB layout for the "STM32F042 board" PCB (1:1 TIF format. BOTTOM layer as well as component placement view are "from component side", i.e. BOTTOM layer shown mirrored "through the PCB" (as needed for PCB production))

Firmware "CForth-G431-48.hex" for Veroboard compatible PCB, SysClock = 48MHz
(Version 4.48 , 16 August 2020 - bugfix in terminal input interpreter and SPI initialisation + minor improvements)

Firmware "CForth-G431-144.hex" for Veroboard compatible PCB, SysClock = 144MHz
(Version 4.48 , 16 August 2020 - bugfix in terminal input interpreter and SPI initialisation + minor improvements)

Firmware "CForth-G431-DMX48.hex"
with a set of DMX512 kernel operators for Veroboard compatible PCB, SysClock = 48MHz
(Version 4.48 , 16 August 2020 - bugfix in terminal input interpreter and SPI initialisation + minor improvements)

Firmware "CForth-G431-DMX144.hex"
with a set of DMX512 kernel operators for Veroboard compatible PCB, SysClock = 144MHz
(Version 4.48 , 16 August 2020 - bugfix in terminal input interpreter and SPI initialisation + minor improvements)

Source code "CForth-G431.zip" (state 16 August 2020)
This source code is provided as complete "Segger Embedded Studio" project (ZIP file, 651 kB. Parts published by Segger are under license of Segger&|Rowley, parts published by STM are under license of STM, parts programmed by me are provided under GNU GPL3 license.)

Firmware "CForth-F042-SPI.hex" for Veroboard compatible PCB, supports SPI.
(Version 2.23 , 15 August 2020 - bugfix in terminal input interpreter + minor improvements)

Firmware "CForth-F042-MIDI.hex"with MIDI interface for minimal board
(Version 2.23 , 15 August 2020 - bugfix in terminal input interpreter + minor improvements)

Source code "CForth-F042.zip" (state 15 August 2020)
This source code is provided as complete "Segger Embedded Studio" project (ZIP file, 317 kB. Parts published by Segger are under license of Segger&|Rowley, parts published by STM are under license of STM, parts programmed by me are provided under GNU GPL3 license.)

Firmware "CForth-L476.hex" for a Nucleo board without ST-LINK module.
The L476 on-chip USB and USART is supported for communication
(Version 2.20 ,16 August 2020 - bugfix in terminal input interpreter and SPI initialisation + minor improvements)

Firmware "CForth-NucleoL476-unmod.hex"
reduced version for an unmodified STM32 Nucleo L476 board
(Version 2.20 , 16 August 2020 - bugfix in terminal input interpreter and SPI initialisation + minor improvements)

Source code "CForth-L476.zip" (state 16 August 2020)
This source code is provided as complete "Segger Embedded Studio" project (ZIP file, 406 kB. Parts published by Segger are under license of Segger&|Rowley, parts published by STM are under license of STM, parts programmed by me are provided under GNU GPL3 license.)

Firmware "CForth-NucleoG431-48.hex", SysClock = 48MHz
reduced version for an unmodified STM32 Nucleo G431 board
(Version 1.6 , 16 August 2020 - bugfix in terminal input interpreter and SPI initialisation + minor improvements)

Firmware "CForth-NucleoG431-144.hex", SysClock = 144MHz
reduced version for an unmodified STM32 Nucleo G431 board
(Version 1.6 , 16 August 2020 - bugfix in terminal input interpreter and SPI initialisation + minor improvements)

Source code "CForth-NucleoG431.zip" (state 16 August 2020)
This source code is provided as complete "Segger Embedded Studio" project (ZIP file, 380 kB. Parts published by Segger are under license of Segger&|Rowley, parts published by STM are under license of STM, parts programmed by me are provided under GNU GPL3 license.)

These projects are programmed directly on register level, no external libraries (except "cmsis" and startup code), no external drivers or HAL are used.



* State of information August 2020.
* Right of technical modifications reserved. Provided 'as is' - without any warranty. Any responsibility is excluded.
* This description is for information only. No product specifications are assured in juridical sense.
* Trademarks and product names cited in this text are property of their respective owners.