Making A Solar-Cell Tester With Mecrisp-Stellaris Forth

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.

Continue reading “Making A Solar-Cell Tester With Mecrisp-Stellaris Forth”

Moving Forth With Mecrisp-Stellaris And Embello

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.

To work!

Hardware

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.

Programmer Connected, Power over USB

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.

Continue reading “Moving Forth With Mecrisp-Stellaris And Embello”

Forth: The Hacker’s Language

Let’s start right off with a controversial claim: Forth is the hacker’s programming language. Coding in Forth is a little bit like writing assembly language, interactively, for a strange CPU architecture that doesn’t exist. Forth is a virtual machine, an interpreted command-line, and a compiler all in one. And all of this is simple enough that it’s easily capable of running in a few kilobytes of memory. When your Forth code is right, it reads just like a natural-language sentence but getting there involves a bit of puzzle solving.

robot_forth_had-colors
From Thinking FORTH (PDF)

Forth is what you’d get if Python slept with Assembly Language: interactive, expressive, and without syntactical baggage, but still very close to the metal. Is it a high-level language or a low-level language? Yes! Or rather, it’s the shortest path from one to the other. You can, and must, peek and poke directly into memory in Forth, but you can also build up a body of higher-level code fast enough that you won’t mind. In my opinion, this combination of live coding and proximity to the hardware makes Forth great for exploring new microcontrollers or working them into your projects. It’s a fun language to write a hardware abstraction layer in. Continue reading “Forth: The Hacker’s Language”

Browsing Forth

Forth has a strong following among embedded developers. There are a couple of reasons for that. Almost any computer can run Forth, even very small CPUs that would be a poor candidate for running programs written in C, much less host a full-blown development environment. At its core, Forth is very simple. Parse a word, look the word up in a dictionary. The dictionary either points to some machine language code or some more Forth words. Arguments and other things are generally carried on a stack. A lot of higher-level Forth constructs can be expressed in Forth, so if your Forth system reaches a certain level of maturity, it can suddenly become very powerful if you have enough memory to absorb those definitions.

If you want to experiment with Forth, you probably want to start learning it on a PC. There are several you can install, including gForth (the GNU offering). But sometimes that’s a barrier to have to install some complex software just to kick the tires on a system.

We have all kinds of other applications running in browsers now, why not Forth? After all, the system is simple enough that writing Forth in Javascript should be easy as pie. [Brendanator] did just that and even enhanced Forth to allow interoperability with Javascript. The code is on GitHub, but the real interesting part is that you can open a Web browser and use Forth.

Continue reading “Browsing Forth”

Interactive ESP8266 Development With PunyForth

Forth is one of those interesting languages that has a cult-like following. If you’ve never looked into it, its strength is that it is dead simple to put on most CPUs, yet it is very powerful and productive. There are two main principles that make this possible. First, parsing is easy because any sequence of non-space characters makes up a legitimate Forth word. So while words like “double” and “solve” are legal Forth words, so is “#$#” if that’s what you want to define.

The other thing that makes Forth both simple and powerful is that it is stack-based. If you are used to a slide rule or an HP calculator, it is very natural to think of “5+2*3” as “5 2 3 * +” but it is also very simple for the computer to interpret.

[Zeroflag] created PunyForth–a Forth-like language for the ESP8266. You can also run PunyForth for cross development purposes on Linux (including the Raspberry Pi). The system isn’t quite proper Forth, but it is close enough that if you know Forth, you’ll have no trouble.

Continue reading “Interactive ESP8266 Development With PunyForth”

No Pascal, Not A SNOBOL’s Chance. Go Forth!

My article on Fortran, This is Not Your Father’s FORTRAN, brought back a lot of memories about the language. It also reminded me of other languages from my time at college and shortly thereafter, say pre-1978.

At that time there were the three original languages – FORTRAN, LISP, and COBOL. These originals are still used although none make the lists of popular languages. I never did any COBOL but did some work with Pascal, Forth, and SNOBOL which are from that era. Of those, SNOBOL quickly faded but the others are still around. SNOBOL was a text processing language that basically lost out to AWK, PERL, and regular expressions. Given how cryptic regular expressions are it’s amazing another language from that time, APL – A Programming Language, didn’t survive. APL was referred to as a ‘write only language’ because it was often easier to simply rewrite a piece of code than to debug it.

Another language deserving mention is Algol, if only because Pascal is a descendant, along with many modern languages. Algol was always more popular outside the US, probably because everyone there stuck with FORTRAN.

Back then certain books held iconic status, much like [McCracken’s] black FORTRAN IV. In the early 70s, mentioning [Nicolas Wirth] or the yellow book brought to mind Pascal. Similarly, [Griswold, (R. E.)] was SNOBOL and a green book. For some reason, [Griswold’s] two co-authors never were mentioned, unlike the later duo of [Kernighan] & [Ritchie] with their white “The C Programming Language”. Seeing that book years later on an Italian coworker’s bookshelf translated to Italian gave my mind a minor boggling. Join me for a walk down the memory lane that got our programming world to where it is today.

Continue reading “No Pascal, Not A SNOBOL’s Chance. Go Forth!”

Go Forth On A Breadboard

Forth isn’t a shiny new programming language, but it has a staunch following because it is lightweight and elegant. The brainchild of [Chuck Moore], the language is deceptively simple. Words are character sequences delimited by spaces. In its simplest form, Forth knows a few basic words including–and this is the key–a word to define other words.

[Jean-Claude Wippler] likes to experiment with physical computing and he found a Forth image ready-made for the LPC1114. Why is that interesting? The LPC1114 is one of the few (or maybe the only) modern ARM processor in a breadboard-friendly DIP package. Since [Jean-Claude] had a chip sitting around, he had a Forth system up in no time. All he needed was a breadboard and a 3.3V serial connector. The chip has its own bootloader and the The Mecrisp-Stellaris Forth he used has over 300 words as well as the ability, of course, to add more.

Continue reading “Go Forth On A Breadboard”