Some people love Forth and some people hate it. However, you usually think of Forth as something running on a little computer such as an 8-bit microcomputer. When [Chuck Moore] developed the system back in the 1960s though, it ran on an IBM 1130. [Carl Claunch] took a scanned listing of the original code and got it running once again.
There are actually a few blog posts with details. Luckily, Forth is pretty simple — especially the core parts. However, there are a lot of differences from a modern Forth. The most obvious is that the dot keyword starts a definition and does not print the top of stack. However, internal details are different too — the system, for example, stores characters in packed EBCDIC — an ASCII-like code used by IBM computers.
For anyone who has dealt with the programming language Forth, odds are good that you picked it up back in the 80s. Since the language is still in use for many applications, though, you might not have this sort of nostalgic feeling for the language that some might have. For that, though, you might want to try out [Richard]’s implementation which simulates the microcomputers of the 80s using this unique language.
The system has an FPGA-based CPU written in Verilog. It runs on a Nexys-3 board and features PS/2 Keyboard input, a VGA output with a VHDL VT100 terminal emulation module, access to the Flash and onboard SRAM, and a UART. With all of that put together it’s virtually a Forth-based time machine. It’s also extremely well documented even if you’re just curious how it works and aren’t planning on building your own.
The project also includes a CPU simulator written in C which can model the entire computer if you don’t have the hardware for building the actual computer. [Richard] also released everything that you’d need to roll out your own Forth computer on the GitHub page. There are other ways of heading way back to the 1980s, though, like using the quirky Parralax Propeller.
Forth has a long history of being a popular hacker language. It is simple to bootstrap. It is expressive. It can be a very powerful system. [jephthal] took the excellent Mecrisp Forth and put it on the very inexpensive STM32 “blue pill” board to create a development system that cost about $2. You can see the video below.
If you have thirty minutes, you can see just how easy it is to duplicate his feat. The blue pill board has to be programmed once using an STM32 programmer. After that, you can use most standard Forth words and also use some that can manipulate the low-level microcontroller resources.
Sometimes I need to be able to take photographs of very small things, and the so-called macro mode on my point-and-shoot camera just won’t cut it. And it never hurts to have an inspection scope on hand for tiny soldering jobs, either, though I prefer a simple jeweler’s loupe in one eye for most tasks. So I sent just over $40 off to my close friend Alibaba, and a few weeks later was the proud owner of a halfway usable inspection scope that records stills or video to an SD card.
Unfortunately, it’s only halfway useable because of chintzy interface design and a wobbly mount. So I spent an afternoon, took the microscope apart, and got it under microcontroller control, complete with WiFi and a scripting language. Much better! Now I can make microscope time-lapses, but much more importantly I can take blur-free photos without touching the wiggly rig. It was a fun hack, so I thought I’d share. Read on!
In the last two articles on Forth, I’ve ranted about how it’s beautiful but strange, and then gotten you set up on a basic system and blinked some LEDs. And while I’ve pointed you at the multitasker, we haven’t made much real use of it yet. Getting started on a Forth system like this is about half the battle. Working inside the microcontroller is different from compiling for the microcontroller, and figuring out the workflow, how to approach problems, and where the useful resources are isn’t necessarily obvious. Plus, there’s some wonderful features of Mecrisp-Stellaris Forth that you might not notice until you’ve hacked on the system for a while.
Ideally, you’d peek over the shoulder of someone doing their thing, and you’d see some of how they work. That’s the aim of this piece. If you’ve already flashed in our version of Mecrisp-Stellaris-plus-Embello, you’re ready to follow along. If not, go back and do your homework real quick. We’ll still be here when you’re done. A lot of this article will be very specific to the Mecrisp-Stellaris flavor of Forth, but given that it runs on tons of ARM chips out there, this isn’t a bad place to be.
In the last episode, I advocated a little bit for Forth on microcontrollers being a still-viable development platform, not just for industry where it’s usually seen these days, but also for hackers. I maybe even tricked you into buying a couple pieces of cheap hardware. This time around, we’re going to get the Forth system set up on that hardware, and run the compulsory “hello world” and LED blinky. But then we’ll also take a dip into one of the features that make Forth very neat on microcontrollers: easy multitasking.
Mecrisp-Stellaris Forth runs on a great number of ARM microcontrollers, but I’ll focus here on the STM32F103 chips that are available for incredibly little money in the form of a generic copy of the Maple Mini, often called a “STM32F103 Minimum System Board” or “Blue Pill” because of the form-factor, and the fact that there used to be red ones for sale. The microcontroller on board can run at 72 MHz, has 20 kB of RAM and either 64 or 128 kB of flash. It has plenty of pins, the digital-only ones are 5 V tolerant, and it has all the usual microcontroller peripherals. It’s not the most power-efficient, and it doesn’t have a floating-point unit or a DAC, but it’s a rugged old design that’s available for much less money than it should be.
Similar wonders of mass production work for the programmer that you’ll need to initially flash the chip. Any of the clones of the ST-Link v2 will work just fine. (Ironically enough, the hardware inside the programmer is almost identical to the target.) Finally, since Forth runs as in interactive shell, you’re going to need a serial connection to the STM32 board. That probably means a USB/serial adapter.
This whole setup isn’t going to cost much more than a fast food meal, and the programmer and USB/serial adapter are things that you’ll want to have in your kit anyway, if you don’t already.
You can power the board directly through the various 3.3 and GND pins scattered around the board, or through the micro USB port or the 5V pins on the target board. The latter two options pass through a 3.3 V regulator before joining up with the 3.3 pins. All of the pins are interconnected, so it’s best if you only use one power supply at a time.
Sometimes I see a component that’s bizarre enough that I buy it just to see if I can actually do something with it. That’s the case with today’s example, the ESP-14. At first glance, you’d ask yourself what AI Thinker, the maker of many of the more popular ESP8266 modules, was thinking.
The ESP-14 takes the phenomenally powerful ESP8266 chip and buries it underneath one of the cheapest microcontrollers around: the 8-bit STM8S003 “value line” chip. Almost all of the pins of the ESP chip are locked inside the RF cage’s metal tomb — only the power, bootloader, and serial TX/RX pins see the light of day, and the TX/RX pins are shared with the STM8S. The rest of the module’s pins are dedicated to the STM8S. Slaving the ESP8266 to an STM8S is like taking a Ferrari and wrapping it inside a VW Beetle.
I had never touched an STM8 chip before, and just wanted to see what I could do with this strange beast. In the end, ironically, I ended up doing something that wouldn’t be too far out of place on Alibaba, but with a few very Hackaday twists: a monitor for our washer and dryer that reports power usage over MQTT, programmed in Forth with a transparent WiFi serial bridge into the chip for interactive debugging without schlepping down into the basement. Everything’s open, tweakable, and the Forth implementation for the STM8S was even developed here on Hackaday.io.
It’s a weird project for the weirdest of ESP modules. I thought I’d walk you through it and see if it sparks you to come up with any alternative uses for the ESP8266-and-STM8S odd couple that is the ESP-14.