back to menue

CForth for STM32G4xx, STM32F042 and STM32L476

CForth is a simple 32bit Forth interpreter system completely written in C language.
(no relationship to "Mitch Bradley's CForth")
The intention is to provide a straightforward user oriented Forth system,
specifically to organize interactive electronic control of art objects and installations or similar process control.

Primarily CForth was developed for the 32pin LQFP STM32G431KB and STM32G441KB 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.

Because it is complicated to etch PCBs without appropriate tools, a Veroboard compatible PCB layout was developed (processor soldered on DIL breakout board like Adafruit 1163), which is presented here.
An experimental small CForth based USB/DMX512 controller is presented at another place of this website.
All firmware versions include an SPI interface, two PWM pulse outputs, an I2C interface and a random number generator.
Furthermore, an optional DMX512 output for the Veroboard PCB version is added.
The useability of the MIDI interface is improved with the actual firmware (Dec.2020 and later).
All of these features are accessed directly with specialized CForth kernel operators (Forth "words").

As a side product, firmware and Veroboard compatible PCB layouts for 20pin TSSOP STM32F042F6 and 32 pin LQFP STM32F042K6 are developed too. It also works with STM32F070.
The small memory size (Flash as well as SRAM) of these processors demands some restrictions concerning kernel operators, max. size of user programs, available I/O features.
To open this bottleneck a little bit, the threaded code for these processors is organized in a compact 8 bit array. This provides up to 3 times more Forth code compared with a straight 32bit word oriented code thread (which is used for the STM32G4 processors). The additional runtime overhead is moderate.

A slightly modified CForth firmware is designed for the small USB to Midi or RS-232 interface 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 with ST-LINK cut off. It is optimized for a hardware design described at another place of this website. It has essentially the same features as the standard STM32G431 version, inclusive MIDI I/O. A basic firmware version for an unmodified STM32L476 Nucleo is provided, too.

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 with basic features.

Low power versions for STM32G4xx and STM32F042 are added at this website

Veroboard compatible PCB designs
Veroboard compatible PCB designs for CForth with
STM32G431(LQFP32 on 32 pin breakout board)                           and   STM32F042(TSSOP20)

Both boards have an optional MIDI IN, the STM32G431 version is equipped with an optional DMX512 output and a switching regulator for external power supply.

Most essential features of the CForth kernel:

F042 Breadboard minimal
Minimal breadboard setup with STM32F042. I/O can be added by user as needed for some experiments.

Colors of wires see schematic. The reset button is replaced by a yellow wire, which is plugged into the ground rail to "Connect" ST-Link for firmware programming and is removed when "Connect" is done. Start upload and programming of the CForth hex file then.
Most times C2 and C3 are not necessary for this processor type.
Operation and CForth programming is done via USB virtual COM port.
Additional components may be added, see DIY manual.

A detailled CForth Operating Manual (PDF file), and
a DIY Construction Manual for STM32G431 and STM32F042 (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-22 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, restrictions of third-party software contributors (Segger GmbH, STM) 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.

The actual firmware is programmed with "Segger Embedded Studio 5.44".

PCB layout for the "STM32G431 and STM32G441 LQFP32 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 "20pin TSSOP STM32F042F6 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 "32pin LQFP STM32F042K6 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-G4xx-48.hex" for Veroboard compatible PCB, LQFP32, SysClock = 48MHz
(21 December 2021 - minor bugfix, minor code improvement)

Firmware "CForth-G4xx-144.hex" for Veroboard compatible PCB, LQFP32, SysClock = 144MHz
(21 December 2021 - minor bugfix, minor code improvement)

Firmware "CForth-G4xx-DMX48.hex"
with a set of DMX512 kernel operators for Veroboard compatible PCB, LQFP32, SysClock = 48MHz
(21 December 2021 - bugfix DMX port blocking for general I/O, else minor bugfix, minor code improvement)

Firmware "CForth-G4xx-DMX144.hex"
with a set of DMX512 kernel operators for Veroboard compatible PCB, LQFP32, SysClock = 144MHz
(21 December 2021 - bugfix DMX port blocking for general I/O, else minor bugfix, minor code improvement)

Source code "CForth-G4xx-v56.zip"
(state 21 December 2021) This source code is provided as complete "Segger Embedded Studio" project (ZIP file, 767 kB).
Parts published by Segger GmbH 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-motor.hex" for 20pin TSSOP Veroboard compatible PCB, SysClock = 48MHz. Kernel Ops for SPI, stepper motor and PWM1 included. PWM2 not implemented. USART can operate as terminal or as serial output
(18 April 2022 - minor improvements)

Firmware "CForth-F042lqfp-motor.hex" for 32pin LQFP Veroboard compatible PCB, SysClock = 48MHz. Kernel Ops for SPI, stepper motor and PWM1 included. PWM2 not implemented. USART can operate as terminal or as serial output
(18 April 2022 - first release)

Firmware "CForth-F042-pwm2.hex" for 20pin TSSOP Veroboard compatible PCB, SysClock = 48MHz. Kernel Ops for SPI and PWM1,PWM2 included. USART can operate as terminal or as serial output
(18 April 2022 - minor improvements)

Firmware "CForth-F042lqfp-pwm2.hex" for 32pin LQFP Veroboard compatible PCB, SysClock = 48MHz. Kernel Ops for SPI and PWM1,PWM2 included. USART can operate as terminal or as serial output
(18 April 2022 - first release)

Firmware "CForth-F042-midi.hex" can operate the serial I/O as conventional RS-232 or as MIDI interface. Instead no SPI, motor and PWM code implemented. For 20pin TSSOP Veroboard compatible PCB, SysClock = 48MHz
(18 April 2022 - minor improvements)

Firmware "CForth-F042lqfp-midi.hex" can operate the serial I/O as conventional RS-232 or as MIDI interface. Instead no SPI, motor and PWM code implemented. For 32pin LQFP Veroboard compatible PCB, SysClock = 48MHz
(18 April 2022 - first release)

Firmware "CForth-F042-mini.hex" This firmware fits for the small USB/serial interface, the USART Tx level is not inverted, because this board is equipped with an external CMOS inverter and 5V level shifter. Else the code is the same as "CForth-F042-midi.hex". SysClock = 48MHz.
(18 April 2022 - minor improvements)

Source code "CForth-F042-v31.zip"
(18 April 2022) This source code is provided as complete "Segger Embedded Studio" project (ZIP file, 553 kB).
Parts published by Segger GmbH 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-cutoff.hex" for a Nucleo board with the ST-LINK module cut off.
The L476 on-chip USB and USART is supported for communication. Else features almost the same as CForth-G4xx-48.
(21 December 2021 - minor bugfix, minor code improvements)

Firmware "CForth-NucleoL476-orig.hex"
reduced version for an unmodified STM32 Nucleo L476 board. Terminal communication exclusively via ST-Link USB.
(21 December 2021 - minor bugfix, minor code improvements)

Source code "CForth-L476-v26.zip"
(state 21 December 2021) This source code is provided as complete "Segger Embedded Studio" project (ZIP file, 467 kB).
Parts published by Segger GmbH 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
(21 December 2021 - minor bugfix, minor code improvements)

Firmware "CForth-NucleoG431-144.hex", SysClock = 144MHz
reduced version for an unmodified STM32 Nucleo G431 board. Terminal communication exclusively via ST-Link USB.
(21 December 2021 - minor bugfix, minor code improvements)

Source code "CForth-NucleoG431-v13.zip"
(state 21 December 2021) This source code is provided as complete "Segger Embedded Studio" project (ZIP file, 443 kB).
Parts published by Segger GmbH 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", startup code and Segger system code), no external drivers or HAL are used.


back to menue


* State of information April 2022.
* 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.