Close

Forth Dictionary entries in the EEPROM

A project log for eForth for cheap STM8S gadgets

Turn cheap modules from AliExpress into interactive development kits!

thomasThomas 03/25/2018 at 19:303 Comments

The low-cost STM8S Low Densitity devices don't have a lot of Flash (8K) and RAM (1K), but they have a surprisingly generous amount of EEPROM (640 Bytes). Ok, officially, the Value Line devices only have 128 Bytes EEPROM, but in practice the Value Line STM8S003F3 devices I tested all behaved like an Acces Line STM8S103F3.

It's tempting to use the Flash Memory for storing code, but it turns out that jumping to an EEPROM address causes a reset!

I now found a way to use EEPROM as a substitute for Flash memory: the ALIAS feature of STM8 eForth allows for splitting the Forth Dictionary from the code, and since an ALIAS is not executed but merrily interpreted it doen't matter where it's stored.

For testing I stripped many dictionary entries from the CORE image for STM8S Low Density devices, and replaced them with ALIAS.

Here is the result:

WORDS
  RAM NVM WORDS .S DUMP IMMEDIATE VARIABLE CONSTANT CREATE ] : ; OVERT ." REPEAT WHILE BEGIN LITERAL C, , ' CR [ \ ( .( ? . U. KEY HEX HERE +! 0= ABS NOT 1+ 1- 2+ 2- 2* 2/ */ M* * / /MOD M/MOD UM/MOD < U< = ROT - 0< OR AND XOR + UM+ I OVER SWAP DUP DROP NIP >R R@ R> C! C@ ! @ 2@ 2! COLD 'BOOT U.R UNTIL UM* TYPE TX! THEN SPACE SIGN SAVEC #S ?RX RESET QUIT QUERY PICK PARSE PAD NEXT NEGATE NAME? NAME> MIN MAX ?KEY IRET IF HOLD FOR FILL EXTRACT EXIT EXECUTE EVAL EMIT ?DUP DOXCODE DNEGATE DIGIT DEPTH DECIMAL COUNT COMPILE? [COMPILE] COMPILE CMOVE CALL, BL ALLOT AHEAD AGAIN AFT ACCEPT ABORT 2DUP 2DROP #> # $" <#  ok
NVM $A000 HERE - . 4461 ok

Since more than half of the dictionary is stored in EEPROM (in bold text), a binary size of just 3731 Bytes offers a rich vocabulary!

It's simple to use, too:

\ EEPROM MODE:
\ * define ALIAS words in the EEPROM, 
\ * abort if a normal compilation (non-ALIAS words) is attempted
\   note: the STM8 resets when executing plain compiled words from EEPROM!
\ * return to RAM MODE with EECLOSE when done
\ * remove ALIAS words in EEPROM from dictionary with EERESET

#include EEALIAS

\ load ALIAS words
#require SPACES
#require DIGIT
#require DNEGATE

\ done: return to normal, and WIPE RAM
EECLOSE

 Check out the code of EEALIAS here - comments are, as always, appreciated!

@RigTig : I guess that with this method a Forth not much larger than 3K is now possible. As I think about it, an interactive Forth for the STM8S103F2 (4K Flash) is now also possible - not very useful, but possible :-)

Discussions

RigTig wrote 03/27/2018 at 07:20 point

I have only made to one Forth Conference (local in Sydney Australia), and it was inspiring. I expect this one to be no less so. Enjoy, learn, inspire and be inspired.

  Are you sure? yes | no

RigTig wrote 03/26/2018 at 02:07 point

I've been watching you weave your magic on this tiny machine. Sorry to have not been of much assistance of late. I still am amazed at what can be done. The underlying structure of Forth allows for really low-level access and manipulation, yet with a high-level interface allowing effective hiding of the detail. 

The main reason for me liking the simple machines is to get my head around what the hardware can do. I enjoy the struggle  at that level. The STM8 is still providing nice surprises in what it can do. Many thanks to all the team. 

  Are you sure? yes | no

Thomas wrote 03/26/2018 at 04:39 point

RigTig, I won't forget that the idea for ALIAS was yours, and that getting a Forth rookie to understand implementation errors was, at times, a difficult task. I hope that you'll get better soon!

  Are you sure? yes | no