CForth Low Power for STM32G431, STM32G43 and STM32F042

The intention for this project is to get a tool for control dynamic art installations powered by small solar panels 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 STM32F042F6 (latter works with STM32F070, too) 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 921.6kHz or optionally 3.6864MHz, derived from a 3.6864MHz HSE crystal oscillator, which is directly used as System Clock.
USB cannot be operated with this clock frequency. 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 was a 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. I still had some original STM LE33A devices, which are a quite good choice, average ground pin current measured ca. 0.5mA with CPU running at normal speed and without additional external components. A good - or even better - alternative is LP2950ACZ-3.3. It is pin compatible and uses only around 0.2mA ground pin current, but increasing with higher load.
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.

Below the line: the complete STM32G431 prototype uses ca. 2.2mA with LED OFF, the STM23F042 prototype uses ca. 1.6mA with LED OFF. Processors are always in full speed mode. No Sleep or Idle mode is used. Though the STM32G431 surely is the more interesting processor, for the intended range of use the more compact and less current hungry STM32F042 seems to be more atttractive.

both models Veroboard PCBs

Veroboard assembly prototypes. left:STM32G431KB, right:STM32F042F6, each soldered on 15.24mm DIL breakout board

About CForth LowPower Firmware:

The set of Kernel Operators and their features is almost the same as the standard CForth version, with lower execution speed of course.
Starting from the actual release, the thread code for STM32F042 processors is compacted to 8bit format, which increases the maximum user Forth code up to 3 times compared with previous versions.

The most essential differences against standard CForth:

  • The basic CPU clock speed is 921.6kHz. To extend the range of use, additional options for 3.6864MHz CPU clock and 48MHz CPU Clock (STM32F042 only, 8MHz HSE) have been introduced. Latter one is not a low power version, but may be used as minimal standard CForth version.
  • STM32G4xx and STM32F042 firmware versions "921k" and "2Speed":
    Max FREQ is 9.216kHz. "9 FREQ" sets the output frequency to 1024Hz.
    PWM can be only adjusted in the range 0 100.
  • STM32F042 firmware version "3686k":
    Max FREQ is 18.432kHz. "18 FREQ" sets the output frequency to 1024Hz.
    PWM can be only adjusted in the range 0 200.
  • Max SPI clock rate is in the order of 50kHz (STM32G4xx)
    (STM32F042 only ca 20 kHz - less efficient code due to lack of memory).
  • The STM32G4xx version supports I2C (PB7,PB8), but only rather low speed clock up to ca. 100kHz.
  • An RS-232 interface is available with Baud Rates 9600,19200,38400,57600,115200.
    MIDI and USB is not implemented.
  • For this reason, the Kernel Operators RX?, TX, TX, TXN, TX", SPLIT, VID, PID and CHANNEL are not included.
  • As an option to save current, the Kernel Operator LED is added: LED ( mode --- ).
    This operator can be compiled into User Threads for process signalling.
    0 LED: LED is always OFF
    1 LED: LED is always ON
    2 LED: LED goes OFF for ca. 0.25 sec when a data byte is received via RS-232
    3 LED = default: LED goes OFF for ca. 0.25 sec when a data byte is received or transmitted via RS-232
  • The STM32G4xx version and the STM32F042 version "2Speed" support the additional Kernel Operator "SPEED",
    1 SPEED sets CPU freq 921.6kHz, 4 SPEED sets CPU freq 3.6864MHz. May even be changed during runtime.
    FREQ is always kept at 921.6kHz level, i.e does not change together with CPU speed.
  • The STM32F042 Low Power version supports 2 projects in Flash, because kernel code takes less Flash segments due to missing USB. Therefore SAVE and LOAD ask the Project number 0 (=Empty), 1, 2 like it is implemented in the G4xx version. Operator EMPTY is not included here.

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

PCB layout for the "STM32G431, STM32G441 Low Power 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 Low Power 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-LP-G4xx.hex" for Veroboard compatible PCB, CPU Clock = 921.6kHz / 3.6864MHz switchable.
(Version 1.4 , 31 May 2021 - minor improvements)

Source code "CForth-LP-G4xx.zip" (state 31 May 2021)
This source code is provided as complete "Segger Embedded Studio" project (ZIP file, 357 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-921k.hex" for Veroboard compatible PCB. CPU clock = 921.6kHz.
(Version 1.4 , 31 May 2021 - thread code now compact 8 bit format, else minor improvements)

Firmware "CForth-LP-F042-3686k.hex" for Veroboard compatible PCB. New: CPU clock = 3.6864MHz
(Version 1.4 , 31 May 2021 - thread code now compact 8 bit format, else minor improvements)

Firmware "CForth-LP-F042-2Speed.hex" for Veroboard compatible PCB. New: CPU Clock = 921.6kHz / 3.6864MHz switchable.
(Version 1.4 , 31 May 2021 - thread code now compact 8 bit format, else minor improvements)

Firmware "CForth-LP-F042-48M.hex". Experimental compact version. 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 AHB and APB frequency. Speed of I/O features is the same as CForth standard version. Provides more Flash and some more I/O features than the standard version.
(Version 1.4 , 31 May 2021 - thread code now compact 8 bit format, else minor improvements)

Source code "CForth-LP-F042.zip" (state 31 May 2021)
This source code is provided as complete "Segger Embedded Studio" project (ZIP file, 275 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.



* State of information June 2021.
* 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.