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, 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).
A by-result is the 48MHz version for STM32F042. For the price of no-USB it offers more user code space and some more I/O features.
A new code version is implemented for STM32F030K6 processors (LQFP32), which is very similar to STM32F042. These processors are quite easily availble for low cost, but offer only 4kB SRAM. So this version is only useable for small projects (up to ca.50 user programmed code threads).

New experience has been made with STM32L031K6(LQFP32): this prototype 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.

USB cannot be operated with the low-power clock frequencies. But this is not regarded as harmful because USB uses a considerable amout 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. 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.

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, a special CForth kernel operator "LED" is introduced to switch the LED off when not needed. 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 seems 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:STM32F042K6
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 STM32F070. 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-23 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.
(09 April 2024 - bugfix)

Firmware "CForth-LP-G4xx-14m.hex" for Veroboard compatible PCB, CPU Clock = 921.6kHz/3.6864MHz/14.7456 switchable. Uses 14.7456MHz crystal.
(09 April 2024 - bugfix)

Source code "CForth-LP-G4xx-v11.zip"
(state 09 April 2024. This source code is provided as complete "Segger Embedded Studio" project (ZIP file, 469 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.
(09 April 2024 - bugfix and minor improvements)

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.
(09 April 2024 - bugfix and minor improvements)

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.
(09 April 2024 - bugfix and minor improvements)

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.
(09 April 2024 - bugfix and minor improvements)

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.
(09 April 2024 - bugfix and minor improvements)

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.
(09 April 2024 - bugfix and minor improvements)

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.
(09 April 2024 - bugfix and minor improvements)

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.
(09 April 2024 - bugfix and minor improvements)

Firmware "CForth-LP-F042-48pwm2.hex" for 20pin TSSOP Veroboard compatible PCB. Code for PWM2.
Designed for the same hardware as described here and the same firmware features but equiped with an 8.0MHz crystal and uses the processor built-in PLL to work with 48MHz/3MHz AHB and APB frequency.
CPU Clock = 48.00MHz/3.00MHz switchable. Default = 48MHz.
Provides more Flash and some more I/O features than the standard version.
(09 April 2024 - bugfix and minor improvements)

Firmware "CForth-LP-F042lqfp-48pwm2.hex" for 32pin LQFP Veroboard compatible PCB. Code for PWM2. Else general description as above.
(09 April 2024 - bugfix and minor improvements)

Firmware "CForth-LP-F042-48motor.hex" for 20pin TSSOP Veroboard compatible PCB. Code for stepper motor. Else general description as above.
(09 April 2024 - bugfix and minor improvements)

Firmware "CForth-LP-F042lqfp-48motor.hex" for 32pin LQFP Veroboard compatible PCB. Code for stepper motor. Else general description as above.
(09 April 2024 - bugfix and minor improvements)

Source code "CForth-LP-F042-v12.zip"
(state 09 April 2024). This source code is provided as complete "Segger Embedded Studio" project (ZIP file, 575kB).
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 2024.
* 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.