CForth Low Power for STM32L031
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.
LowPower Hardware with STM32L031 processor:
Because the STM32L031K6 (LQFP32) version does not include pinout for a crystal oscillator, the built-in MSI RC osciallator is used for system clock. This provides a CPU clock speed (STM32 SYSCLK, AHB and APB bus) of 1.048MHz (default, switchable by Forth command to 4.194MHz).
During tests here, stability was good for RS-232 baudrates up to 57600 Baud with default frequency calibration of the MSI clock. 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 STM32L031 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 remarkable 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).
Typical features of CForth LowPower Firmware for STM32L031:
The set of CForth Low Power Kernel Operators and their features is almost the same as the standard CForth version, with lower execution speed of course - and with up to 1/50 lower supply current.
The User Thread code storage for STM32L031 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:
- Two projects in Flash are supported, 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.
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 600 word entries wide.
- An exclusive feature is the 'EEPROM' Kernel Operator: up to 256 data words are stored here non-volatile in STM32L031 processor internal EEProm (project independent globally).
- The basic CPU clock speed is 1.048MHz, switchable by Forth command '2 SPEED' up to 4.194MHz.
- Max FREQ is 10.48kHz. "10 FREQ" sets the output frequency to 1048Hz.
PWM can only be adjusted in the range 0...100. - PWM1 pulse output is PB1. If available, PWM2 pulse output is PA0.(changed 05Jan24)
- Max SPI clock rate is only ca 20 kHz (less efficient code due to lack of memory).
- General I/O ports PC14 and PC15 are provided in place of pins for crystal oscillator.
- I/O port PB8 is not implemented, only the BOOT0 pin instead. For normal operation connect it with Vss(pin32).
- An RS-232 interface is available with baud rates 9600,19200,38400,57600.
115200 doesn't work. 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 STM32L031 motor drive is 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)2023-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-L031-pwm2.hex" for 32pin LQFP Veroboard compatible PCB.
CPU Clock = 1.048Hz/4.194MHz switchable. Code for PWM2.
(09 April 2024 - bugfix and minor improvements)
Firmware "CForth-LP-L031-motor.hex" for 32pin LQFP Veroboard compatible PCB.
CPU Clock = 1.048Hz/4.194MHz switchable. Code for stepper motor.
(09 April 2024 - bugfix and minor improvements)
Source code "CForth-LP-L031-v4.zip"
(state 09 April 2024). This source code is provided as complete "Segger Embedded Studio" project (ZIP file, 406kB).
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.