Close

A place for hardware drivers, and no more 0x3FF

A project log for eForth for cheap STM8S gadgets

Turn cheap modules from AliExpress into interactive development kits!

thomasThomas 12/26/2016 at 22:130 Comments

The code In the development branch on GitHub has some interesting changes:

  1. hardware driver code is now in the board folders (file boardcore.inc). Adding code for new boards, especially I/0-drivers, is now much easier
  2. the code is now again a bit leaner, for a simple reason: I wanted a complete CORE development system to fit into 4KiB.
  3. when you get data from th empty stack the first word you get isn't 0x3FF but it's random. The reason for this is that I fixed two off-by-one bugs that canceled each other out, but that left the number 0x3FF (1023) on the floor of the stack.

The first point became a priority when I realized that most Cheap China Gadgets won't provide simple access to RS23. With "most" I mean 9 out of 10. Since giving up isn't what I'm best known for, I decided to tackle diversity through clean configuration options.

The second point was important to me because I wanted this Forth implementation for tiny µCs to be, well, tiny. Also I wouldn't call it complete if your work vanishes when you cut the power (my VIC=20 did that and I didn't like it). Also there's no point in a fancy self-contained development environment when there is no space left for your application code. Call it my "4K challenge" ;-)

Here is a small demo of the new CORE image:

RESET ok
NVM ok
: test WORDS ; ok
RAM ok
COLD ok
test
 test RESET RAM NVM WORDS .S DUMP CREATE IMMEDIATE : ] ; ." 
ABORT" AFT REPEAT WHILE ELSE THEN IF AGAIN UNTIL BEGIN 
NEXT FOR $," LITERAL C, , ALLOT ' [ \ ( .( ? . U. TYPE 
U.R CR SPACE KEY DECIMAL HEX FILL CMOVE 2@ 2! +! PICK 
ABS NEGATE NOT 2/ 1- 1+ 2* 2- 2+ */ */MOD M* * UM* / 
MOD /MOD M/MOD UM/MOD WITHIN MIN MAX < U< = DNEGATE 
2DUP ROT ?DUP FILE HAND -1 1 0 BL BASE UM+ - 0< OR AND 
XOR + OVER SWAP DUP >R R@ 2DROP DROP R> C! C@ ! @ 
EXECUTE EMIT ?KEY 'BOOT COLD ok
HEX ' test . 8FF8 ok

RESET removes any vocabulary in the Flash (and resets the initialization constants in the 'BOOT array. NVM switches to Flash compile mode. For the demo test is an alias for WORDS. RAM makes the configuration persistent. COLD does a cold-start. Running test shows that the word is still there, and a lookup of the code address with ' (tick) shows it to be below 0x9000, and this means that there is 4 KiB left for application code!

The CORE vocabulary was trimmed for usage as a scripting language, but I didn't select the background task option (this would have taken about 230 bytes more). A plain REPL now requires about 3800 bytes (down from the 5500 bytes of the original STM8EF code).

The 3rd point (0x3FF as the value when reading from an empty stack) indicates that I've turned most bytes of Dr. C.H. Ting's implementation upside-down by now. Some dark spots got cleaned up in the process.

Discussions