Non Cortex-M

Readers of this site would no doubt be aware that I believe that the STM32 range of ARM Cortex-M cores are the best choice by far for embedded designers because of the FLOSS friendly, low cost, high availability, wide range of on-board peripherals and excellent documentation. No it’s not perfect but then what is ?

I also believe that Mecrisp-Stellaris by Matthias Koch is the very best FLOSS Forth for the STM32 architecture. In fact Mecrisp-Stellaris is the only FLOSS on-chip-Forth (20KB) with a long history (since 2014), proven reliability and ongoing author support and maintenance that you will find on the Internet at this time (2022).

Hence this site deals only with Cortex-M hardware and Mecrisp-Stellaris Forth, however I saw a need to document notable non Cortex-M embedded Forths I have tested over the years.

Note

I also feature a lot of information on the Texas Instruments MSP430 MCU on this site because it runs “Mecrisp” by Matthias Koch and came before Mecrisp-Stellaris, so in a way it’s the “Father of Mecrisp-Stellaris” even tho it is a totally different ISA. However I do have a different document site for the Tethered Version which can be viewed at https://mecrisp-across-folkdoc.sourceforge.io/index.html

Forth is I think, the most commonly programmer created programming language, with hundreds of different projects hosted on Sourceforge and Github. However most of those Forths are incomplete, can’t be built or just don’t work as they were the result of an experiment, now abandoned.

To Be listed Here a Forth Must

  • be easy to build under *bsd and Linux

  • be stable

  • have good documentation

  • be designed for a well known embedded MCU

  • include example working Forth code

  • have that certain special ‘something’ about it

8051

The Intel designed 8051 is a early embedded microprocessor and billions have been made, cross licensed and are still in use because of their very cheap mass pricing. All the Greyhairs are very familiar with this MCU, still have all the tools, and I’m told they’re still used in the millions in cheap devices like electric toothbrushes etc.

_images/8051.jpg

Modern 8051’s

Like the Cortex-M cores are licensed from Arm by many manufacturers, so was/is the 8051 core, which means there are many variants with their own extra peripherals added, and their own programming/debugging methods and theyre not compatible from what I can see, so it pays to make sure that the cheap programmer on ebay is actually for the model 8051 youre buying.

Nuvoton N76E003

Used in many of the cheap Chinese “Relay Boards” such as the example below. Note the STM8 is also used in many “Relay Boards”, which is not a 8051 arch.

Nuvoton Relay Board:

_images/nuvoton-relay-board.jpg

Nuvoton Programmer/debugger Board:

_images/nuvoton-programmer-board.jpg
CPU:
  • Fully static design 8-bit high performance 1T 8051-based CMOS microcontroller.

  • Instruction set fully compatible with MCS-51.

  • 4-priority-level interrupts capability.

  • Dual Data Pointers (DPTRs).

Operating:
  • Wide supply voltage from 2.4V to 5.5V.

  • Wide operating frequency up to 16 MHz.

  • Industrial temperature grade: -40℃ to +105℃.

Memory:
  • Up to 18K Bytes of APROM for User Code.

  • Configurable 4K/3K/2K/1K/0K Bytes of LDROM, which provides flexibility to user developed Boot Code.

  • Flash Memory accumulated with pages of 128 Bytes each.

  • Built-in In-Application-Programmable (IAP).

  • Code lock for security.

  • 256 Bytes on-chip RAM.

  • Additional 768 Bytes on-chip auxiliary RAM (XRAM) accessed by MOVX instruction.

Clock sources:
  • 16 MHz high-speed internal oscillator trimmed to ±1% when VDD 5.0V, ±2% in all conditions.

  • 10 kHz low-speed internal oscillator.

  • External clock input.

  • On-the-fly clock source switch via software.

  • Programmable system clock divider up to 1/512.

Peripherals:
  • Up to 17 general purpose I/O pins and one input-only pin. All output pins have individual 2-level slew rate control.

  • Standard interrupt pins /INT0 and /INT1

  • Two 16-bit Timers/Counters 0 and 1 compatible with standard 8051.

Silabs Various Models

toolstick-silabs.jpgSilabs introduced high speed and cool peripherals to the 8051, but they insist on making their own proprietary IDE’s etc. FLOSS people will likely find themselves marooned at sea with these chips.

I’m not advocating the Silabs “Toolstick” range because I bought some in 2014 that are now long obsolete and still have no Unix support that I can find.

_images/toolstick-silabs.jpg
  • Pipelined 8-bit C8051 core with 50 MHz maximum operating frequency

  • 16 multifunction, 5 Volt capable I/O pins

  • 1 x 12-bit Analog to Digital converter

  • 2 x analog comparators

  • Integrated temperature sensor

  • 3-channel PCA w/ PWM

  • 3-channel PWM engine

  • 4 x 16-bit timers

  • 2 x 8-bit timers

  • 2 x UART

  • SMBus/I2C

  • SPI with 4 byte FIFO

  • Priority crossbar for flexible pin mapping

  • 4 x configurable logic units

Old 8051 Models

Like the AT89C51 has only 4KB of flash and cannot run even this super small Forth which needs 6417 bytes.

CamelForth v1.6

This release by James Bowman, updates the original DOS version by Brad Rodriguez so that it runs under Unix. It features am assembler and emulator for a PC, tests aids and example code. in testing I found this Forth stable and easy to use with a large Dictionary for the embedded designer. It has the feel of a very well designed Forth about it.

Brads ‘Moving Forth’ papers are the classic way to learn how to make your own Forth: http://www.bradrodriguez.com/papers/moving1.htm

Readme

# 8051forth - Forth for the 8051

This is based on CamelForth for the Intel 8051 (c) 1994,1997,1999 Bradford J. Rodriguez: A

Brad’s 1999 version uses a DOS assembler, which is a little difficult to find now. http://www.camelforth.com/page.php?4

The changes to this project are:

1. now uses a modified version PJRC's `as31` assembler, included in this project
2. minor changes to Brad's code to build with `as31`
3. a software emulator based on emu8051, included in this project
4. regression test using the ANS test suite, CI by Travis
5. a version tuned for the TI CC1110 SoCs

To rebuild:

make

Runing Camel5 Via The Emulator On a PC

$ emu8051/emu generic camel51.hex
8051 CamelForth v1.6  18 Aug 1999
1 2 + .
1 2 + . 3 ok

WORDS
WORDS CLOCKOFF CLOCKON INITTASK SWITCH @TCON !TCON @P1 !P1 DUMP COLD .S WORDS ENVIRONMENT? DEPTH MOVE WITHIN LEAVE +LOOP LOOP ENDLOOP DO L> >L REPEAT WHILE
AGAIN UNTIL BEGIN ELSE THEN IF POSTPONE ['] ; : IMMEDIATE REVEAL HIDE ] [ RECURSE DOES> (DOES>) CREATE \ ( [CHAR] CHAR ' ABORT" ?ABORT ABORT QUIT EVALUATE
INTERPRET ?NUMBER >NUMBER ?SIGN DIGIT? LITERAL FIND IMMED? NFA>CFA NFA>LFA WORD >COUNTED /STRING SOURCE IC, I, IALLOT IHERE C, , ALLOT HERE HEX DECIMAL . U.
SIGN #> #S # >DIGIT <# HOLD UD* UD/MOD IWORD ITYPE ICOUNT ." S" IS" (S") (IS") TYPE ACCEPT UMAX UMIN SPACES SPACE CR COUNT 2OVER 2SWAP 2DUP 2DROP 2! 2@ MIN
MAX */ */MOD MOD / /MOD * FM/MOD SM/REM M* DABS ?DNEGATE DNEGATE ABS ?NEGATE S>D #INIT UINIT R0 L0 PAD S0 IDP LP HP LATEST 'SOURCE DP STATE BASE >IN U0 TIB
TIBSIZE BL ,UNLOOP !DEST ,DEST ,BRANCH ,EXIT !COLON ,CF !CF COMPILE, >BODY CHARS CHAR+ CELLS CELL+ CELL ALIGNED ALIGN N= SCAN SKIP CMOVE> CMOVE D->I I->D
FILL UM/MOD UM* UNLOOP J I (DO) (+LOOP) (LOOP) ?BRANCH U> U< > < = 0< 0= <> +! RSHIFT LSHIFT 2/ 2* >< 1- 1+ NEGATE INVERT XOR OR

To run the ANS regression suite:

$ ./confirm generic camel51.hex
Cycles: 491549891, 17555.353 ms

Same for the CC1110 Forth:

./confirm cc1110  cc0.hex

Running On a 8051 MCU

Not tested, only because the only 8051’s I have with over 7KB of flash won’t flash on Unix for me (Silabs) and the ones that I could flash don’t have enough memory to support CamelForth.

CamelForth v1.6 Summary

This is the best 8051 Forth I have seen and built over the years and a pleasure to build and play with. The PC emulator is the icing on the cake.

While no one would chose a 8051 over a Cortex-M these days, it has been a memorable chip and is still far from dead. The 8051 has been called ‘the most second sourced chip in the world’ but I think Cortex-M smashed that record years ago.

One very good reason for running the 8051 is that it runs CamelForth v1.6 which is a simple ITC and together with the outstanding Moving Forth articles by Brad Rodriguez, is a great way to learn how to make your own Forth.

http://www.bradrodriguez.com/papers/moving1.htm