The STM8L Release
About the release
This is release is very much about fully supporting STM8L devices (i.e. the likes of STM8L051F3, STM8L151C6 or STM8L152R8).
While STM8S peripherals are simple and the pin and clock configuration is trivial, the STM8L designers clearly had both "larger" and "many more" spec sheets. The "many more" one can be seen in the number of configuration dependencies the programmer has to infer when trying to use one of the many features of the peripherals. For STM8 eForth this means that things that were implicit or hard-coded needed to be restructured and tested. The device families STM8S and STM8L now are on equal footing and the generalizations gained when adding STM8L support now also makes supporting STM8S variants easier.
This release (finally) adds support for the low-end RM0013 STM8L device STM8L101, and, at the other end of the spectrum, STM8L "High density" devices like STM8L152R8 (also STM8L162 devices can be expected to work).
Configuration folders with docs for typical "Low", "Medium" and High density" devices in both families have been added (refer to Generic Targets for a list of supported devices). So far the hypothesis holds that memory and peripheral properties are the same across a range of package and memory specs variants the devices for which these "6+1 device types" and there is no evidence that the "small world of STM8 devices" is much more complicated than that. If you have reason to believe that a device doesn't fit in this simple schema please file an issue!
Devices in the following device families have not been examined:
- STM8L RM0312 family touch sensing MCUs, e.g. STM8TL5xxx
- STM8S STLUX lighting MCUs and STNRGxxxA power conversion MCUs (including wireless charging STWBC)
It shouldn't be big problem to get a Forth console on any of these devices, but for using the specialized peripherals it's maybe a good idea to apply ST's proprietary C-code libraries and configuration tools.
New Features
STM8L: Peripheral addresses
New or improved register address (efr-) files for e4thcom and codeload.py are now available. @Eelkhoorn first provided an improved STM8L151.efr
file, and in #342 efr files for specific STM8L variants were created.
STM8L "Medium" and "High density" should work with the generic STM8L151.efr
.
Peripheral register addresses of RM0031 "Low density" devices differ from STM8L "Medium density" and "High density" devices. Constants should be imported with \res MCU: STM8L051
.
The final group is RM0013 "Low density" devices like STM8L101F3 or STM8L001J3: here \res MCU: STM8L101
should be used.
STM8 Timers and interrupts
Some applications, like XY-LPWM, need to use a different timer than TIM2 for the background task.
Issue #369 adds this option to the STM8L device families.
By setting BG_USE_TIM3 = 1
in globconf.inc
the Background task (BG) timer will use TIM3 instead of TIM2 in STM8L "Low density" devices. STM8L "Medium" and "High density" devices can also set BG_USE_TIM1 = 1
for using TIM1. There is currently no support for TIM5 in STM8L "High density" devices.
A conflict between a simulated serial port and the background task in an STM8L051F3 device was discovered and fixed in issue #340 STM8L interrupt priority of BG task.
STM8S UART and STM8L USART configurations
STM8L devices in the RM0031 family support USART GPIO function remapping. This can easily lead to a mismatch between the USART GPIO mapping an the GPIO output initialization.
The following issues provide a solution:
- #358 USART options for STM8L High Density devices
- #364 STM8L: general options for USART configuration
- #360 half-duplex USART console option for STM8L devices
Common elements in boardcore.inc
of all STM8L devices, together with docs in the target folders, that also show the default mapping, make the configuration easy.
STM8S "Low" and "High density" devices use matching configuration items. STM8L152R8 has the most options.
Configuration of STM8 memory variants
Issue #330 made EEPROMBASE
, the EEPROM start address, a target.inc
configuration item which can be used to write device independent code.
The new feature was used in issue #339 which removed hard-coded addresses in EEALIAS
so that offloading a part of the dictionary to the EEPROM now works for both STM8S and STM8L devices. STM8L "Low density" devices have a much smaller EEPROM than those in the STM8S family, of course.
Issue #355 introduced a PAGESIZE
constant so that device independent code for "Flash ROM page write" can load it with #require PAGESIZE
.
Note that memory variants should be defined in the configuration folder's target.inc
based on the device type (STM8L or STM8S, "Low", "Medium" or "High density"). If you're engineering a product you should care for selecting the device with the right specs. For casual use memory specs are most likely not that important (if there is evidence of the opposite please share it and file an issue).
Make target for OpenOCD / stm8-gdb
OpenOCD and stm8-gdb can be of great help, especially when dealing with new devices. Issue #350 added support for an ELF target so that binaries that can be loaded into stm8-gdb can be built with make BOARD=<boardname> debug
.
There are notes about using OpenOCD and stm8-gdb is in this Gist which also contain OpenOCD target configuration files for STM8L101 and STM8L051 "Low density" devices.
Experimental debug console
At times it's interesting to examine the state of a Forth program in the middle of the execution. Issue #372 introduces a very simple debug console with the words OUTER
and BYE
.
Here is a simple example:
#require BYE
: test ( n -- )
FOR
I DUP . 2 MOD 0= IF
CR ." Break - mind the stack - continue with BYE" CR
OUTER THEN
NEXT ." done"
;
A debug session on a STM8S003F3, where a FOR ... NEXT
loop is terminated manually by changing the loop counter on the return stack ($3FF growing down), looks like this:
66 7 test 7 6
Break - mind the stack - continue with BYE
$03F0 10 dump
3F0 23 0 0 A 8D 1E 8D 12 1 1D 0 6 8D 1E 8D 12 1_______________ ok
bye 5 4
Break - mind the stack - continue with BYE
$03F0 10 dump
3F0 23 0 0 A 8D 1E 8D 12 1 1D 0 4 8D 1E 8D 12 1_______________ ok
$3FA ? 4 ok
0 $3FA ! ok
bye done ok
. 66 ok
Note that a single misspelled word will clear both the data and the return stacks. This will not only reset the console but it will terminate the program and typing BYE
in this situation will crash the system! There is clearly room for improvement.
Boards and target support
STM8L101F3 Low density support
Several differences between the STM8L101 and other STM8L devices (e.g. option bytes) delayed STM8 eForth support for a long time. STM8 eForth now supports RM0013 devices with NVM
, the TIM2 based BG
task and also the simulated serial interface. A binary release is available and the ordinary STM8 eForth workflows can be used.
Please refer to the docs in the configuration folder STM8L101F3 and the following issues:
- #349 Add support for STM8L101 and STM8L001
- #356 improve STM8L101 docs and efr file
- #356 STM8L101F3: improve target.inc and docs Documentation
Note that statements in the Wiki and other docs that the STM8L101 would not be supported have been changed. Using OpenOCD and gdb-stm8 were instrumental for adding support of this MCU.
STM8L051F3 Low density support
Support for RM0031 STM8L "Low density" devices has long been available. Test results with STM8L devices from applications in the community were used to revise support. Configuration options (e.g. USART, BG timer, simulated serial interface) and docs are now consistent with other STM8L devices.
Please refer to the docs in the STM8L051F3 configuration folder.
STM8L Medium density support
Although there has long been the STM8L-Discovery configuration by @plumbum requests for a more active support of STM8L "Medium density" devices like STM8L151K4 was a recurrent issue (e.g. #218, #267, #268 or #287).
@Eelkhoorn finally sent an STM8L151K4 breakout board to @TG9541 and contributed to configuration files and to testing. Issue #354 implemented support for RM0031 STM8L "Medium density" devices, independent of "Medium+" and "High density" devices.
Please refer to the docs in the STM8L151K4 configuration folder where console configuration options are listed.
STM8L High density support
STM8L "High density" devices have a rather rich feature set and more memory than other STM8L devices. Issue #358 added support for these devices and also describes the various console options. It's possible that this configuration also works for "Medium+ density" devices like the STM8L152R6 but no samples have been tested and feedback would be appreciated.
Please refer to the docs in the STM8L152R8 configuration folder.
STM8S configuration folders
The configuration folders STM8S001J3, STM8S105K4 and STM8S207RB now contain docs with a common range of information.
STM8S103F3 Low density support
Issue #371 added an STM8 eForth configuration with standard features and plain UART console settings and for STM8S "Low density" devices. STM8S103F3 includes docs in a similar form as for all the other base configurations and a binary release is provided.
Alternative configurations are MINDEV, SWIMCOM, DOUBLECOM and CORE.
STM8S207RB default serial interface
In order to support the STM8S207K8 issue #334 changed the UART used by the console by default from the first UART (UART1) to the 2nd UART (UART3).
This can be changed by setting USE_UART2 = 0
in globconf.inc
.
Improvements and Other Changes
#295 extended memory access with FC@ and FC!
#336: factored solution for BF! abd LEBF! using B!
#353 Add BTJT/ BTJF spin loop enhancement
#337: FC! and FC@ added
#346 Add COMPONLY to the library
#344 STM8L: fix interrupt number naming error