CForth for STM32G431, STM32G441 and STM32F042
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.
Very new is a LQFP48 version for STM32G4xx processors. It is a simplified "Black Pill" compatible PCB layout. Because it is made with home-makers technologies, the USB connector, the reset button and the BOOT0 button could not be integrated on the PCB. Therefore it is called "Grey Pill".
All firmware versions include a combined RS-232/MIDI interface, 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.
All of these features are accessed directly with specialized CForth kernel operators (Forth "words").
A reduced version for an unmodified STM32G431 Nucleo-64 is available, too
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.
Soon after, firmware and Veroboard compatible PCB layouts for 20pin TSSOP STM32F042F6 and 32 pin LQFP STM32F042K6 were developed. Also works with STM32F070.
The small memory size (Flash as well as SRAM) of these processors demands some restrictions concerning number of 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.
Veroboard compatible PCB designs:
Both boards have an optional MIDI IN. The STM32G431 version is equipped with an optional DMX512 output and an optional switching regulator for external power supply.
CForth has been ported to other STM32 projects and processors. These projects are described on individual HTML pages:
Most essential features of the CForth kernel:
A detailled CForth Operating Manual (PDF file), and
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 actual firmware is programmed with "Segger Embedded Studio 5.44".
Firmware "CForth-G4xx-48.hex" for Veroboard compatible PCB, LQFP32, SysClock = 48MHz
Firmware "CForth-G4xx-144.hex" for Veroboard compatible PCB, LQFP32, SysClock = 144MHz
Firmware "CForth-G4xx-DMX48.hex"
Firmware "CForth-G4xx-DMX144.hex"
Firmware "CForth-G4xx-Grey48" (LQFP48 "Grey Pill")
Firmware "CForth-G4xx-Grey144.hex" (LQFP48 "Grey Pill")
Firmware "CForth-G4xx-GreyDMX48.hex" (LQFP48 "Grey Pill")
Firmware "CForth-G4xx-GreyDMX144.hex" (LQFP48 "Grey Pill")
Source code "CForth-G4xx-v62.zip"
Firmware "CForth-F042-pwm2.hex" for 20pin TSSOP Veroboard compatible PCB, SysClock = 48MHz.
Firmware "CForth-F042LQFP-pwm2.hex" for 32pin LQFP Veroboard compatible PCB, SysClock = 48MHz.
Firmware "CForth-F042-motor.hex" for 20pin TSSOP Veroboard compatible PCB, SysClock = 48MHz.
Firmware "CForth-F042LQFP-motor.hex" for 32pin LQFP Veroboard compatible PCB, SysClock = 48MHz.
Firmware "CForth-F042-midi.hex" can operate the serial I/O as conventional RS-232 or as MIDI interface.
Firmware "CForth-F042LQFP-midi.hex" can operate the serial I/O as conventional RS-232 or as MIDI interface.
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.
Source code "CForth-F042-v37.zip"
Firmware "CForth-NucleoG431-48.hex", SysClock = 48MHz
Firmware "CForth-NucleoG431-144.hex", SysClock = 144MHz
Source code "CForth-NucleoG431-v19.zip"
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.
This firmware has essentially the same features as the standard STM32G431 version.
Firmware versions for unmodified Nucleo boards are provided, too.
Minimal breadboard setup with STM32F042. I/O can be enhanced as needed by user.
specific "doAll" runtime operators are introduced for loops, conditionals, VARCONs. So I think, I have got an acceptably fast and rather easy to understand and to manage Forth system.
This way VARCONs of the main thread can be modified externally during runtime for example, which allows interactive flow control of the executing thread.
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. The background process can be switched off, to get approx. 40% higher execution speed.
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 hardware DIY Construction Manual for STM32G431/G441 and STM32F042 (HTML file) is provided here.
The subsequently downloadable material is copyrighted (c)2020-24 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.
(09 April 2024 - bugfix)
(09 April 2024 - bugfix)
with a set of DMX512 kernel operators for Veroboard compatible PCB, LQFP32, SysClock = 48MHz
(09 April 2024 - bugfix)
with a set of DMX512 kernel operators for Veroboard compatible PCB, LQFP32, SysClock = 144MHz
(09 April 2024 - bugfix)
for Black Pill compatible Veroboard PCB, LQFP48, SysClock = 48MHz
(09 April 2024 - bugfix)
for Black Pill compatible Veroboard PCB, LQFP48, SysClock = 144MHz
(09 April 2024 - bugfix)
with a set of DMX512 kernel operators for Black Pill compatible Veroboard PCB, LQFP48, SysClock = 48MHz
(09 April 2024 - bugfix)
with a set of DMX512 kernel operators for Black Pill compatible Veroboard PCB, LQFP48, SysClock = 144MHz
(09 April 2024 - bugfix)
(state 10 April 2024) This source code is provided as complete "Segger Embedded Studio" project (ZIP file, 1036 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.
Kernel Ops for SPI and PWM1,PWM2 included. USART can operate as terminal or as serial I/O
(09 April 2024 - minor improvements and bugfix)
Kernel Ops for SPI and PWM1,PWM2 included. USART can operate as terminal or as serial I/O
(09 April 2024 - minor improvements and bugfix)
Kernel Ops for SPI, stepper motor and PWM1 included. PWM2 not implemented. USART can operate as terminal or as serial I/O
(09 April 2024 - minor improvements and bugfix)
Kernel Ops for SPI, stepper motor and PWM1 included. PWM2 not implemented. USART can operate as terminal or as serial I/O
(09 April 2024 - minor improvements and bugfix)
By jumper, this board can be started as a USB-to USART RS232 interface or into a USB-to conventional USART MIDI interface. Details see CForth Operating Manual p.15.
Instead no SPI, motor and PWM code implemented. For 20pin TSSOP Veroboard compatible PCB, SysClock = 48MHz
(09 April 2024 - improvements and bugfix)
Instead no SPI, motor and PWM code implemented. For 32pin LQFP Veroboard compatible PCB, SysClock = 48MHz
(09 April 2024 - minor improvements and bugfix)
Else this code is the same as "CForth-F042-midi.hex". SysClock = 48MHz.
By jumper, this board can be started as a USB-to USART RS232 interface or into a USB-to conventional USART MIDI interface. Details see CForth Operating Manual p.15.
(09 April 2024 - improvements and bugfix)
(09 April 2024) This source code is provided as complete "Segger Embedded Studio" project (ZIP file, 512 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.
reduced version for an unmodified STM32 Nucleo G431 board
(09 April 2024 - bugfix)
reduced version for an unmodified STM32 Nucleo G431 board.
Terminal communication exclusively via ST-Link USB.
(09 April 2024 - bugfix)
(state 09 April 2024) This source code is provided as complete "Segger Embedded Studio" project (ZIP file, 434 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.
* 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.