Close

Compile to Flash released

A project log for eForth for cheap STM8S gadgets

Turn cheap modules from AliExpress into interactive development kits!

thomasThomas 11/06/2016 at 12:200 Comments

I just released the Compile to Flash feature. I tried to stick to the original design of eForth as much as possible, but maintaining two vocabularies, one in Flash, and one in RAM is a bit challenging. The way I implemented it it's now possible to change between the modes RAM and NVM (Non Volatile Memory) back and forth, while linking new words to the right space in the vocabulary, and preventing words from volatile RAM to be referenced by non-volatile words (words in RAM are always available in interactive mode, though).

Let me give you a walk-through:

after flashing the MINDEV binary to a $0.70 board you'll get a clean vocabulary. Then we change to NVM mode, define a new greeting word, set it as the boot word, and restart.

NVM ok
: mystart CR 3 FOR I . NEXT CR ." Hi!" CR ; ok
' mystart 'BOOT ! ok
RAM ok
COLD
 3 2 1 0
Hi!

NVM unlocks the Flash memory, and the core words CONTEXT, CP, and OVERT do some magic in the background to keep the vocabularies in good order. RAM locks the Flash memory and makes the pointers LAST and CP persistent. After defining the simple startup word mystart, ' (tick) retrieves its address, 'BOOT gets the address of the startup word pointer, and ! stores the address of our word to it.

Setting a startup word is also a good way for first initializing an application, and then starting the background control task. Here is a very simple example, that shows a running counter on the 3 digit 7S-LED display of a W1209:

NVM ok
: bg TIM . ; ok
: start [ ' bg ] LITERAL BG ! ; ok
' start 'BOOT ! ok
RAM ok

We first go to NVM mode, then we define bg that prints out the value of the background ticker TIM. Character output like . (dot) in background automatically goes to the 7S-LED display. In the definition of start, [ and ] use the interpreter to fetch the address of bg, and LITERAL inserts it into the compiled code. BG gets the address of the background task pointer to which the value from the stack is stored with !. After that the operating is returned to RAM like in the first example.

Here is how this looks like:

Discussions