back to menue

CForth Low Power for STM32G431(G441), STM32F042(F070), STM32L031 and STM32F030

The intention for this project is to get a tool for control dynamic art installations powered by small solar panels or other "weak" power sources using the Forth programming language (no relationship to "Mitch Bradley's CForth").
For this reason, primarily reduced versions of the CForth interpreter for STM32G431KB, STM32G441KB and STM32F042 and corresponding Verobard compatible PCB designs are developed.

LowPower Hardware:

First of all the CPU clock speed (STM32 AHB and APB bus) is reduced to about 1MHz (details see below).
For the price of no-USB it offers more user code space and some more I/O features.

Additionally, attactive CForth Low Power versions for similar processor models are developed:
Interesting experience has been made with STM32L031K6(LQFP32) and STM32L031F6(TSSOP20, new Feb25): These prototypes uses only ca.0.2mA with LED OFF at 1.048 MHz clock (0.8mA at 4.194MHz clock). But it has to be noted, that supply current rises remarkably with ADC on (ca. +0.4mA), power via pull-up or pull-down (ca. +0,08mA) and fast pulse out via I/O pin (ca. +0.2mA at 1 kHz PWM, no load). Else this code is very similar to the STM32F042 version.
Another code version is implemented for STM32F030K6(LQFP32 only) low cost processor, which is very similar to STM32F042, but offers only 4kB SRAM. So this version is only useable for small projects (up to ca.50 user programmed code threads). A by-result is the 48MHz version for STM32F030 - may be regarded as lowest-tech version of standard CForth.

USB cannot be operated with the low-power clock frequencies. But this is not regarded to be harmful because USB uses a considerable amount of current and Flash memory (latter case is important for the STM32F042 version, there is a permanent struggle byte by byte to fit the code into Flash). The chosen system frequency allows standard RS-232 Baud Rates up to 115200 (STM32L031 max.57600). The RS-232 interface does not draw current except during data transfer. The RS-232 transmitter is extremely simplified, but has been tested with several standard RS-232 receivers, which typically have a trigger level around 0.7 Volt and an input impedance in the order of 5kOhm.

Another critical aspect of supply current is the quality of the 3.3V regulator. After some tests, I have found out that MCP1702 (ca. 0.01mA ground pin current) is the best solution for most CForth Low Power target projects. But it is specified only up to 13V supply voltage.
A good alternative is LP2950ACZ-3.3 which is specified up to 20V input voltage. It uses about 0.2mA ground pin current, but increasing with higher load. It can be placed into MCP1702 PCB layout turned about 135 degrees counter clockwise. The middle pin of LP2059 is Ground instead of Vin at MCP1702. A pin compatible replacement for LP2950 is STM LE33A, but it uses ca 0.5mA ground pin current.

The LED should be a very efficient blue or white type. To save current and to make it accessable for "blinking LED" user access, a special CForth kernel operator "LED" is introduced to switch the LED OFF or permanently ON, if not needed to signalize terminal I/O . With 10kOhm serial resistor, a blue LED uses about 0.1mA.

Resume of CPU features - processors in RUN mode, current measured behind voltage regulator and LED OFF:
The STM32G431, STM23F042 and STM23F030 prototypes use ca.1.1 to 1.2mA (921kHz system freq. with 3.68MHz crystal). (Ca.1.6 to 1.9mA at 3.68MHz system freq. and ca.1.6 to 1.7mA at 921kHz system freq. with 14.74MHz crystal). The STM32L031 prototype uses only ca. 0.2mA with LED OFF at 1.048 MHz clock (0.8mA at 4.194MHz clock).
Though the STM32G431 surely is the most interesting processor, for the intended range of use the less current hungry STM32L031 or the more compact TSSOP20 STM32F042 seem to be more atttractive.

To get a more straight and better readable text,
---the differing low-power features of the STM32L031 version are described on a separate HTML page.

---and the differing low-power features of the STM32F030 version are described on a separate HTML page.

Next follows description of differing low-power features of the "original" STM32G431 and STMF042 codes:

both models Veroboard PCBs
Veroboard assembly prototypes.
left:STM32G431KBright:STM32F042F6(TSSOP20)
each soldered on 15.24mm DIL breakout board.
Another Veroboard layout for STM32F042K6 (LQFP32) is provided.

About CForth LowPower Firmware: (STM32G431/G441, STM32F042/F070)

The set of Kernel Operators and their features is almost the same as the standard CForth version, with lower execution speed of course.
In contrast to the straight 32bit code for STM32G431, the thread code storage for STM32F042 processors is compacted to 8bit format, which increases the maximum user Forth code up to 3 times compared with 32 bit code (details see CForth Operating Manual, p1-3).
The code for STM32F042 is 1:1 useable with STM32F070F6 (TSSOP20).
STM32F070 data sheet does not support I/O pin PB8, but surprisingly tests here have shown that it works. Not guaranteed, of course..
The code for STM32G431 is 1:1 useable with STM32G441,LQFP32

The most essential differences against standard CForth:

A detailled CForth Operating Manual Standard version (PDF file), and
a DIY Construction Manual Low Power version (HTML 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-25 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.

Firmware "CForth-LP-G4xx-3M6.hex" for Veroboard compatible PCB, CPU Clock = 921.6kHz/3.6864MHz switchable. Uses 3.6864MHz crystal.
(06 February 2025 - code improvement and minor bugfixes)

Firmware "CForth-LP-G4xx-14m.hex" for Veroboard compatible PCB, CPU Clock = 921.6kHz/14.7456 switchable. Uses 14.7456MHz crystal.
(06 February 2025 - code improvement and minor bugfixes)

Source code "CForth-LP-G4xx-v12.zip"
(state 06 February 2025. This source code is provided as complete "Segger Embedded Studio" project (ZIP file, 468 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-LP-F042-3m6pwm2.hex" for 20pin TSSOP Veroboard compatible PCB. CPU Clock = 921.6kHz/3.6864MHz switchable. Uses 3.6864MHz crystal. Code for PWM2.
(06 February 2025 - code improvement and minor bugfixes)

Firmware "CForth-LP-F042lqfp-3m6pwm2.hex" for 32pin LQFP Veroboard compatible PCB. CPU Clock = 921.6kHz/3.6864MHz switchable. Uses 3.6864MHz crystal. Code for PWM2.
(06 February 2025 - code improvement and minor bugfixes03 February 2025 - code improvement and minor bugfixes)

Firmware "CForth-LP-F042-3m6motor.hex" for 20pin TSSOP Veroboard compatible PCB. CPU Clock = 921.6kHz/3.6864MHz switchable. Uses 3.6864MHz crystal. Code for stepper motor.
(06 February 2025 - code improvement and minor bugfixes)

Firmware "CForth-LP-F042lqfp-3m6motor.hex" for 32pin LQFP Veroboard compatible PCB. CPU Clock = 921.6kHz/3.6864MHz switchable. Uses 3.6864MHz crystal. Code for stepper motor.
(06 February 2025 - code improvement and minor bugfixes)

Firmware "CForth-LP-F042-14pwm2.hex" for 20pin TSSOP Veroboard compatible PCB. CPU Clock = 921.6kHz/14.7456MHz switchable. Uses 14.7456MHz crystal. Code for PWM2.
(06 February 2025 - code improvement and minor bugfixes)

Firmware "CForth-LP-F042lqfp-14pwm2.hex" for 32pin LQFP Veroboard compatible PCB. CPU Clock = 921.6kHz/14.7456MHz switchable. Uses 14.7456MHz crystal. Code for PWM2.
(06 February 2025 - code improvement and minor bugfixes03 February 2025 - code improvement and minor bugfixes)

Firmware "CForth-LP-F042-14motor.hex" for 20pin TSSOP Veroboard compatible PCB. CPU Clock = 921.6kHz/14.7456MHz switchable. Uses 14.7456MHz crystal. Code for stepper motor.
(06 February 2025 - code improvement and minor bugfixes)

Firmware "CForth-LP-F042lqfp-14motor.hex" for 32pin LQFP Veroboard compatible PCB. CPU Clock = 921.6kHz/14.7456MHz switchable. Uses 14.7456MHz crystal. Code for stepper motor.
(06 February 2025 - code improvement and minor bugfixes)

Source code "CForth-LP-F042-v13.zip"
(state 06 February 2025). This source code is provided as complete "Segger Embedded Studio" project (ZIP file, 466kB).
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 February 2025.
* 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.