CForth Low Power for STM32F030K6
Here the latest result of my CForth Low Power project is presented separately. 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.
STM32F030K6 processors are quite easily available 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). Else all features are very similar to the STM32F042 version:
The basic system frequency is 921.6 kHz, derived from a 3.6864MHz or 14.7456MHz crystal oscillator. A by-product is a 48MHz version with features comparable with the standard STM32F042 CForth, but without USB.
The chosen system frequencies 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. For this reason, on the Veroboard compatible PCB design, a layout for MCP1702 (ca. 0.01mA ground pin current) is provided. LP2950 or LE33 regulators fit into the PCB layout: mounted ca.135 degrees counter clockwise with respect to the MCP1702 position. The middle pin of LP2059/LE33 is Ground instead of Vin at MCP1702.
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 STM23F030 prototype uses ca.1.1mA (921kHz system freq. with 3.68MHz crystal) measured behind the voltage regulator and with LED OFF. (Ca.1.9mA at 3.68MHz system freq. and ca.1.6mA at 921kHz system freq. with 14.74MHz crystal.)
LowPower Hardware with STM32F030K6 processor:
Typical features of CForth LowPower Firmware for STM32F030:
The set of Kernel Operators and their features is almost the same as the standard CForth version, with lower execution speed of course.
The User Thread code storage for STM32F030 is derived from the compact code for STM32F042 processors. In contrast to the straight 32bit code for STM32G431, it is compacted to 8bit format, which increases the maximum User Forth code volume up to 3 times at the price of slightly slower code runtime (details see CForth Operating Manual, p1,2).
The most essential differences against standard CForth:
- The memory size for User code is only 2/3 of the STM32F042 version.
- This code works on STM32F042 / STM32F070, too: less User code but 3 User projects.
- The STM32F030 Low Power version supports 3 projects in Flash, because kernel code takes less Flash segments due to missing USB. Furthermore, due to small SRAM the project size is less than other low-power versions. Therefore SAVE and LOAD ask the Project number 0 (=Empty), 1, 2, 3 like it is implemented in the G4xx version.
Basic system parameters (project number, number base, baud rate) are stored globally in a separate Flash page, but may be overriden by project specific setup. - 'ARRAY' is not implemented due to small SRAM.
- The basic CPU clock speed is 921.6kHz, switchable by Forth command to 3.6864MHz CPU clock or 14.7456MHz CPU clock - depending on assembled crystal.
-- Furthermore 48MHz CPU Clock (derived from 8MHz crystal HSE with PLL, switchable down to 3.0 MHz at runtime) . Latter one is not a low power version, may be regarded as a standard CForth version without USB. Supply current ca.12mA (ca.4mA at 3MHz). - STM32F030(versions 3M68 and 14M):
Max FREQ is 9.216kHz. "9 FREQ" sets the output frequency to 1024Hz.
PWM can be only adjusted in the range 0...100. - STM32F030 firmware version 48M):
Max FREQ is 30.0kHz. "30 FREQ" sets the output frequency to 1000Hz.
PWM can be only adjusted in the range 0...100. (changed 05Jan24) - Max SPI clock rate is only in the order of ca.20 kHz - less efficient code due to lack of memory).
- 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 SLEEP command has beed added. Supply current in SLEEP mode is a few microAmp, awake is triggered by a high-to low transient at PA3 or PA15 or PA10(USART Rx). (changed 05Jan24)
- Though stepper motors surely are no low power devices, simple code for driving stepper motors as background process (external inverter with hiZ switch for 4 phases necessary) is provided. I use steppers from old disk drives together with small solar panels buffered with big electrolytic capacitors and small numbers of steps per capacitor discharge. Due to lack of memory for STM32F030 only available as alternative to PWM2.
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-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.
Firmware "CForth-LP-F030-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-F030-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-F030-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-F030-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-F030-48pwm2.hex" for 32pin LQFP 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-F030-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-F030-v5.zip"
(state 09 April 2024). This source code is provided as complete "Segger Embedded Studio" project (ZIP file, 410kB).
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.
* 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.