STM8S eForth Interrupts Docs and other Wiki Updates

A project log for eForth for cheap STM8S gadgets

Turn cheap stuff from AliExpress into interactive development kits!

ThomasThomas 01/20/2019 at 10:140 Comments

STM8 eForth is now a serious alternative to coding C coding for STM8 µCs, especially if Flash space is a premium or if interactive features or configuration in the field are required.

Recently, many other pages got updates. Especially a lot of graft was moved from the STM8 eForth Programming introduction page to improved topic pages in the Wiki.

The Forth VM makes context switching very efficient. In my opinion (I wrote many interrupt handlers for industrial and safety critical applications), implementing interrupts in Forth is easer than in C.

The STM8 eForth Interrupts in the STM8 eForth Wiki explains the bit that there is to know. The MODBUS server and the nRFL01 libraries implement low level code using STM8 interrupts.

As an example, here is the STM8S UART RX handler from the MODBUS library:

  \ RX ISR handler
    \ P1H
    UART1_DR C@  ( c ) 
    rxp @ ( c a ) DUP rxbuf - ( c a len ) RXLEN < IF
      ( c a ) SWAP ( a c ) OVER ( a c a ) C!
      ( a ) 1+ rxp !
    TIM tstamp !
    \ P1L

This example contains many stack comments (the stuff in round brackets) and just a bit of code for copying characters from the UART to a buffer, protecting against buffer overrun, and providing a time stamp for the MODBUS "end of transmission" detection.

The most striking point is that in this use case Forth is much more used as a macro assembler for a very simple virtual machine than as a programming language. The programmer builds the most simple "machine" that will do the job. No unnecessary abstractions.

Links to these libraries are on the examples page.