Skip to content

More features release

Pre-release
Pre-release
Compare
Choose a tag to compare
@TG9541 TG9541 released this 22 Dec 14:04

STM8 eForth 2.2.27 development cycle

As most STM8 devices are now officially supported, this release is going to concentrate on features, e.g. drivers for STM8 peripherals or support of the Wakeup Timer for the Background Task (instead of using TIM2).

A simple debug console

It's sometimes useful to inspect the system (e.g. the stack) while executing a word in an application. That can be done by calling OUTER, the Forth interpreter, from user code. The new word BYE leaves this interpreter (but not that of the normal console).

Here is an example session:

#require BYE
\ ...
Closing: ./lib/BYE  ok 
: test 1 2 3 OUTER . . . ; ok
test<ENTER>.S<ENTER>
 1 2 3 <sp  ok
. 3 ok
4 ok
bye 4 2 1 ok

Note that there is no prompt indication when the "debug interpreter" gets active after test<ENTER>. Also note that any ?response from the interpreter means that the stack was emptied. Only a debug interpreter with a different type of error response would be able to prevent that.

The issue #372 "better BYE for debug console" contains technical details.

Fully Modular Background Task code

The BG code is now "fully modular" which means that it can be replaced with user code by placing a modified copy of bgtask.inc into a Board folder.

Now the background task can also be run by the STM8L RM0031 device RTC (think "alarm") or by the Wakeup Timer.

Details are in the issues #375 "improve BG task interrupt configuration options" and #377 "factor out BG task code".

Better control of interrupt vectors in the C interface

In STM8 eForth the linker is called by SDCC (which is the main task of SDCC in this project). The C interface in main.c used to depend on a fixed a set of interrupt vectors which limited the configuration of core features, e.g. the Background Task. This definition is now done by an include file in the Board folder.

Details are in the issue #379 "re-order C-Stub infrastructure".

Relative Addressing for IF .. ELSE .. THEN

Some use cases require STM8 machine code branch instructions instead of ?branch or branch that use absolute addressing (e.g. relocatable code in RAM, fast ISRs). Calculating the branch offset is better left to the compiler.

This feature is implemented by exchanging control structures on the fly (i.e. by loading a bit of the compiler into RAM).

#require >REL

NVM
: test ( f -- )  IF ."  True" ELSE ."  False" THEN ;
RAM

Here, IF will compile to >Y JREQ rel and ELSE to JRA rel:

' test 20 dump
955B CD 8A C 27 B CD 89 91 5 20 54 72 75 65 20 A ___'_____ True _
956B CD 89 91 6 20 46 61 6C 73 65 81 0 0 0 0 0 ____ False______ ok

While this already solves the problem of relocatable code the most important use case of this solution is using fast bit test ([ a #b ]B@IF) or anything that can be done with Forth - Assembler interface (e.g. [ c ]A<IF).

Details are in the issue #382 "IF .. ELSE .. THEN with relative addressing".

More machine code generating words

STM8 eForth doesn't have STM8 assembler words (yet). Instead "macros" are used to generate assembler instructions (e.g. conditional branch, bit and byte transfers). A number of new "macros" have been added to better support time critical ISRs (Interrupt Service Routine).

Word Explanation
[ a ]@ push contents of word at literal a to TOS
[ a ]@IF test contents of word at literal a and perform IF w\ relative branch
[ ... c ]A<IF test if A is < literal c and perform IF w\ relative branch
[ f a #b ]B! set bit #b in byte at literal a to literal f
[ a #b ]B? push flag with value of bit #b in byte at literal a to TOS
[ a #b ]B@IF test bit #b at literal a and perform IF w\ relative branch
[ a #b ]BC copy bit #b in byte at literal a to carry flag
[ a #b ]BCPL complement bit #b in byte at literal a
[ c a ]C! set byte at literal a to literal c
[ a ]C@IF test contents of byte at literal a and perform IF w\ relative branch
[ a #b ]CB copy carry flag to bit #b in byte at literal a
[ f a #b ]SPIN spin until bit #b at literal a is equal to f
[ ... n ]Y<IF test if Y is < literal n and perform IF w\ relative branch

Also see #383 "machine code generating words for ISR programming"

An I2C Master driver

On the face of it the STM8 I2C interface is a bit difficult to use. An easy to use driver has been added to the core. Example code is here.

Refr tp #385 "generic STM8 I2C Master" for details.